diff --git a/Missing CS semester/README.md b/Missing CS semester/README.md index 5526b8d..bbd50a1 100644 --- a/Missing CS semester/README.md +++ b/Missing CS semester/README.md @@ -115,4 +115,81 @@ Another trick is Ctrl+R, you can insert a subtring to find matching shell comman > Navigating directories -You can use [fasd](https://github.com/clvv/fasd) to autojump to common directories that you visit often. \ No newline at end of file +You can use [fasd](https://github.com/clvv/fasd) to autojump to common directories that you visit often. + +## 3. [Editors](https://missing.csail.mit.edu/2020/editors/) + +Vim has multiple operating modes. + +* Normal: for moving around a file and making edits +* Insert: for inserting text +* Replace: for replacing text +* Visual (plain, line, or block) mode: for selecting blocks of text +* Command-line: for running a command + +The letter `x` in insert mode just inserts the wharacter 'x', but in normal mode, it deletes the caracter under the cursor. In visual mode, it deletes the selection. + +In its default configuration, it shows the current mode in the bottom left. The initial/default mode is normal mode. Press `` to switch from any mode, to normal mode. From normal to insert, with `i`. To replace mode, with `R`. With visual mode, with `v`. + +To go to **insertion mode**, press `i` and insert text. Press `` to go back to normal mode. + +Vim can have many tabs and buffers, initially it has a single tab, containing a single window. + +To enter **Command line mode**, type `:`. + +* :q quit (close window) +* :w save (“write”) +* :wq save and quit +* :e {name of file} open file for editing +* :ls show open buffers +* :help {topic} open help + * :help :w opens help for the :w command + * :help w opens help for the w movement + +### 3.1. Movements + +* Basic movement: hjkl (left, down, up, right) +* Words: w (next word), b (beginning of word), e (end of word) +* Lines: 0 (beginning of line), ^ (first non-blank character), $ (end * of line) +* Screen: H (top of screen), M (middle of screen), L (bottom of screen) +* Scroll: Ctrl-u (up), Ctrl-d (down) +* File: gg (beginning of file), G (end of file) +* Line numbers: :{number} or {number}G (line {number}) +* Misc: % (corresponding item) +* Find: f{character}, t{character}, F{character}, T{character} + * find/to forward/backward {character} on the current line + * , / ; for navigating matches +* Search: /{regex}, n / N for navigating matche + +### 3.2. Edits + +* i enter insert mode + * but for manipulating/deleting text, want to use something* more than backspace +* o / O insert line below / above +* d{motion} delete {motion} + * e.g. dw is delete word, d$ is delete to end of line, d0 is* delete to beginning of line +* c{motion} change {motion} + * e.g. cw is change word + * like d{motion} followed by i +* x delete character (equal do dl) +* s substitute character (equal to xi) +* visual mode + manipulation + * select text, d to delete it or c to change it +* u to undo, \ to redo +* y to copy / “yank” (some other commands like d also copy) +* p to paste +* Lots more to learn: e.g. ~ flips the case of a character + +### 3.3. Counts + +* 3w move 3 words forward +* 5j move 5 lines down +* 7dw delete 7 words + +### 3.4. Demo + +To learn vim: https://www.openvim.com/ and vimtutor. + +sudo apt install vim + +https://medium.com/actualize-network/how-to-learn-vim-a-four-week-plan-cd8b376a9b85 \ No newline at end of file