(neo)vim keybindings
Published on
For the past few years, Neovim has become my go-to text editor
for everything from coding to note-taking. I’ve spent some time sharing keybindings that I’ve found indispensable to my workflow through random social media posts, so I thought it would be worthwhile to group them in a more convenient form. Here is a list of motion
, delete
, search
, and replace
keybindings I use daily, as well as a few that I’m working on becoming more familiar with myself. Whether you’re a seasoned (neo)vim user or just starting out with it, these tips should help you get more out of your editing experience.
This is not intended to be an exhaustive list of keybindings, but feel free to share of your favorite ones I may have missed.
╭── Motion
| Level | Command | Description |
|---|---|---|
| Basic | h | Move cursor left by one character. |
j | Move cursor down by one line. | |
k | Move cursor up by one line. | |
l | Move cursor right by one character. | |
w | Move cursor to the beginning of the next word. | |
e | Move cursor to the end of the current word. | |
b | Move cursor to the beginning of the previous word. | |
0 | Move cursor to the beginning of the current line. | |
^ | Move cursor to the first non-blank character of the current line. | |
$ | Move cursor to the end of the current line. | |
| Intermediate | gg | Move cursor to the beginning of the file. |
G | Move cursor to the end of the file. | |
n | Move cursor to the next match of the last search pattern. | |
N | Move cursor to the previous match of the last search pattern. | |
f\<char> | Move cursor to the next occurrence of <char> on the current line. | |
t\<char> | Move cursor to just before the next occurrence of <char> on the current line. | |
/{pattern} | Move cursor forward to the next match of a pattern. | |
?{pattern} | Move cursor backward to the previous match of a pattern. | |
% | Move cursor to the matching parenthesis, bracket, or brace. | |
| Advanced | '' | Move the cursor back to the previous position where it was last moved by any motion or action that caused a jump |
`. | Move the cursor to the exact position of the last change in the file | |
'. | Move the cursor to the beginning of the line of the last change made in the file | |
y + motion | ||
v | Start visual mode to select text (motion commands affect the selection). | |
Ctrl-d | Move half a page down. | |
Ctrl-u | Move half a page up. | |
{ | Move cursor to the beginning of the current paragraph. | |
} | Move cursor to the beginning of the next paragraph. | |
H | Move cursor to the top of the screen (visible area). | |
M | Move cursor to the middle of the screen (visible area). | |
L | Move cursor to the bottom of the screen (visible area). | |
| Visual Mode | v | Start visual mode (character selection). |
V | Start visual line mode (select whole lines). | |
Ctrl-V | Start visual block mode (select block of text). | |
gv | Re-select the previous visual selection. | |
| Advanced Motions | /{pattern}\% | Search forward for the pattern and highlight the results for efficient navigation. |
:normal! {motion} | Execute a motion command in normal mode (e.g., :normal! 3j will move the cursor down 3 lines). | |
:argdo {motion} | Execute a motion command across all files in the argument list. | |
/\%V{pattern} | Perform a search that restricts the search pattern to visual selection. |
╭── Delete
| Level | Command | Description |
|---|---|---|
| Basic | x | Delete the character under the cursor. |
X | Delete the character before the cursor. | |
d | Delete operator (combined with movement commands). | |
dw | Delete the current word (to the next space/punctuation). | |
dd | Delete the entire current line. | |
| Intermediate | d$ | Delete from the cursor to the end of the line. |
d0 | Delete from the cursor to the beginning of the line. | |
d^ | Delete from the cursor to the first non-blank character of the line. | |
dG | Delete from the cursor to the end of the file. | |
dgg | Delete from the cursor to the beginning of the file. | |
d3w | Delete three words starting from the cursor. | |
dF\<char> | Delete from the cursor to the first occurrence of <char> in the current line. | |
dT\<char> | Delete up to, but not including, the first occurrence of <char> in the current line. | |
| Advanced | d} | Delete to the next paragraph (block of text separated by blank lines). |
d% | Delete between matching parentheses, brackets, or braces. | |
d' | Delete from the cursor to the previous jump location. | |
d" | Delete text inside quotes (single or double). | |
daw | Delete a word including the surrounding whitespac | |
daf | Delete a paragraph | |
d2j | Delete two lines below the cursor. | |
dF\<char> | Delete up to and including the first occurrence of <char> in the current line. | |
dT\<char> | Delete up to but not including the first occurrence of <char> in the current line. | |
:g/foo d | Delete lines containing foo | |
:v/foo/d | Delete lines not containing foo | |
:/foo/,/bar/d | Delete from the first match of foo to first match of bar | |
:g/^$/d | Delete all empty line | |
:1,.d | Delete from top to current lin | |
:%d | Delete the entire fil | |
| Visual Mode | v + d | Delete the selected region (after entering visual mode). |
D | Delete from the cursor to the end of the line (in visual mode). | |
dG | Delete from the cursor to the end of the file (in visual mode). | |
dgg | Delete from the cursor to the beginning of the file (in visual mode). | |
| Insert Mode | Backspace | Delete the character before the cursor. |
Ctrl-W | Delete the word before the cursor in Insert Mode. |
Note that prepending the deletion commands with "_ allows to delete text without saving it into the default buffer (see more details here
).
╭── Search
| Level | Command | Description |
|---|---|---|
| Basic | /pattern | Search forward for a pattern. |
?pattern | Search backward for a pattern. | |
n | Repeat the last search in the same direction. | |
N | Repeat the last search in the opposite direction. | |
* | Search forward for the word under the cursor. | |
# | Search backward for the word under the cursor. | |
| Intermediate | /\<word\> | Search for the exact whole word “word”. |
/word\c | Search case-insensitively for “word”. | |
/word\C | Search case-sensitively for “word”. | |
:set ignorecase | Makes all searches case-insensitive by default. | |
:set noignorecase | Restores case-sensitive searching. | |
:set smartcase | Case-insensitive search unless uppercase is used in the pattern. | |
// | Repeat the last search pattern without retyping it. | |
/\vpattern | Uses “very magic” mode (treats most characters as regex special symbols). | |
| Advanced | /\cpattern | Case-insensitive search for a specific pattern. |
/foo|bar | Search for either “foo” or “bar”. | |
/foo.*bar | Search for “foo” followed later by “bar” on the same line. | |
/^pattern | Search for pattern at the beginning of a line. | |
/pattern$ | Search for pattern at the end of a line. | |
/\%23lpattern | Search for “pattern” on line 23. | |
:set hlsearch | Highlight all matches of the current search. | |
:set nohlsearch | Stop highlighting matches. | |
:nohlsearch | Temporarily stop highlighting (without changing the setting). | |
:set incsearch | Show incremental matches while typing the search. | |
:set nowrapscan | Prevent search from wrapping around the file. | |
:set wrapscan | Allow searches to wrap from end to start of file (default). | |
| Visual/Command Integration | gn | Visually select the next search match (useful for replacing). |
gN | Visually select the previous search match. | |
:g/pattern/d | Delete all lines that match the pattern. | |
:v/pattern/d | Delete all lines that don’t match the pattern. | |
:%s/pattern/replacement/g | Substitute all matches in the file with something else. | |
:%s//replacement/g | Replace using the last searched pattern. | |
| Advanced Search Motions | * | Search forward for the word under the cursor. |
# | Search backward for the word under the cursor. | |
g* | Search forward for the next occurrence of the word under the cursor (in a case-sensitive manner). | |
g# | Search backward for the previous occurrence of the word under the cursor (in a case-sensitive manner). |
╭── Replace
| Level | Command | Description |
|---|---|---|
| Basic | :s/old/new/ | Replace the first occurrence of old with new on the current line. |
:s/old/new/g | Replace all occurrences of oldwith new on the current line. | |
:s/old/new/c | Replace the first occurrence of old with new and ask for confirmation. | |
| Intermediate | :%s/old/new/g | Replace all occurrences of old with new in the entire file. |
:1,10s/old/new/g | Replace all occurrences of old with new between lines 1 and 10. | |
:%s/old/new/gc | Replace all occurrences of old with new in the whole file, with confirmation. | |
:s/old/new/n | Replace the n-th occurrence of old with new on the current line. | |
:s/old/new/gi | Case-insensitive search and replace of old with new on the current line. | |
:s/old/new/gI | Case-sensitive search and replace of old with new on the current line. | |
| Advanced | :%s/old/new/gc | Replace all occurrences of old with new in the whole file, with confirmation for each. |
:%s/\<old\>/new/g | Replace the exact word old with new globally (use word boundaries). | |
:%s/\<old\>/new/gc | Replace the exact word old with new globally with confirmation. | |
:s/\%Vold/new/g | Replace old with new, but restrict the replacement to the visual selection. | |
:%s/\%Vold/new/g | Replace old with new in the visual selection across the whole file. | |
:%s/\vpattern/replacement/g | Use very magic mode, where special characters in the pattern are treated as regex (e.g., .* for any character). | |
:%s/\vpattern\zs.*\ze/replacement/g | Use very magic mode and replace part of the pattern after a match. | |
| Search & Replace (with Visual Mode) | v + :s/old/new/g | Visual select a region, then replace old with new in that region. |
Ctrl-R + Ctrl-W + :s/old/new/g | Replace the word under the cursor in the visual selection. | |
| Interactive Replacement | :s/old/new/gc | Replace all occurrences of old with new, confirming each replacement. |
:args | List all files in the argument list, useful for replacing across multiple files. | |
| Multiple Files | argdo %s/old/new/g | Replace old with new in all files listed in the argument list. |
argdo %s/old/new/gc | Replace old with new in all files listed in the argument list, with confirmation. | |
| Command Integration | :g/pattern/s/old/new/g | Apply the substitution to all lines that match the pattern. |
:v/pattern/s/old/new/g | Apply the substitution to all lines that don’t match the pattern. | |
:g/pattern/d | Delete lines that match the pattern. | |
| Regular Expressions | :%s/\v(.*)(old)(.*)/\1new\3/g | Use regular expressions to match patterns and replace parts of the text. |
:%s/\v(\d+)/\=submatch(0)*2/g | Use Vim’s expression feature in substitution for complex replacements. |
More food for thoughts? Check other posts about: #(Neo)vim
Thanks for your read. Hope it's been useful to you.
✄ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈