www-gem words

(neo)vim keybindings

Published on

vim 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

LevelCommandDescription
BasichMove cursor left by one character.
jMove cursor down by one line.
kMove cursor up by one line.
lMove cursor right by one character.
wMove cursor to the beginning of the next word.
eMove cursor to the end of the current word.
bMove cursor to the beginning of the previous word.
0Move 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.
IntermediateggMove cursor to the beginning of the file.
GMove cursor to the end of the file.
nMove cursor to the next match of the last search pattern.
NMove 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
vStart visual mode to select text (motion commands affect the selection).
Ctrl-dMove half a page down.
Ctrl-uMove half a page up.
{Move cursor to the beginning of the current paragraph.
}Move cursor to the beginning of the next paragraph.
HMove cursor to the top of the screen (visible area).
MMove cursor to the middle of the screen (visible area).
LMove cursor to the bottom of the screen (visible area).
Visual ModevStart visual mode (character selection).
VStart visual line mode (select whole lines).
Ctrl-VStart visual block mode (select block of text).
gvRe-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

LevelCommandDescription
BasicxDelete the character under the cursor.
XDelete the character before the cursor.
dDelete operator (combined with movement commands).
dwDelete the current word (to the next space/punctuation).
ddDelete the entire current line.
Intermediated$Delete from the cursor to the end of the line.
d0Delete from the cursor to the beginning of the line.
d^Delete from the cursor to the first non-blank character of the line.
dGDelete from the cursor to the end of the file.
dggDelete from the cursor to the beginning of the file.
d3wDelete 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.
Advancedd}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).
dawDelete a word including the surrounding whitespac
dafDelete a paragraph
d2jDelete 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 dDelete lines containing foo
:v/foo/dDelete lines not containing foo
:/foo/,/bar/dDelete from the first match of foo to first match of bar
:g/^$/dDelete all empty line
:1,.dDelete from top to current lin
:%dDelete the entire fil
Visual Modev + dDelete the selected region (after entering visual mode).
DDelete from the cursor to the end of the line (in visual mode).
dGDelete from the cursor to the end of the file (in visual mode).
dggDelete from the cursor to the beginning of the file (in visual mode).
Insert ModeBackspaceDelete the character before the cursor.
Ctrl-WDelete 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 ).

LevelCommandDescription
Basic/patternSearch forward for a pattern.
?patternSearch backward for a pattern.
nRepeat the last search in the same direction.
NRepeat 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\cSearch case-insensitively for “word”.
/word\CSearch case-sensitively for “word”.
:set ignorecaseMakes all searches case-insensitive by default.
:set noignorecaseRestores case-sensitive searching.
:set smartcaseCase-insensitive search unless uppercase is used in the pattern.
//Repeat the last search pattern without retyping it.
/\vpatternUses “very magic” mode (treats most characters as regex special symbols).
Advanced/\cpatternCase-insensitive search for a specific pattern.
/foo|barSearch for either “foo” or “bar”.
/foo.*barSearch for “foo” followed later by “bar” on the same line.
/^patternSearch for pattern at the beginning of a line.
/pattern$Search for pattern at the end of a line.
/\%23lpatternSearch for “pattern” on line 23.
:set hlsearchHighlight all matches of the current search.
:set nohlsearchStop highlighting matches.
:nohlsearchTemporarily stop highlighting (without changing the setting).
:set incsearchShow incremental matches while typing the search.
:set nowrapscanPrevent search from wrapping around the file.
:set wrapscanAllow searches to wrap from end to start of file (default).
Visual/Command IntegrationgnVisually select the next search match (useful for replacing).
gNVisually select the previous search match.
:g/pattern/dDelete all lines that match the pattern.
:v/pattern/dDelete all lines that don’t match the pattern.
:%s/pattern/replacement/gSubstitute all matches in the file with something else.
:%s//replacement/gReplace 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

LevelCommandDescription
Basic:s/old/new/Replace the first occurrence of old with new on the current line.
:s/old/new/gReplace all occurrences of oldwith new on the current line.
:s/old/new/cReplace the first occurrence of old with new and ask for confirmation.
Intermediate:%s/old/new/gReplace all occurrences of old with new in the entire file.
:1,10s/old/new/gReplace all occurrences of old with new between lines 1 and 10.
:%s/old/new/gcReplace all occurrences of old with new in the whole file, with confirmation.
:s/old/new/nReplace the n-th occurrence of old with new on the current line.
:s/old/new/giCase-insensitive search and replace of old with new on the current line.
:s/old/new/gICase-sensitive search and replace of old with new on the current line.
Advanced:%s/old/new/gcReplace all occurrences of old with new in the whole file, with confirmation for each.
:%s/\<old\>/new/gReplace the exact word old with new globally (use word boundaries).
:%s/\<old\>/new/gcReplace the exact word old with new globally with confirmation.
:s/\%Vold/new/gReplace old with new, but restrict the replacement to the visual selection.
:%s/\%Vold/new/gReplace old with new in the visual selection across the whole file.
:%s/\vpattern/replacement/gUse very magic mode, where special characters in the pattern are treated as regex (e.g., .* for any character).
:%s/\vpattern\zs.*\ze/replacement/gUse very magic mode and replace part of the pattern after a match.
Search & Replace (with Visual Mode)v + :s/old/new/gVisual select a region, then replace old with new in that region.
Ctrl-R + Ctrl-W + :s/old/new/gReplace the word under the cursor in the visual selection.
Interactive Replacement:s/old/new/gcReplace all occurrences of old with new, confirming each replacement.
:argsList all files in the argument list, useful for replacing across multiple files.
Multiple Filesargdo %s/old/new/gReplace old with new in all files listed in the argument list.
argdo %s/old/new/gcReplace old with new in all files listed in the argument list, with confirmation.
Command Integration:g/pattern/s/old/new/gApply the substitution to all lines that match the pattern.
:v/pattern/s/old/new/gApply the substitution to all lines that don’t match the pattern.
:g/pattern/dDelete lines that match the pattern.
Regular Expressions:%s/\v(.*)(old)(.*)/\1new\3/gUse regular expressions to match patterns and replace parts of the text.
:%s/\v(\d+)/\=submatch(0)*2/gUse 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.

✄ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈ ┈