These are some notes [from this video](https://www.youtube.com/watch?v=wgbvBDR4yxk). (Note I write e.g. `` for control-a, and `` for escape.) 1. Sequential Increment: 1. Select some lines. 2. `g` * This increments the number in the first line by 1, in the second line by 2, and so on. 2. Control-J to insert new line * During *insert mode*, `` adds a new line. 3. Control-W to delete last word * During *insert mode*, `` deletes the last word. Note that `` does the same. Often `w` defines words by contiguous sequences of chars like `abc324A`, and `W` defines words delimited by whitespace. 4. Control-O to run normal mode command * Shorthand for exiting insert mode, doing one action, and then immediately going back into insert mode. 5. Asterisk * `*` searches for the next instance of the word under the cursor * `#` searches backwards in the same way as `*` * `g*` searches forward for the next word containing the word under the cursor * `g#` searches backwards in the same way as `g*` 6. Jumping * `gg` jump to start * `G` jump to end * `:jumps` lists recent jumps * In *normal mode*, `` jumps to next jump in jump list, `` jumps to previous jump 7. Marks * `ma` sets mark `a`, `'a` jumps to mark `a`; this is *local to the current file* * `mA` sets mark `A`, `'A` jumps to mark `A`; this is *global to all files*, so if you set mark `A` in one file, open another, then `'A` will jump back into the first file. 8. Special Jumps * `''` jumps to prev jump location * `'.` jump back to last edited location * `'^` last location when we left insert * `'[` beginning of last change * `']` last line of last edit 1. Registers * `:register` to view register contents * numbered registers store previous yanks/deletions 1. Repeat Last Op * `.` repeats last operation * If referring to a numbered register, the number is incremented each time `.` is used so `"1p` will paste the contents of register 1, `u` will undo the paste, but then `.` will redo the paste except that it will do `"2p` instead. Repeating pastes the contents of the next numbered register and so on. 1. Refactor Across Files * `:vim /regex/ *` finds matches in files in current directory * `:vim /regex/ **` is recursive * `:copen` — [quickfix list](/editor/vim/QuickfixList) * `j`/`k` and `` to select * `:cp`/`:cn` for prev/next item respectively * `:cdo s/Random/Bobbins/gc` to global search replace Random with Bobbins in the files found by `:vim /regex/ *`. The `c` at the end means to confirm changes. 2. Confirm Replacement * `:%s/hello/world/c` or `.../gc` asks for confirmation for each replacement. ## Rough Notes These are rough notes [from this video](https://www.youtube.com/watch?v=wgbvBDR4yxk). At some point I'll explore these and make this more readable. ``` Increment/decrement C-a/C-x ## num 10o0. -- add ten 0. lines vip -- select para g -- increment o... # insert C-w delete last word C-o run normal mode * asterisk search word under cursor g* partial match g# like g* but backwards # jumping gg G :jumps -- jumplist back in jl forward in jl Moving by j,k doesn't qualify as jump. jumps: see help about what qualifies as a jump marks m,' :marks jump across files capital letters mA -- jumps back to file ma -- local to file '' jumps to prev jump loc '. jump back to last edited loc '^ last loc when we left insert '[ beginn of last change '] last line of last edit :register view regs numbered regs store prev deletes . repeat last op ref reg increments so "1p u . etc cycles through del's refactor across files :vim /regex/ * :vim /regex/ ** -- recursive :copen -- quickfix list jk enter :cp :cn prev next item :cdo s/Ollama/Bobbins/gc gc global and confirm ```