DEV Community

Cover image for Vim Tips
Ding Fan
Ding Fan

Posted on

1

Vim Tips

If you know nothing about vim, you can also read this and feel the power.

Remember, there is a tutor at your service anytime in your terminal. Just summon the tutor with vimtutor . What? You haven't install vim? Never mind.

The first thing you need to know about vim is HOW TO QUIT

quit

:q!
quit a vim editor without saving

If you are using VSCode extension Vim, you don't need to "quit" ;)


aCharacter should be replaced with character you want
aString should be replaced with string you want

motion

j / k / h / l
down, up, left, right
I think j is down because usually we read a file from top to bottom
so we can press j with index finger

gg / G
move to start / end of this file

0 / $
move to start / end of this line

^
move to first character of this line

ctrl + o / ctrl + i
move cursor to previous / next position

# / *
move cursor to previous / next occurrence of current word under cursor

ctrl + w
switch between panels

ctrl + b / ctrl + f
move backward / forward a page
In VSCode: If you check fold fix, this might not work

ctrl + u / ctrl + d
move up / down half page
In VSCode: If you check fold fix, this might not work

editing

ciw
change in word

diw
delete in word

d/ c / y + i + ({["'
delete / change / yank in () {} [] "" '' and etc
you will love this

dt aCharacter
delete to aCharacter

>> / <<
increase / decrease indentation

A
append to the end of this line

I
insert at the start of this line

J
join current line with next line

r + enter
replace character under cursor with enter

D
delete to the end of this line

dd
delete this line

~
toggle letter case

.
repeat last text change

u / ctrl + r
undo / redo
In VSCode: this might be unreliable, enter insert mode and use ctrl + z for the rescue

function

za
toggle folding
In VSCode: If you ran into trouble with motion, ctrl + , open settings, search vim fold , check fold fix.

:%s/foo/bar/g
% in all lines s substitute foo with bar g every occurrence in corresponding line

/ aString
search aString
press enter move cursor to the occurrence of aString
press n move cursor to next occurrence of aString
press N move cursor to previous occurrence of aString

ctrl + , open settings, search vim clip , check use system clipboard to use system clipboard

ctrl + , open settings, search vim easy , check enable easymotion plugin, now you can use \\ with hjkl

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

While many AI coding tools operate as simple command-response systems, Qodo Gen 1.0 represents the next generation: autonomous, multi-step problem-solving agents that work alongside you.

Read full post

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay