I have been using Vim for quite some time, and switched to Neovim about a year ago. Even though I managed to make Neovim my daily driver, I didn't yet reach the familiarity with Neovim where I could say that I'm super confident using it. So my goal was to increase my confidence with Neovim by watching this course.
The following are the notes I captured during the course:
- There's a possibility in Neovim to setup a short blinking highlight on yank. Can be useful for me, just as a quick confirmation on the yanked region.
- When typing any command that starts with
:
, you can press<C-d>
to get a list of possible autocompletions. Neat. :Ex
opens file tree in the same buffer.:Vex
does the same, but with a neat vertical split.- Vim allows for "recursive mappings". This means you can bind some key to a command, and then in another binding use the hotkey that was introduced earlier. There was a case in the course when binding was specifically introduced as non-recursive with
nore
prefix. Not sure I'll find a good use for that personally. - Introducing a mapping for re-sourcing the lua config might be very convenient, I should look into that.
- Marks – something that you can use to navigate between files and file sections when in "bare bones" Vim.
- Press
m
and then any of the lowercase letters – this would set a file-scoped mark. - Press
m
and then any of the uppercase letter – this would set a global mark. - To navigate to a mark, press
'
and then a corresponding letter.
- Press
<C-^>
navigates between the two last open buffers.- Instead of escape, you can use
<C-c>
to enter normal mode. The are some slight differences between the two, one can think of<C-c>
as a "cancel and get back to normal mode". I should try switching to<C-c>
to see if my fingers find it more ergonomic. - I could try using Telescope to enhance my lists plugin. I.e. showing a list of all saved lists and fuzzy-find across them.
- Music from Inception
- Quick list is a new concept for me,
:copen
to access. I am yet to find a good use for that.- Interesting example shown in the course – getting a list of files into the quick list, sorting them and then updating quick list with the sorted list of files. I'll refer to the code snippet used for that below.
- In Vim you can search through files with
grep
when no third-party tools are installed. Example –:grep map **/*.lua
. - When a buffer is open, you can search and replace –
:%s/foo/bar
.- This command would find
foo
and replace withbar
,:%s
is for global file search.
- This command would find
'<,'>
indicates visual selection in commands, two things here actually – both start and the end of selection, separated by comma.- You can increment a number under the cursos with
<C-a-a>
. Doublea
is actually needed due to collision with tmux<C-a>
mapping. - I learned what macros are, I often was confused by the
recording @q
in the status bar.- To record a macro, press
q
, then select a lowercase letter to assign upcoming macro to. Execute the actions you want and then pressq
again to save.
- To record a macro, press
- I usually rely on
0
to get to the start of the line, but I didn't know there's also_
which respects indendation. Very convenient, I should incorporate this into my flow. - Registers can be simply viewed as key-value storage in Vim. Actually, macros are saved to registers too!
- Thus one can record a macro and edit it if there was a mistake. Or if you need to slightly modify it for the next task.
- To paste from a register –
"bp
, usingb
as a register of choice. - To save to a register –
"by
.
q:
opens a buffer with the history of executed commands. I often open it by accident, now I know what it is at least.- There's a super neat binding of
Vc
to remove the current line and immediately start typing. Blessed. - Another one is
S
as an alternative toD
. C
can also be useful. It doesn't replace the whole line, but from the cursor until the end of the line.- Instead of
x
I could uses
. Removes and immediately gets you to insert mode. - When you searched with
t
orf
, one can use;
and,
to get "next" and "previous" results. - You can move in paragraphs with
{
and}
. ]m
to move to the next open curly braces.Vf{%d
delete entire code block.- When in visual mode, you can press
o
to switch between the start and the end of the visual selection. W
is similar tow
, but moves between contiguous blocks of text surrounded by whitespaces.<C-w r>
to rotate open windows.:buffers
to see a list of open buffers.P
is one of the most powerful remaps. It allows to paste whatever you have in your yanked register, but without updating the register with what you are about to delete.- I should probably re-watch the last section of the course. It was blazingly fast and filled with good ideas and advanced power moves.
Snippet to sort lines in the quick list:
vim.fn.setqflist(vim.fn.sort(vim.fn.getqflist(), function(a, b)
local a_text = a.text
local b_text = b.text
local a_num = a_text:sub(9, #a_text - 2)
local b_num = b_text:sub(9, #b_text - 2)
if a_num > b_num then
return 1
end
return -1
end))