How To Speak To Vim

Why Vim?

  • Modal editor
  • Lightweight
  • Usable through SSH
  • Universal shortcuts (less, git diff...)

Vim Basics

Movements

h j k l
w b e

 for ←↑↓→

move around words

^ $

move to begin/end of line

Movements

tA fA
;

jump to character A

repeat the last "t" or "f" jump

%

move to matching parenthesis

Movements

gg G
123G

jump to beginning/end of file

jump to line 123

CTRL-U
CTRL-D

scroll up/down half a page

Movements

CTRL-I
CTRL-O

previous/next in the jump list

The jump list!

Actions

o O

new line and insert

i a
I

insertion mode

insert at beginning of line

A

insert at end of line

Essentials

d
y
p

delete (cut)

copy

paste

Actions

Essentials

u

undo

CTRL-R

recover

v
V
CTRL-V

select

select whole lines

select by block

Actions

Essentials

combine it with I and A :)

c
S cc
r

change (delete + insert)

change line

replace one character

Actions

Useful

> <
=

add/remove one indent

auto indent

Actions

Useful

Vim as Language

Sentences

Verb + Modifier + Noun

action + modifier + object

or

action + movement

=

Sentences

Examples

`daw`
`ci(`
`dtP`

delete a word

change inside parenthesis

delete until letter P

Sentences

Verbs (= actions)

d
...

delete

p

paste

c

change

y

copy

"yank"

=

indent

Sentences

Modifiers

i

inside

a

around

Sentences

Objects

w

word

p

paragraph

s

sentence

t

<tag>...</tag>

'

'...'

{

{...}

(

(...)

Sentences

Repeat your sentences!

Use

.

Search & Replace

Search & Replace 

Searching

/hello
n N

Searches 'hello' in the file

Jumps to next/previous occurence

(can be combined with an action!

e.g. "delete until first occurence of 'hello'")

*

Searches the word under the cursor

Search & Replace 

Highlight spaces or tabs

/ 

highlights space characters

/\t

highlights tab characters

:set hlsearch

↓

"slash space"

Search & Replace 

Replacing

:%s/hello/hi/g

Replace 'hello' by 'hi' in the whole file

Search & Replace 

Replacing

%s/hello/hi/g

Range '%'

= whole file

Option 'g'

= replace all occurrences of each line

Search & Replace 

Replace currently highlighted word

*

then

%s//new word/g

Other commands/tips

jump to next number of the line and increment/decrement it

CTRL-A CTRL-X
<C-X><C-F>

ctrl-x then ctrl-f successively

autocomplete filenames

References

  • https://yanpritzker.com/learn-to-speak-vim-verbs-nouns-and-modifiers-d7bfed1f6b2d

Registers

Registers

Copy/paste from different places

"

Prefix with      and a character (= register name)

"ay
"bp

Copy in register 'a'

Paste from register 'b

Registers

Special registers

"+
"%

System clipboard :)

Current filename

(doesn't work through SSH!)

deck

By Pierre Poupin