Vim

From CleanPosts

Jump to: navigation, search

Contents

VIM COMMANDS

Move cursor to the beginning of current line

0

Write lines 10 through 25 into file named temp

10,25w temp

Move lines to end of file

1,10m$

Write lines to shell

1,10w !command

Join lines 13 and 14

13,14j

Delete lines 1 through 9

1,9d

Copy all lines and put at end of file

1,$co$

Delete all lines in file

1,$d

Show tabs and end of lines

1,$l

Replace <\/b> globally

1,$s/<\/b>//g

Replace globally

1,$s/<b>//g

Replace with null

1,$s/<\/b>//g

Sort file

1,$!sort

Paste from buffer 2 [there are 9]

"2p

Paste twice

2p

Replace with confirm

50,100s/old/new/gc

Replace old with new in range

50,100s/old/new/g

Go to column 56

56|

Indent paragraph

5>>

Yank 5 lines

5yy

Append text after the cursor [count] times

a

Append text at the end of the line [count] times

A

Append to end of current line

A

Create abbreviation

ab abbr phrase

Yank line

[address]y[a-z][count]

To the mark {A-Z0-9} in the correct file

`{A-Z0-9}

Back one word

b

Back screenful

^B

One page backward

^b

Change

c

Quit always, without writing

cq[uit]

Visual block, by characters

CTRL-v

Visual block, by lines

CTRL-V

Change current word to a new word

cw

Delete five lines

d5d

Delete word backward

db

D caret, not CTRL d - Delete to beginning of line

d^

Delete [count] lines

dd

Delete

d

Delete all lines

%d

Delete from current line to end of file

.,$d

Delete the characters under the cursor until the end of the line

D

Delete to end of line

d$

Down half screenful

^D

Delete word from cursor on

dw

Edit {file}

e[dit]

Edit {file} always. Discard any changes to the current buffer

e[dit]!

Start editing a new file

e file

Exit Visual mode without making any change

<Esc>

Directory list

Explore

CTRl F - Forward screenful

^F

Filter through 'equalprg' option command

=

Filter through external command

!

One page forward

^f

Find match, ahead

/foo

Find match, behind

?foo

Replace a by nothing

g/a/s///g

Replace the letter a, by blank

g/a/s// /g

Edit the file whose name is under or after the cursor

gf

Go to file beginning

gg

Go to file end

G

Go to next line

+

Go to previous line

-

Format lines to 'textwidth' length

gq

Go to screen top

H

Moves the cursor one character to the left

h

Insert

i

Insert text at the beginning of the cursor line

I

Insert text before the cursor [count] times

i

indent line

>>

Join next line to the end of the current line

J

Moves the cursor down one line

j

Moves the cursor up one line

k

Go to screen bottom

L

Moves the cursor one character to the right

l

Display file list

!ls

List all the current marks not a motion command

marks

Go to screen middle

M

Move cursor to the end of current line

$

Find previous

N

Example 10G goes to line 10

nG or n

Repeat the latest "/" or "?" [count] times

n

Repeat the latest "/" or "?" [count] times in opposite direction

N

Open up a new line following the current line and add text there

o

Open up a new line in front of the current line and add text there

O

Justify selected range to 40 columns wide

!par 40j

Pattern Search backward for the pattern

?

Search forward for the [count]'th occurrence of {pattern}

/{pattern}[/]

Pattern Search forward for the pattern

/

Paste after

p

Quit, no warning

q!

Quit with warning

q

Quit Vim. This fails when changes have been made

q[uit]

Quit without writing

q[uit]!

Delete {count} lines, starting with [range]

[range]d[elete]

Same as above, but only write the lines in [range]

[range]wq[!] [file]

Begin overstrike or replace mode, use ESC key to exit

R

Replace the character under the cursor with {char}

r{char}

Execute {cmd} and insert its standard output below the cursor

r[ead] !{cmd}

Insert the file [name] below the cursor

r[ead] [name]

Enter Insert mode, replacing characters rather than inserting

R

Repeat command

.

Get file

r filename

Read in sorted file

r !sort phone.txt

Make backspace standard

set backspace=2

Number of lines for command line

set cmdheight=3

Set bar at column 70

set colorcolumn=70

Force autowrap

set fo-=1

Highlight matches

set hlsearch

Enable left-right scrolling

set nowrap

Show line numbers

set nu

Replace tabs with spaces

set retab

Turn on ruler

set ruler

Show ruler

set ru

Set amount by which text is tabbed

set shiftwidth=4

70 columns

set wm=60

Set 70 columns wide

set wm=60

set wrapping

set wrap

Replace foo with newline

%s/foo/^M/g

Shift left

<

Shift right

>

Delete unicode character

%s/\%u200d//g

Switch case

~

Close tab

tabc

Insert tab

TAB -

Go to last tab

tabl

Move tab to position n

tabm n

Open new tab

tabnew filename

Go to next tab

tabn

Unabbreviate a word

una word

Undent line

<<

Restore line

U

Undo last change

u

Up half screenful

^U

Start Visual mode per character

v

Visual mode, by line

V

Remove line breaks

w ++ff=unix

Write out

w[!][>>] filename

Write workspace to named file

w file

Forward one word

w

Write file to disk and quit the editor

wq

Write the current file and exit always

wq!

Write workspace to original file

w

Write visual block to clipboard

w !xclip -selection clipboard

Delete character

x

Delete [count] characters before the cursor

X

Delete lines x through y

x,yd

Yank from cursor to end of current word

yw

Yank

y

Yank current line

Y

Yank to end of current line from cursor

y$

Yank current line

yy

Scroll the screen so the cursor is at the bottom

zb

Quit current file and exit - same as "q!

ZQ

Scroll the screen so the cursor is at the top

zt

Write current file if modified and exit

ZZ

Personal tools
Strangers In Paradise