Skip to content
Yoshiyuki Hisamatsu edited this page Nov 15, 2025 · 3 revisions

My Vim Environment


Vim Commands and Tips Collection!

Vim Commands

Command Mode


Move to end of line

$

Move to beginning of line

0

Next page

C_f

Half page down

C_d

Half page up

C_u

Previous page

C_b

To bottom of screen

S_l

To middle of screen

S_m

To top of screen

S_h

Next tab

gt

Previous tab

gT

To first line

gg

To last line

G

To end of current word

e

To next word

w

To previous word

b

Copy line

yy

Duplicate line

Yp

Paste

P

Paste on current line

P

Paste on next line

p

Undo

u

Redo

C_r

Open line below and enter insert mode

o

Open line above and enter insert mode

O

Center current line on screen

zz

Delete line and enter insert mode

S

Delete 2 lines

dj

Delete word

dw

Delete to end of line

d$

Delete 3 words

3dw

Same as above

d3w

Replace character below cursor

r

Replace one or more characters

R

Jump to next jump position

C_i

Jump to previous jump position

C_o

Useful when you want to return to your previous location after searching


Delete word from cursor position and enter insert mode

cw

Delete everything after cursor

D

Delete everything after cursor and enter insert mode

C

Jump to matching bracket

%

Search for word under cursor

*

Search for "hoge"

/hoge

Show search history

q/

Next search result

n

Previous search result

N

Jump to character '6' on current line

f6

Open fold

zo

Close fold

zc

Visual mode

v

Visual line mode

V

Visual block mode

C_v

Yank inside double quotes (when executed inside quotes)

yi"

Delete inside double quotes (when executed inside quotes)

di"

Delete inside parentheses (when executed inside parentheses)

di(

Delete including double quotes

da"

Delete from cursor position to "

dt"

Save from cursor to end of line in register 'a'

"av$yy

Increment number

C_a

Execute command with !

:!ls

Set current directory to hoge

:cd ~/hoge/

Replace foo with bar (current line)

:s/foo/bar

Replace foo with bar (all lines)

:%s/foo/bar

Split window horizontally, or C+w,s

:sp

Split window vertically, or C+w,v

:vsp

Move between windows

C_w_w

Move to window below

C_w_j

Move to window above

C_w_h

Set current directory to open file's directory

:CdCurrent

Grep word "hoge" from hoge.js

:vimgrep /hoge/ ./hoge.js

Show grep results

:copen

Case-insensitive grep for "jquery", "| cw" opens QuickFix if matches found

:vim[grep] /jquery/j ~/Dropbox/*.js | cw

Format code

=

Repeat last command

. (period)

Open new tab

:tabnew

Set mark - ma sets mark 'a'

ma

Show valid marks

:marks

Jump to mark (backtick is Shift_@)

`a

Go to line 10

:10

Go to 50% of document

50%

Insert Mode

Insert same character as line above

C_y

Insert same character as line below

C_e

Toggle case of character under cursor

~

Convert entire word to uppercase

gUiw

Convert entire line to uppercase

gUU

Enter tutorial mode - doing this makes a huge difference

:Tutorial

Vim Tips

Add text to beginning of multiple lines

Press C_v then I to enter insert mode, text entered will be applied to all lines after Esc

Add text to end of multiple lines

Press C_v then A to enter insert mode, press $ to go to end, text entered will be applied to all lines after Esc

Paste yanked content after deleting other lines

Yank → Delete → "0P

Save yank to specific register

"ay

Delete lines containing specific text

:%g/hisasann/d

Keep only lines containing specific text and delete others

:%v/hisasann/d

Yank lines containing specific text

:let @a=''
:%g//y A

Yank one line (including newline)

v$y

Yank one line (excluding newline)

vg_y

Delete one character in insert mode

C_h

Clone this wiki locally