0% found this document useful (0 votes)
36 views

Basic Vi Commands

This document provides a summary of basic commands for the vi text editor. It outlines commands for navigating and editing text, including moving the cursor, inserting and deleting text, searching, and saving files. Some key commands include using j, k, h, and l to move the cursor; i, a, and o to insert text; x and dw to delete characters and words; / to search forward and ? to search backward.

Uploaded by

deepak_gen
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

Basic Vi Commands

This document provides a summary of basic commands for the vi text editor. It outlines commands for navigating and editing text, including moving the cursor, inserting and deleting text, searching, and saving files. Some key commands include using j, k, h, and l to move the cursor; i, a, and o to insert text; x and dw to delete characters and words; / to search forward and ? to search backward.

Uploaded by

deepak_gen
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

17/5/2014 Linux Tutorial For Beginners..: Basic Vi Commands...

http://linuxtutorial4beginner.blogspot.in/2013/12/basicvicommands.html 1/3
Basic Vi Commands...
To Start vi :
1. vi filename Create or Edit filename starting at line 1
2. vi -r filename Recover filename that was being edited
when system crashed
To Exit vi :
1. :x<return> Quit vi, writing out modified file to file
named in original invocation
2. :wq<return> Quit vi, writing out modified file to file
named in original invocation
3. :q<return> Quit or exit vi
4. :q!<return> Quit vi even though latest changes have not
been saved for this vi call
Moving the cursor :
1. j or <return> Move cursor down one line
[or down-arrow]
2. k[or up-arrow] Move cursor up one line
3. h or<backspace> Move cursor left one line
[or left-arrow]
l or<space>[or right-arrow] Move cursor right one line
4. 0(zero) Move cursor to start of current line(the one with the arrow)

5. $ Move cursor to end of the current line
6. w Move cursor to beginning of next word
7. b Move cursor back to beginning of preceding word
8. :0<return> or 1G Move cursor to first line in file
9. :n<return>or nG Move cursor to line n in file
10. :$<return>or G Move cursor to last line in file
Screen Manipulation :
1. ^f Move forward one screen
2. ^b Move backward one screen
17/5/2014 Linux Tutorial For Beginners..: Basic Vi Commands...
http://linuxtutorial4beginner.blogspot.in/2013/12/basicvicommands.html 2/3
3. ^d Move down(forward) one half screen
4. ^u Move up(back)one half screen
5. ^l Redraws the screen
6. ^r Redraws the screen, removing the deleted lines
Adding, Changing, Deleting the text :
1. u Undo whatever you just did(a simple toggle)
Inserting or Adding text :
1. i Insert text before cursor, until<esc>hit
2. I Insert text at beginning of current line, until<esc>hit
3. a Append text after cursor, until<esc>hit
4. A Append text to end of current line, until<esc>hit
5. o Open and put text in a new line below current line, until<esc>hit
6. O Open and put text in a new line above current line, until<esc>hit
Changing the text :
1. r Replace single character under cursor(no <esc>needed)
2. R Replace characters, starting with current cursor position, until<esc>hit
3. cw Change the current word with new text, starting with the character under
cursor,until<esc>hit
4. cNw Change N words beginning with the character under cursor, until<esc>hit
5. c Change(replace)the characters in the current line,until<esc>hit
6. cc Change(replace)the characters in the current line,stopping when <esc>hit
7. Ncc or cNc Change(replace)the next N lines, starting with the current line, stopping
when <esc>hit
Deleting the text :
1. x Delete single character under cursor
2. Nx Delete N characters, starting with character under cursor
3. dw Delete the single word beginning with character under cursor
17/5/2014 Linux Tutorial For Beginners..: Basic Vi Commands...
http://linuxtutorial4beginner.blogspot.in/2013/12/basicvicommands.html 3/3
4. dNw Delete N words beginning with character under cursor
5. D Delete the remainder of the line, starting with current cursor position
6. dd Delete entire current line
7. Ndd or dNd Delete N lines beginning with the current line
Cutting and pasting the text :
1. yy Copy (yank,cut) the current line into buffer
2. Nyy or yNy Copy(yank, cut) the next N lines, including the current line, into the
buffer
3. p Put(paste) the lines in the buffer into the text after the current line
Searching the text :
1. /string Search forward for occurence of string in text
2. ?string Search backward for occurence of string in text
3. n Move to next occurence of search string
4. N Move to next occurence of search string in opposite direction
Determining line numbers :
1. :.= Returns line number of current line at bottom of screen
2. := Returns the total number of lines at bottom of the screen
3. ^g Provides the current line number, along with the total number of lines, in
the file at the bottom of the screen
Saving and reading files :
1. :r filename<return> Read file named filename and insert after current line(the line with
arrow)
2. :w<return> Write current contents to a file named in original vi call
3. :w newfile<return> Write current contents to a new file named newfile
4. :12,35w smallfile<return> Write the contents of the line numbered 12 through 35 to a new
file named smallfile
5. :w! prevfile<return> Write current contents over a pre-existing file named prevfile

You might also like