Dup Goto 📝

HenryMisc_MoreVimTricksThatBlewMyMind

PT2/editor/vim/youtube 08-12 14:28:19
To Pop
129 lines, 656 words, 3989 chars Tuesday 2025-08-12 14:28:19

These are some notes from this video.

(Note I write e.g. <C-a> for control-a, and <esc> for escape.)

  1. Sequential Increment:
    1. Select some lines.
    2. g<C-a>
    • 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, <C-j> adds a new line.
  3. Control-W to delete last word
    • During insert mode, <C-w> deletes the last word. Note that <C-S-w> 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, <C-o> jumps to next jump in jump list, <C-i> 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
  9. Registers
    • :register to view register contents
    • numbered registers store previous yanks/deletions
  10. 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.
  11. Refactor Across Files
    • :vim /regex/ * finds matches in files in current directory
    • :vim /regex/ ** is recursive
    • :copenquickfix list
      • j/k and <cr> 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.
  12. Confirm Replacement
    • :%s/hello/world/c or .../gc asks 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