These are some notes from this video.
(Note I write e.g. <C-a> for control-a, and <esc> for escape.)
- Sequential Increment:
- Select some lines.
g<C-a>
- This increments the number in the first line by 1, in the second line by 2, and so on.
- Control-J to insert new line
- During insert mode,
<C-j>adds a new line.
- During insert mode,
- Control-W to delete last word
- During insert mode,
<C-w>deletes the last word. Note that<C-S-w>does the same. Oftenwdefines words by contiguous sequences of chars likeabc324A, andWdefines words delimited by whitespace.
- During insert mode,
- Control-O to run normal mode command
- Shorthand for exiting insert mode, doing one action, and then immediately going back into insert mode.
- 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 cursorg#searches backwards in the same way asg*
- Jumping
ggjump to startGjump to end:jumpslists recent jumps- In normal mode,
<C-o>jumps to next jump in jump list,<C-i>jumps to previous jump
- Marks
masets marka,'ajumps to marka; this is local to the current filemAsets markA,'Ajumps to markA; this is global to all files, so if you set markAin one file, open another, then'Awill jump back into the first file.
- 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
- Registers
:registerto view register contents- numbered registers store previous yanks/deletions
- Repeat Last Op
.repeats last operation- If referring to a numbered register, the number is incremented each time
.is used so"1pwill paste the contents of register 1,uwill undo the paste, but then.will redo the paste except that it will do"2pinstead. Repeating pastes the contents of the next numbered register and so on.
- Refactor Across Files
:vim /regex/ *finds matches in files in current directory:vim /regex/ **is recursive:copen— quickfix listj/kand<cr>to select
:cp/:cnfor prev/next item respectively:cdo s/Random/Bobbins/gcto global search replace Random with Bobbins in the files found by:vim /regex/ *. Thecat the end means to confirm changes.
- Confirm Replacement
:%s/hello/world/cor.../gcasks for confirmation for each replacement.
Rough Notes
These are rough notes from this video. At some point I'll explore these and make this more readable.
Increment/decrement C-a/C-x
## num
10o0.<cr> -- add ten 0. lines
vip -- select para
g<C-a> -- increment
o<C-j><C-j>...
# 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
<C-o> back in jl
<C-i> 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