Neovim Tricks
Published: April 4, 2024
This is a short cheat sheet for important keybindings in vim more specific for neovim. I am using NVChad as such not all keybindings are applicable to standard vim/nvim.
Capitalization is important!
Modes:
ESC
, switch to normal mode.v
, switch to visual mode.i
ora
, switch to insert mode.R
, replace mode.
Navigation:
arrow keys
, shame on you!- Movement keys, can be combined with arbitrary number
h
, to the left.l
, to the right.j
, downwards.k
, upwards.- Example:
10j
jumps 10 lines downwards,5k
jumps 4 lines upwards.
_
or0
, beginning of the line.$
, to the end of the line.e
, one word forward.b
, one word backward.:NUMBER
, jumps to the line number.f
+CHAR
, jumps to the next character matching the input char.F
+CHAR
, jumps to the previous character matching the input char.gg
, moves to the top of the files.G
, moves to the bottom of the file.20G
, moves cursor to line 20.
Navigating Code:
%
, to the matching bracket.[
+{
, jumps to previous curly bracket.]
+}
, jumps to next curly bracket.]
+m
, next method beginning.[
+m
, previous method beginning.
Files:
:w
, save current file to disk.:wall
, saves all open files to disk.:q
, closes current window.:qall
, closes all windows.:qall!
, forcefully closes all windows.:wq
, saves and closes window.
Selecting:
v
+i
+p
, select the current paragraph.- can be repeated
vipipipip
.
- can be repeated
y
+a
+p
, yanks paragraph.
Editing:
d
+POSTFIX
, stands for delete depends on postfix.d
, deletes whole line$
, deletes from current postion up to last character in the line._
, deletes from current postion up to first character in the line.e
, deletes next word.b
, deletes previous word.
D
, same asd$
.u
, undo last change.STRG
+r
, redoes the last change.- In visual mode:
y
, copy(yank) the selected text. y
+y
, yank current line.- can be paired with a number, example
5
+y
+y
, yanks the next 5 lines.
- can be paired with a number, example
p
, paste the yanked text after the cursor.P
, paste the yanked text before the cursor.x
, deletes current character.c
+c
, remove current line and edit it."
+BUFFER
+p
, chooses a clipboard buffer and then pastes it.
Search:
/
, searches for patterns forward.?
, searches for pattern backward.n
, jumps to next found pattern.
Misc:
vsp
, vertically splits screen.hsplit
, horizontal splits screen.- In visual mode
>
, intends marked lines in the right direction. - In visual mode
<
, intends marked lines in the left direction. z
+=
, correct spelling mistake.
Telescope File Browser
<leader>
+fb
, opens the telescope file browser.ctrl
+f
, switches between file and folder mode.- In
normal
mode:c
, create a file.r
, rename a file.y
, copy a file.d
, delete a file.g
, goes to parent folder.
Search and Replace
:%s/foo/bar/gc
, changes all occurence offoo
in the current file tobar
, asks for confirmation:%s/foo/bar/g
, changes all occurence offoo
in the current file tobar
, doesn’t asks for confirmation:%s/<foo>/bar/gc
, Changes only whole wors exactly matchingfoo
.
Debugging Neovim
- Start Neovim
- Find the PID of neovim
:lua print(vim.fn.getpid())
or use something likehtop
orbtop
. - Attach the debugger to neovim
gdb -tui -p PID nvim
, the gdb interactive prompt will appear, useful commands:
-n
step over the next statement
-s
step into the next statement
-c
continue
-finish
step out of the current function
-bt
to see the backtrace from current location - Reproduce the bug and check the backtrace
References: