Skip to main content

Tips and Tricks

Level up your Neovim skills with these essential techniques and productivity tips.

Essential Motions

Motions are the foundation of Vim efficiency. Master these to navigate code like a pro.

Character Movement

MotionDescription
hLeft
jDown
kUp
lRight

Tip: Avoid arrow keys! Your fingers stay on home row with hjkl.

Word Movement

MotionDescription
wNext word start
WNext WORD start (space-separated)
bPrevious word start
BPrevious WORD start
eNext word end
ENext WORD end

Example: 3w moves 3 words forward.

Line Movement

MotionDescription
0Start of line
^First non-blank character
$End of line
g_Last non-blank character

Screen Movement

MotionDescription
ggFirst line of file
GLast line of file
{number}GGo to line number
Ctrl+dHalf page down
Ctrl+uHalf page up
Ctrl+fFull page down
Ctrl+bFull page up
HTop of screen
MMiddle of screen
LBottom of screen
zzCenter current line

Find Movement

MotionDescription
f{char}Find char forward
F{char}Find char backward
t{char}Till char forward
T{char}Till char backward
;Repeat find forward
,Repeat find backward

Example: f( jumps to next (, ; jumps to the one after that.

Search Movement

MotionDescription
/{pattern}Search forward
?{pattern}Search backward
nNext match
NPrevious match
*Search word under cursor
#Search word under cursor (backward)

Operators

Operators perform actions on text. Combine them with motions for powerful editing.

Basic Operators

OperatorDescription
dDelete
cChange (delete + insert)
yYank (copy)
>Indent right
<Indent left
=Auto-indent
gUUppercase
guLowercase

Operator + Motion Examples

CommandDescription
dwDelete word
d$Delete to end of line
d0Delete to start of line
cwChange word
c$Change to end of line
yyYank entire line
y3jYank 3 lines down
>jIndent current + next line
gUwUppercase word

Double Operator (Line)

CommandDescription
ddDelete line
ccChange line
yyYank line
>>Indent line
<<Unindent line

Text Objects

Text objects let you operate on structured text. This is Vim's superpower!

Syntax: {operator}{a|i}{object}

  • a = "around" (includes delimiters)
  • i = "inside" (excludes delimiters)

Common Text Objects

ObjectDescription
wWord
sSentence
pParagraph
"Double quotes
'Single quotes
`Backticks
( or ) or bParentheses
[ or ]Square brackets
{ or } or BCurly braces
< or >Angle brackets
tHTML/XML tag

Text Object Examples

CommandDescription
diwDelete inner word
dawDelete around word (includes spaces)
ci"Change inside quotes
ca"Change around quotes
di(Delete inside parentheses
da{Delete around braces
citChange inside tag
vipSelect inner paragraph

Treesitter Text Objects (FtVim)

FtVim adds smart text objects via Treesitter:

CommandDescription
dafDelete around function
cifChange inside function
vacSelect around class
daaDelete around argument

The Dot Command

The . command repeats your last change. It's incredibly powerful!

Example: Changing Multiple Words

  1. ciw - Change inner word
  2. Type the new word
  3. Esc - Return to normal mode
  4. n - Find next occurrence (if searching)
  5. . - Repeat the change

Example: Adding Semicolons

  1. A; - Append semicolon to line
  2. Esc
  3. j - Move down
  4. . - Add semicolon to this line too

Macros

Macros record and replay keystrokes. Perfect for repetitive tasks.

Recording a Macro

  1. q{register} - Start recording (e.g., qa)
  2. Perform your edits
  3. q - Stop recording

Playing a Macro

CommandDescription
@{register}Play macro (e.g., @a)
@@Repeat last macro
5@aPlay macro 5 times

Macro Tips

  • Use 0 to start at line beginning (consistent starting point)
  • Use j to move to next line at end (for multi-line replay)
  • Test on one line before running on many

Example: Add Quotes Around Words

  1. Position cursor on first word
  2. qa - Start recording to register a
  3. ciw"Ctrl+r"" - Change word, add quotes, paste original
  4. j0w - Move to next line, first word
  5. q - Stop recording
  6. 10@a - Repeat 10 times

Registers

Registers are like multiple clipboards.

Types of Registers

RegisterDescription
"Default register
0Yank register (last yank)
1-9Delete history
a-zNamed registers
A-ZAppend to named register
+System clipboard
*Primary selection (Linux)
_Black hole (delete without saving)

Using Registers

CommandDescription
"ayYank to register a
"apPaste from register a
"+yYank to system clipboard
"+pPaste from system clipboard
"_dDelete without saving
:regView all registers

Tip: Access Last Yank

After yanking then deleting, your yank is in register 0:

"0p

Marks

Marks save positions you can jump back to.

Setting Marks

CommandDescription
m{a-z}Set local mark
m{A-Z}Set global mark (across files)

Jumping to Marks

CommandDescription
'{mark}Jump to mark's line
`{mark}Jump to exact position
''Jump to last position
``Jump to exact last position

Automatic Marks

MarkDescription
`.Last change
`"Last position when file closed
`[Start of last yank/change
`]End of last yank/change
`<Start of last visual selection
`>End of last visual selection

Search and Replace

Basic Replace

:s/old/new/      " Replace first on line
:s/old/new/g " Replace all on line
:%s/old/new/g " Replace all in file
:%s/old/new/gc " Replace all with confirmation

Replace Tips

PatternDescription
\<word\>Whole word only
.*Any characters
\nNewline
&The matched text
\1First capture group

Visual Mode Replace

  1. Select text with v
  2. :s/old/new/g - Replace in selection

Replace Word Under Cursor

  1. * - Search for word
  2. :%s//new/g - Replace (empty pattern = last search)

Splits and Navigation

Creating Splits

CommandDescription
<leader>|Vertical split
<leader>-Horizontal split
:vs {file}Vertical split with file
:sp {file}Horizontal split with file
KeymapDescription
<C-h>Move to left window
<C-j>Move to window below
<C-k>Move to window above
<C-l>Move to right window

Resizing Splits

CommandDescription
<C-w>=Equal size
<C-w>>Increase width
<C-w><Decrease width
<C-w>+Increase height
<C-w>-Decrease height

Productivity Tips

1. Use Relative Line Numbers

FtVim enables relative line numbers by default. Use them with motions:

  • 5j - Jump 5 lines down
  • 3k - Jump 3 lines up

2. Stay in Normal Mode

Spend most time in normal mode. Enter insert mode briefly, make changes, return to normal.

3. Avoid Repetitive Keystrokes

Bad: jjjjjjj
Good: 7j or use search/find

4. Use Visual Block Mode

Ctrl+v enters visual block mode. Great for:

  • Adding text to multiple lines: Ctrl+v, select, I, type, Esc
  • Removing columns: Ctrl+v, select, d

5. Quick Substitution

:%s/\<old\>/new/g - Replace whole words only

6. Jump to Matching Bracket

% jumps between matching (), [], {}

7. Indent Blocks Quickly

>i{ - Indent inside braces
<i{ - Unindent inside braces

8. Sort Lines

Visual select lines, then :sort

9. Remove Trailing Whitespace

:%s/\s\+$//e

10. Increment/Decrement Numbers

Ctrl+a - Increment number under cursor
Ctrl+x - Decrement number under cursor

Practice Resources

  • Run :Tutor in Neovim for interactive tutorial
  • Vim Adventures - Game to learn Vim
  • VimGolf - Challenges to improve efficiency
  • Practice daily - muscle memory takes time!