Vim

From CleanPosts

Jump to: navigation, search

Contents

VIM COMMANDS

70 columns

set wm=60 

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   

Back one word

b 

Back screenful

^B 

Begin overstrike or replace mode, use ESC key to exit

R

Capitalize the first letter of each line

%norm gUl

Change

c 

Change current word to a new word

cw 

Close tab

tabc 

Copy all lines and put at end of file

1,$co$   

Create abbreviation

ab abbr phrase 

CTRl F - Forward screenful

^F 

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

d^ 

Delete all lines

%d 

Delete all lines in file

1,$d

Delete blank lines

v/\S/d

Delete character

x 

Delete [count] characters before the cursor

X 

Delete [count] lines

dd 

Delete {count} lines, starting with [range]

[range]d[elete] 

Delete

d 

Delete five lines

d5d 

Delete from current line to end of file

.,$d 

Delete lines 1 through 9

1,9d    

Delete lines x through y

x,yd 

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

D 

Delete to end of line

d$ 

Delete unicode character

%s/\%u200d//g 

Delete word backward

db 

Delete word from cursor on

dw 

Directory list

Explore 

Display file list

!ls 

Down half screenful

^D 

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

e[dit]!  

Edit {file}

e[dit] 

Edit the file whose name is under or after the cursor

gf 

Enable left-right scrolling

set nowrap 

Enter Insert mode, replacing characters rather than inserting

R 

Example 10G goes to line 10

nG or n 

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

r[ead] !{cmd} 

Exit Visual mode without making any change

<Esc> 

Filter through 'equalprg' option command

= 

Filter through external command

!  

Find match, ahead

/foo 

Find match, behind

?foo 

Find previous

N 

Force autowrap

set fo-=1 

Format lines to 'textwidth' length

gq 

Forward one word

w 

Get file

r filename 

Go to column 56

56|   

Go to file beginning

gg 

Go to file end

G 

Go to last tab

tabl 

Go to next line

+ 

Go to next tab

tabn 

Go to previous line

- 

Go to screen bottom

L 

Go to screen middle

M 

Go to screen top

H 

Highlight matches

set hlsearch 

indent line

>> 

Indent paragraph

5>>    

Insert

i 

Insert tab

TAB - 

Insert text at the beginning of the cursor line

I 

Insert text before the cursor [count] times

i 

Insert the file [name] below the cursor

r[ead] [name]

Join all lines ending in a hyphen and reformat to 80 character lines

g/-$/j
%s/- //g
%!par -w 80

Join lines 13 and 14

13,14j   

Join next line to the end of the current line

J 

Justify selected range to 40 columns wide

!par 40j 

List all the current marks not a motion command

marks 

Make backspace standard

set backspace=2 

Move cursor to the beginning of current line

0    

Move cursor to the end of current line

$ 

Move lines to end of file

1,10m$   

Moves the cursor down one line

j 

Moves the cursor one character to the left

h 

Moves the cursor one character to the right

l 

Moves the cursor up one line

k 

Move tab to position n

tabm n 

Number of lines for command line

set cmdheight=3 

One page backward

^b 

One page forward

^f 

Open new tab

tabnew filename 

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 

Paste after

p 

Paste from buffer 2 [there are 9]

"2p    

Paste twice

2p      

Pattern Search backward for the pattern

?  

Pattern Search forward for the pattern

/ 

Quit always, without writing

cq[uit] 

Quit current file and exit - same as "q!

ZQ 

Quit, no warning

q!  

Quit Vim. This fails when changes have been made

q[uit] 

Quit without writing

q[uit]!  

Quit with warning

q 

Read in sorted file

r !sort phone.txt 

Remove line breaks

w ++ff=unix 

Repeat command

.  

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

N 

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

n 

Replace a by nothing

g/a/s///g 

Replace <\/b> globally

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

Replace globally

1,$s/<b>//g     

Replace with null

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

Replace foo with newline

%s/foo/^M/g 

Replace old with new in range

50,100s/old/new/g      

Replace tabs with spaces

set retab 

Replace the character under the cursor with {char}

r{char} 

Replace the letter a, by blank

g/a/s// /g 

Replace with confirm

50,100s/old/new/gc     

Restore line

U 

Return the number of search matches

:%s/love//gn

Reverse order of file

g/^/m 0

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

[range]wq[!] [file] 

Scroll the screen so the cursor is at the bottom

zb 

Scroll the screen so the cursor is at the top

zt 

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

/{pattern}[/] 

Set 70 columns wide

set wm=60 

Set amount by which text is tabbed

set shiftwidth=4 

Set bar at column 70

set colorcolumn=70 

set wrapping

set wrap 

Shift left

< 

Shift right

> 

Show line numbers

set nu 

Show ruler

set ru 

Show tabs and end of lines

1,$l    

Sort file

1,$!sort   

Start editing a new file

e file 

Start Visual mode per character

v 

Switch case

~ 

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

`{A-Z0-9} 

Turn on ruler

set ruler 

Unabbreviate a word

una word 

Undent line

<< 

Undo last change

u 

Up half screenful

^U 

Visual block, by characters

CTRL-v 

Visual block, by lines

CTRL-V 

Visual mode, by line

V 

Write current file if modified and exit

ZZ 

Write file to disk and quit the editor

wq 

Write lines 10 through 25 into file named temp

10,25w temp   

Write lines to shell

1,10w !command  

Write out

w[!][>>] filename 

Write the current file and exit always

wq!  

Write visual block to clipboard

w !xclip -selection clipboard 

Write workspace to named file

w file 

Write workspace to original file

w 

Yank 5 lines

5yy   

Yank current line

Y 

Yank current line

yy 

Yank from cursor to end of current word

yw 

Yank line

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

Yank to end of current line from cursor

y$ 

Yank

y
Personal tools
Strangers In Paradise