Vim Tricks
A collection of Vim tricks I found and are likely to forget because I do not use them enough.
- Reload file that's edited somewhere else
- :e!
- Magically create a numbered list
- Type "1" a X times
- Visually select everything expect the first line
- g
to create a numbering - g
for decreasing numbering - :help v_g_ctrl-a
- Source: https://www.reddit.com/r/vim/comments/eh72g0/creating_a_list_of_numbers/
- N.B. in normal mode, c-a and c-x increment and decrement a single number under the cursor (or directly right to it)
- Automatically timestamp
- iabbrev date-
=strftime("%Y/%m/%d %H:%M:%S") - Werkt niet echt lekker.
- Source: https://www.reddit.com/r/vim/comments/29ade4/journaling_in_vim/
- Mijn eigen alternatief: :put! =strftime(\"%a %Y/%m/%d\")
- iabbrev date-
- Open file from netrw with "x"
- Handig om snel iets in browser te openen, hoef ik het path niet meer te zoeken of met verkenner te werken!
- Check for illegal bytes
- Case: illegal quote sign copied from pdf prevented rendering to pdf with pandoc
- Error was that
\xbfwas illegal - Solution: search for
/[^\x00-\xFF]
- Jump to end of previous word:
gefor word andgEfor WORD.- Before I did
bbe
- Before I did
- Use the
changelist!giandg;andg,- I actively use the
jumplistfor navigation (Ctrl-O, Ctrl-I). But when I'm programming I often look through several files and then want to continue where I was last actually editing text (as opposed to navigating text). Turns out that Vim sets a marker in your last edit location that you can jump to withgi. g;to older positions in the list,g,to newer positions.
- I actively use the
- Repeat forward command
fandFwith;(forward) and,(backward)- Navigation syntax is consistent with the semicolon and comma in
g;andg, - I often tend to do a quick search with
/and jump withn, butfis cleaner if you just want to jump to a word in the same sentence (highlighting with/is overkill in this case; andnprobably jumps to another location in the document at some point which required you to jump back) - Example: in Python function names we_use_underscores_a_lot.
ewill skip to the end of the word because the underscore is not defined to be a word separator. You can of course adjust this behavior (but that is more complex and may introduce side effects elsewhere ), but here f
- Navigation syntax is consistent with the semicolon and comma in
- Reminder: more actively use fuzzy file finding for other things than files as well. E.g. also rely on
CtrlPBufTagto find e.g. function definitions in opened files. (I mapped tosbfor "search buffer";stis mapped toCtrlPTag). - More control over pasting from register.
- In insert and command mode, paste with
Ctrl-R+ register name. I always forget this. - In normal and visual mode, paste with
"xpwithxbeing the register identifier. - Very good explanation with cool use cases: https://stackoverflow.com/a/3997110
0is the yank register (when yanking in normal mode got to0and default register")1-9: shifting deleting register, with1storing the most recent deletion (fromcanddcommands)"default (unnamed) register+and*: system clipboarda-zfor own use:: stored last VimL command/: stores search pattern register- I've often been unable to quickly get back a search pattern to refine it. Now I know why: it's in its own register!
- In insert and command mode, paste with
TODO: Vim for writers.
]sjump to next spelling error.- Adding words to spelling list.
- Having spelling for multiple languages at once
- Fixing spelling error on the fly
- "inoremap
u [s1z=`]a u" - Source: https://castel.dev/post/lecture-notes-1/
- "inoremap
- Maybe a use for vimsessions for larger projects?
- File navigation
Also see: