Child pages
  • 4. Text Editor
Skip to end of metadata
Go to start of metadata



There are lots of options that we can use to do text editing in Linux. This tutorial provides how to to text editing in Linux with vi and nano software.


The vi (pronounce: vee ay) editor is a screen-oriented text editor originally created for the Unix operating system. The vi editor is the most text editor that Linux users use for text editing. The vi editor has two modes: command and insert. The command mode allows the entry of commands to manipulate text. The insert mode puts anything typed on the keyboard into the current file. vi starts out in command mode. There are several commands that put the vi editor into insert mode. The most commonly used commands to get into insert mode are a and i. These two commands are described below. Once you are in insert mode, you get out of it by hitting the escape key. Except where indicated, vi is case sensitive. Below is list of the vi editor commands:

Cursor Movement Commands:
(n) indicates a number, and is optional
(n)hleft (n) space(s)
(n)jdown (n) space(s)
(n)kup (n) space(s)
(n)lright (n) space(s)
(The arrow keys usually work also)
^Fforward one screen
^Bback one screen
^Ddown half screen
^Uup half screen
(^ indicates control key; case does not matter)
Hbeginning of top line of screen
Mbeginning of middle line of screen
Lbeginning of last line of screen
Gbeginning of last line of file
(n)Gmove to beginning of line (n)
0(zero) beginning of line
$end of line
(n)wforward (n) word(s)
(n)bback (n) word(s)
eend of word
Inserting Text:
iinsert text before the cursor
aappend text after the cursor (does not overwrite other text)
Iinsert text at the beginning of the line
Aappend text to the end of the line
rreplace the character under the cursor with the next character typed
ROverwrite characters until the end of the line (or until escape is pressed to change command)
o(alpha o) open new line after the current line to type text
O(alpha O) open new line before the current line to type text
Deleting Text:
dddeletes current line
(n)dddeletes (n) line(s)
(n)dwdeletes (n) word(s)
Ddeletes from cursor to end of line
xdeletes current character
(n)xdeletes (n) character(s)
Xdeletes previous character
Change Commands:
(n)ccchanges (n) characters on line(s) until end of the line (or until escape is pressed)
cwchanges characters of word until end of the word (or until escape is pressed)
(n)cwchanges characters of the next (n) words
c$changes text to the end of the line
ct(x)changes text to the letter (x)
Cchanges remaining text on the current line (until stopped by escape key)
~changes the case of the current character
Jjoins the current line and the next line
uundo the last command just done on this line
.repeats last change
ssubstitutes text for current character
Ssubstitutes text for current line
:ssubstitutes new word(s) for old
:<line nos effected> s/old/new/g
&repeats last substitution (:s) command.
(n)yyyanks (n) lines to buffer
y(n)wyanks (n) words to buffer
pputs yanked or deleted text after cursor
Pputs yanked or deleted text before cursor
File Manipulation:
:w (file)writes changes to file (default is current file)
:wq writes changes to current file and quits edit session
:w! (file)overwrites file (default is current file)
:q quits edit session w/no changes made
:q! quits edit session and discards changes
:n edits next file in argument list
:f (name)changes name of current file to (name)
:r (file)reads contents of file into current edit at the current cursor position (insert a file)
:!(command)shell escape
:r!(command)inserts result of shell command at cursor position
ZZwrite changes to current file and exit


To start using vi editor, simply type vi followed by the text file that you want to edit or new text file that you want to create.

vi example

$ vi


$ vi data.txt



nano is a text editor for Unix-like computing systems or operating environments using a command line interface. nano is keyboard-oriented, controlled with control keys. For example,  Ctrl+O saves the current file;   Ctrl+W goes to the search menu. Nano puts a two-line "shortcut bar" at the bottom of the screen, listing many of the commands available in the current context. For a complete list,  Ctrl+G gets the help screen.

To start using nano editor, simply type nano followed by the text file that you want to edit or new text file that you want to create.

nano example

$ nano


$ nano data.txt



  • No labels