For longtime (Neo)Vim enthusiasts, nothing here will blow your mind. However, if you've always felt like there are more builtin features of Vim you're missing out on, here's a handful of useful features I'd overlooked for years which don't require any plugins.
Neovim's Builtin Terminal Emulator
This is probably the most killer built-in upgrade that Neovim offers over standard Vim. Basically, Neovim exposes a new "terminal" mode that forwards all your keystrokes to an underlying terminal (which is handled by a cross-platform terminal emulator library).
Compared to using tmux + Vim, Neovim's terminal editor lets you keep all your buffers (and terminal) in a single Vim instance. So your jump list, yanks, and global state are shared. For folks like me too lazy to learn tmux, I can cross that off my list.
Starting Terminal Mode in the Current Buffer
:terminal
And then type anything that will put you into insert mode (a
, o
, i
, etc).
Start Terminal Mode in a New Buffer
If you'd rather split the current buffer and start a terminal in that, type this:
:sp term://bash
Then click or <C-W>h
into the new terminal buffer and use insert mode.
Exiting Terminal Mode
<C-\><C-n>
Personally, I find that a bit too cumbersome, so I'm definitely going to remap that to something else.
To learn more about terminal mode, see the official docs.
Deciphering Vim's Key Notation
I found myself perpetually confused by the key notation I'd see everywhere online and in the builtin docs. Finally, I determined to search until I found an explanation. Here's a semi-official wikia entry which does a great job of explaining. Here's the major takeaways:
<C-...>
means CTRL and ... at the same time. Ex:<C-k>
= CTRL+k<S-...>
means Shift and ... at the same time.<A-...>
means Alt and ... at the same time.<BS>
is backspace (not profanity...silly I know).<F1>
is the F1 key. No shocker there, just mentioning it in case you can't easily access your function keys.<ENTER>
is the enter key.
Additionally, you can always escape a single key stroke in insert or normal mode (and possibly other modes too) by pressing CTRL-V first. For example, CTRL-V and ENTER becomes which is the same as
<ENTER>
but a lot fewer keystrokes.
Vim's Visual Blockwise Edit
Seriously...how did I not know about this? How?! Basically, you can visually select a rectangular region of the current buffer and make the same change to all of them simultaneously. This is a really fast way to change a list of items that start with a single quote into a list of items that start with double quotes, or other tedious tasks which are difficult to change by using regex. Here's a quick example of visual blockwise edit in action:
In that gif, I pressed CTRL-V
(sorry, using the mouse doesn't work by default) in insert mode to start visually selecting. Next I pressed l
three times. Then I pressed j
repeatedly to select down several rows. Instead of the selection wrapping around the end of the current line, a "block" of text is selected straight down. Any operator will be previewed on the first line but applied to all lines of the block selection. I pressed x
to delete the entire selection.
Another idea that you might try is changing the whole selection with c
followed by ESC
after your changes.
Search and Replace Within a Selection
- Use the cursor to select (or press
v
and use motion commands) to select a block of text - Press
:
. You should the statusline show:'<,'>
which simply means the selection - Type
:s/old/new/g
and press<ENTER>
Vim's Ways of Moving
- Go to line (normal mode). Type the line number then capital G. Ex:
200G
- Ignore case for only one search. Add
\c
to the end (for "case"). Ex:/FOOBAR\c
- Jump a paragraph forward
}
- Jump a section forward
]]
- Jump back to a previous jump -
CTRL-O
- Jump forward to a previous jump -
CTRL-I
A "jump" can be triggered by using /
, }
, ]]
and other forms of movement. See :help jumps
.
Conclusion
Writing this article made me realize how much of Vim I'm not taking advantage of, and that it always pays to invest a little more time and effort into your tools. What's your favorite builtin features of (neo)vim? I'd love to hear in the comments. Better yet, open a PR against this article with your corrections and additions.