Editor
Many editors are available in unix /linux like vi, pico, neon, joe, ed, sed etc.
vi - visual editor
There are two modes of operations- command mode and editing mode.
vi editor is started in command mode. You can move around in file, load, save file (s), delete a
character, word(s), line(s) in a file.
Insert mode- to use to edit (insert) the contents (characters) in the file. Esc key is pressed to return
back to command mode, whereas to enter in insert mode many commands are available
(i,I,o,O,u,U,a,A).
Commands-
vi [path/][filename ]; opens filename (if already exist or create a bank file, in command mode) [ the
file name and size appear at the bottom of the screen , the cursor is in the top left corner of the
screen , one screen full of text appears. In case of new (blank) file first column of all lines are
displayed with ~ symbol], filename / path optional
Insert mode
to enter in insert mode-press following key (Enter is displayed in the bottom of the screen)
a - append text after cursor ; A - append text at the end of the line
i - insert text before the cursor; I - insert text at beginning of the line
o - insert (open) a blank line after the current (cursor) line
O - insert (open) a blank line before the current (cursor) line
Command mode-
Press Esc key to enter in command mode (if not already in)
Quit and/or save
:q - quit vi (back to command prompt), if any changes have made vi warn
:q! - quit without writing edit buffer to disk (file)
:w - write edited file in disk (like save in same file)
: w filename - write edited file in disk by filename (like save as)
:wq - edited file in disk and quit vi
ZZ - edited file in disk and quit vi
Moving in text file
Left arrow / backspace / h – move left one character; right arrow / space bar / l – move right
one character
w - beginning of next word ; nw - beginning of next nth word ;b – back to previous word
nb – back to previous nth word ; e – end of next word ; ne – end of next nth word
down arrow / j – down one line; up arrow / k – up one line
+ - beginning of next line (down) ; - - beginning of previous line (up)
0 / ^ / $ - first column / first character/ last character of current line
( / { - beginning of sentence/ paragraph ; ) / } - end of sentence/ paragraph
Ctrl+f / Ctrl+b – forward / backward one screen; Ctrl+d / Ctrl+u – forward / backward half screen
H / M / L - top line / mid line / last line of current screen
nG / G – nth line / last line of the file
Delete
x / dh / nx – delete character at / before / n characters at cursor
dw / db / dnw / dnb – delete next word / previous word / n words from / n words before cursor
d0 / d$ / D – delete to beginning of /end of line of cursor
dd / ndd – delete of current / n lines from current line
d( / d{ - delete to beginning of sentence /paragraph ; d( / d{ - delete to end of sentence /paragraph
Text change (press Esc when entered text ends)
cw / cc - replace word / line with text ; c0/ c$ /c - change to beginning / end of line
c( / c{ - change to beginning of sentence / paragraph ; c) / c} - change to end of sentence / paragraph ;
r - overwrite one character ; R - overwrite text until Esc pressed ; J – loin two lines
Cut / paste and copy /paste line
ndd – cut n lines (placed in buffer) ; p / P - paste contents of buffer after/ before current line
yy / nyy – copy one / n lines into buffer (yank) ; p / P- paste contents of buffer after/ before current line
(buffer contents does not change until new editing command overwrite the buffer)
/string / ?string – search forward / backward for string
:1-ns/ old string/new string/g – substitute first occurrence of old string by new string in lines 1 to n
:%s/ old string / new string/g – substitute all occurrence of old string by new string in entire file
u – undo the last command ; . – repeat last command ; :!cmd – execute unix command cmd (press Enter
to back to editor)
r filename – insert (read) contents of filename after current line
: !fmt – reformat the entire file
:set nu /nonu – set on / turn off line numbering ; set ai / noai – set on / turn off autoindent
: set showmode – display insert mode at bottom
Pico / nano / joe are simple menu based text editors.
These are far easier to use than vi, with the trade off that they are not as powerful.
pico [path] [filename] - open /create file name (filename is optional) (or use nano)
The basic commands provided by pico or nano includes:
CTRL+G - get help ; CTRL+X - exit ;
CTRL+O - write out to a file ; CTRL+C - cursor position information
CTRL+J - justify text ; CTRL+R - read a file
CTRL+W - where is (search) ; CTRL+Y - previous page
CTRL+B - move backward a character ; CTRL+K - cut text
CTRL+U - uncut text / paste ; CTRL-T - check spelling
CTRL+F - move forward a character ; CTRL+V - next page ;
CTRL+L - refresh the display ; CTRL+N - move to the next line
CTRL+^ - mark cursor position as start of selected text
CTRL+P - move to the previous line
CTRL+A - move to the beginning of the current line
CTRL+E - move to the end of the current line
CTRL+D - delete the character at the cursor position
CTRL+I - insert a tab at the current cursor position
joe [path] [filename] - open /create file name
The basic commands provided by joe includes:
CTRL+K+H – get help (shows the menu in top the text field)
CTRL+K+X – save ;CTRL+C - abort; CTRL+K+Z – shell
CTRL+K+E - edit; CTRL+K+ - insert CTRL+K+D – save
CTRL+D – delete char; CTRL+Y – delete line ; CTRL+W – delete word (left);
CTRL+O – delete word (right); CTRL+^_ – undo ; CTRL+^^ – redo ;
CTRL+K+B- block select begin ; CTRL+K+K- block select end
CTRL+K+M- block move ; CTRL+K+C- block copy
CTRL+K+W- block to file ; CTRL+K+Y- block delete