VI (Path/) (Filename) Opens Filename (If Already Exist or Create A Bank File, in Command Mode) (The
VI (Path/) (Filename) Opens Filename (If Already Exist or Create A Bank File, in Command Mode) (The
VI (Path/) (Filename) Opens Filename (If Already Exist or Create A Bank File, in Command Mode) (The
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
Command mode-
Press Esc key to enter in command mode (if not already in)
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
Ctrl+f / Ctrl+b – forward / backward one screen; Ctrl+d / Ctrl+u – forward / backward half screen
Delete
dw / db / dnw / dnb – delete next word / previous word / n words from / n words before cursor
cw / cc - replace word / line with text ; c0/ c$ /c - change to beginning / end of 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)
: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)
:set nu /nonu – set on / turn off line numbering ; set ai / noai – set on / turn off autoindent
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)
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