This is a list of various vim tricks I find useful and get asked / forget about.
Alternate File & Jumplists
Although both of those nav methods are quite useful, they’re not as good as fuzzy finder would be. Bear that in mind when you’re considering your plugins.
- If you’ve edited more than one file in that session, you’d have populated the # register that holds a reference to the previous file. Type in
regto check that. Once you’re sure that register is populated, you can jump between current and previous file by pressing
<C-^>, which also works just fine as
<C-6>on a QWERTY keyboard. Super useful for testing, when you can have the file and its respective test open right where you need it.
- Jump list help:
:jumpsto see a list of jumps. To navigate between them, use
<C-o>. SUPER useful for when you want to jump to a specific place and come back, for example
ggto go to the top of the file, and then jump back with
:set scrollof=8sets auto-scroll after you’re 8 lines over from the edge of the file
:set numberto turn on line numbers
:set rnuto set relative line numbers
Copy and paste to a global system buffer
<shift-D>deletes from cursor to end of line
:eallows you to open and edit a file. Useful in NetRw or otherwise, but not the greatest solution, supports globbing, but not fuzzy finding. That makes you have to actually traverse the file tree.
- You can expand text by pressing tab, for example when typing the
:commands. If you’re typing in a command, and press
, you will see a little pop up menu with all the possible options. Neat.
- To enter the explorer, simply type in
Find and replace
s/a/b/gcwill replace every
bglobally, but will ask you first on every instance.
<indents one level to the left.
>same, but to the right.
iget you into insert mode, but on different sides of the cursor
Igoes to the first non-whitespace character of this line
Omakes a newline, respects the indenting, and puts you into insert mode
<C-v>tells vim to treat the next character literally. Enables inserting tabs for example
Jumps (while editing)
ffollowed by a char takes you to that char
tfollowed by a char takes you one char before it
mfollowed by a capital letter sets a mark in a file
'followed by a capital letter goes to that mark
- Same applies to lowercase letters. Uppercase are global, lowercase marks are local to a buffer
- Open the explorer and split panes vertically/horizontally use
- Open a file named
bread.bdin a new pane
- Move between splits by using
ctrl-wand press directional key (arrows or home row)
- To close all but the current pane you’re in, do
Quick editing tips
ciwdeletes the word under a cursor and puts you in insert mode
cwdoes the same but doesn’t delete the whole word, deletes until the end of the word.
.performs the last action again. Super useful
:h regopens help on registers
:regopens register view
- To search with ripgrep use
- It’ll open a fzf finder, use
<tab>to mark files that you want to have in the quicklist.
- To sort a bunch of lines, select them in visual mode, and run the
- To start a search, type in the
/, followed by the pattern you’re looking for. Then use
nto go forward to the next match, and
Nto go to the previous match.
:set hls icsets highlighting and incremental search.
- To enable spellcheck, use
:set spell spelllang=en_us. To disable it,
zzto center the screen on the current line
pare different modes of posting
:so %source current file (useful for editing vimrcs)
:cdoenables you to execute a command against quicklist. Then, you can execute a write all command
:wato make it happen. It’s great for a global find-and-replace.