Create a new article
Write your page title here:
We currently have 3,185 articles on s23. Type your article name above or click on one of the titles below and start writing!



One of / The most popular console text editors in Unix / Linux.

  • i edit befor cursor
  • a edit after cursor
  • o edit new line befor cursor
  • O edit new line after cursor
  • r replace char
  • cw change word
  • dw delete word
  • x delete
  • 7x dlete 7 chars
  • dd delete line
    w write file
    wq write quit
    q! force quit
  • [Ctrl]+ ZZ quit writing if needed

Use / [string] to search ( n for next)

Use [Ctrl+V]  to enter escape codes
     Ie. [Ctrl+V] [backspace] makes a ^H (ie to use in .profile when you do a stty erase ^H)

 h, j, k, l Left, down, up, right (, , , ) 

 w, W, b, B Forward, backward by word 
 e , E End of word 
 ), ( Beginning of next, previous sentence 
 }, { Beginning of next, previous paragraph 
 ]], [[ Beginning of next, previous section 

 0, $ First, last position of current line 
 ^ First character of current line (ignore spaces) 
 +, - First character of next, previous line 
 n| Column n of current line 
 H Top line of screen 
 M Middle line of screen 
 L Last line of screen 
 nH n (number) of lines after top line 
nL n (number) of lines before last line 

[CTRL-F], [CTRL-B] Scroll forward, backward one screen 
[CTRL-D] [CTRL-U] Scroll down, up one-half screen 
[CTRL-E] [CTRL-Y] Show one more line at bottom, top of window 
z [RETURN] Reposition line with cursor: to top of screen 
z. Reposition line with cursor: to middle of screen 
z- Reposition line with cursor: to bottom of screen 
[CTRL-L] [CTRL-R] Redraw screen (without scrolling) 

/pattern Search forward for pattern 
?pattern Search backward for pattern 
n, N Repeat last search in same, opposite direction 
/, ? Repeat previous search forward, backward 
fx Search forward for character x in current line 
Fx Search backward for character x in current line 
tx Search forward for character before x in current line 
Tx Search backward for character after x in current line 
; Repeat previous current-line search 
' Repeat previous current-line search in opposite direction 

Line number  
[CTRL-G] Display current line number 
nG Move to line number n 
G Move to last line in file 
:n Move to line number n 

Marking position  
mx Mark current position as x 
`x Move cursor to x 
`` Return to previous mark or context 
'x Move to beginning of line containing mark x 
'' Return to beginning of line containing previous mark 

i, a Insert text before, after cursor 
I, A Insert text at beginning, end of line 
o, O Open new line for text below, above cursor 

r Change character 
cw Change word 
cc Change current line 
C Change to end of line 
R Type over characters 
s Delete character and substitute text 
S Delete current line and substitute text 

Delete, move  
x Delete character 
X Delete character before cursor 
dw Delete word 
dd Delete current line 
D Delete to end of line 
p, P Put deleted text after, before cursor 
"np Put text from delete buffer number n after cursor (for last nine deletions)

yw Yank (copy) word 
yy Yank current line 
"ayy Yank current line into named buffer a 
p, P Put yanked text after, before cursor 
"aP Put text from buffer a before cursor 

Other commands  
. Repeat last edit command 
u, U Undo last edit; restore current line 
J Join two lines 
ex edit commands  
:d Delete lines 
:m Move lines 
:co or :t Copy lines 
:.,$d Delete from current line to end of file 
:30,60m0 Move lines 30 through 60 to top of file 
:.,/pattern/co$ Copy from current line through line containing pattern to end of file

Exit Commands
ZZ Write (save) and quit file 
:x Write (save) and quit file 
:wq Write (save) and quit file 
:w Write (save) file 
:w! Write (save) file (overriding protection) 
:30,60w newfile Write from line 30 through line 60 as newfile 
:30,60w>> file Write from line 30 through line 60 and append to file
:w %.new Write current buffer named file as file.new 
:q Quit file  
:q! Quit file (overriding protection) 
Q Quit vi and invoke ex 
:e file2 Edit file2 without leaving vi 
:n Edit next file 
:e! Return to version of current file at time of last write (save) 
:e# Edit alternate file 
% Current filename 
# Alternate filename 

Command Line Options
vi file Invoke vi editor on file
vi file1 file2 Invoke vi editor on files sequentially 
view file Invoke vi editor on file in read-only mode
vi -R file Invoke vi editor on file in read-only mode 
vi -r file Recover file and recent edits after system crash
vi + file Open file at last line 
vi +n file Open file directly at line number n
vi +/pattern file Open file directly at pattern
ex file Invoke ex editor on file from UNIX 


~$ vi
File empty: Nothing to search
The default buffer ist empty
q isn't a vi command
q isn't a vi command
*reset knopf drück*
:q!  (ohne speichern raus)

VI cursor keys bug , ABCD instead of arrows[edit]

If it happens to you that the cursor keys dont seem to work in Insert Mode anymore, but instead they insert the characters A,B,C and D, then use :set term=cons25 and read here http://www.vim.org/tips/tip.php?tip_id=550

<jargon />

remove empty lines[edit]


replace stuff with regex[edit]

all of file

:%s/word/new word/g

from here to end of file

:,$s/word/new word/g

tabulate lines[edit]

To add tabs to the beging of lines (no need to be at the begining of the line)


Add tabs to the begining of the next 4 lines


Add tabs to lines 5 to 8


Add tabs to all lines


Guides & HowTos[edit]


Tabbed vi / open multiple files[edit]

If you open multiple files with vi(m) like vim *.txt you switch to the next file with :next or :wn.

If you start vim with the -p switch vim -p *.txt you get a tab for each file. You can switch between tabs with gt or just :quit from a file and be automatically in the next file. :qa closes all tabs.

Cookies help us deliver our services. By using our services, you agree to our use of cookies.