Neovim Commands

Rahul Das
03/18/2025

This is a blog contains some useful and common neovim commands.

Here is a comprehensive list of important NeoVim keybindings, covering navigation, editing, search, buffers, splits, macros, registers, and more.


πŸ“ Basic Movements

KeybindingAction
hMove left
lMove right
jMove down
kMove up
0Move to the beginning of the line
^Move to the first non-blank character of the line
$Move to the end of the line
ggMove to the beginning of the file
GMove to the end of the file
5GMove to line 5 (replace 5 with any number)
HMove to the top of the screen
MMove to the middle of the screen
LMove to the bottom of the screen
zzCenter the current line on the screen

πŸ“œ Scrolling

KeybindingAction
Ctrl + dScroll down half a page
Ctrl + uScroll up half a page
Ctrl + fScroll down a full page
Ctrl + bScroll up a full page

πŸ” Searching

KeybindingAction
/textSearch forward for "text"
?textSearch backward for "text"
nRepeat last search (forward)
NRepeat last search (backward)
*Search for the word under the cursor (forward)
#Search for the word under the cursor (backward)
:%s/old/new/gReplace all occurrences of "old" with "new" in the file
:%s/old/new/gcReplace with confirmation
:nohRemove search highlight

βœ‚οΈ Editing

KeybindingAction
iInsert mode before cursor
IInsert at the beginning of the line
aInsert mode after cursor
AInsert mode at the end of the line
oInsert a new line below and enter insert mode
OInsert a new line above and enter insert mode
rReplace a single character
REnter replace mode
JJoin the current line with the next one
uUndo last change
Ctrl + rRedo last undone change
.Repeat the last command

πŸ“‘ Copy, Cut, and Paste (Yank, Delete, Put)

KeybindingAction
yyYank (copy) the current line
y$Yank from cursor to end of the line
ywYank one word
pPaste after cursor
PPaste before cursor
ddDelete (cut) the current line
dwDelete a word
d$Delete from cursor to end of the line
xDelete (cut) a single character

πŸ“Œ Visual Mode

KeybindingAction
vEnter visual mode (character selection)
VEnter visual line mode
Ctrl + vEnter visual block mode (column selection)
yYank selection
dDelete selection
>Indent right
<Indent left

πŸ“‚ Buffers & Tabs

KeybindingAction
:e <file>Open a file
:bnext (:bn)Move to the next buffer
:bprev (:bp)Move to the previous buffer
:bdClose the current buffer
:buffersShow open buffers
:tabnew <file>Open a file in a new tab
gtSwitch to the next tab
gTSwitch to the previous tab

πŸ–₯️ Windows (Splits)

KeybindingAction
:split or :spSplit the window horizontally
:vsplit or :vsSplit the window vertically
Ctrl + w + wSwitch between windows
Ctrl + w + hMove to the left split
Ctrl + w + lMove to the right split
Ctrl + w + jMove to the lower split
Ctrl + w + kMove to the upper split
Ctrl + w + qClose the current split
Ctrl + w + oClose all other splits

πŸ“œ Marks and Jumps

KeybindingAction
m<letter>Set a mark at the current position
'<letter>Jump to a mark within the same file
``Jump back to the last cursor position
Ctrl + oJump to the previous cursor position
Ctrl + iJump forward to the next cursor position

⏺️ Macros

KeybindingAction
q<letter>Start recording a macro in register <letter>
qStop recording a macro
@<letter>Play the recorded macro
@@Repeat the last macro

πŸ“’ Registers (Clipboard & Yank History)

KeybindingAction
"aYYank into register "a"
"apPaste from register "a"
:registersShow all registers

πŸš€ Miscellaneous

KeybindingAction
:wSave file
:qQuit NeoVim
:q!Quit without saving
:wq or ZZSave and quit
:xSave and quit (only if changes were made)
:help <command>Show help for a command
Ctrl + gShow file name and cursor position
gaShow ASCII value of character under cursor

πŸ’‘ Useful Custom Mappings

To customize mappings, add these to your ~/.config/nvim/init.vim or init.lua:

" Map space as leader key
let mapleader=" "

" Save file with leader + w
nnoremap <leader>w :w<CR>

" Quit NeoVim with leader + q
nnoremap <leader>q :q<CR>

" Copy to system clipboard
nnoremap <leader>y "+y
vnoremap <leader>y "+y

" Paste from system clipboard
nnoremap <leader>p "+p

🎯 Conclusion

These keybindings cover almost everything you need to efficiently navigate and edit in NeoVim. πŸš€ If you want more details, check out the official documentation with:

:help

Happy Vimming! πŸŽ‰ πŸ˜ƒ

Share this post