103.8 Perform basic file editing operations using vi

Key Knowledge Areas

  • Navigate a document using vi.
  • Use basic vi modes.
  • Insert, edit, delete, copy and find text.

Terms and Utilities

  • vi
  • /, ?
  • h,j,k,l
  • i, o, a
  • c, d, p, y, dd, yy
  • ZZ, :w!, :q!, :e!

Basic navigation:

h, j, k, l : left, down, up, right

Jump around:

H : top of screen
L : bottom of screen
G : end of file
gg: 1st line of file

CTRL+D: scroll down half screen
CTRL+U: scroll up half screen
CTRL+E: scroll window down 1 line
CTRL+Y: scroll window up 1 line

w : move forward one word
b : move backward one word

Screen - adjust/position

z<CR> : make the current line the window top
z.    : ... window center
z-    : ... window bottom


/pattern   search next line matching pattern
?pattern   search prev line matching pattern
n : repeat last / or ?  (=> next match)
N : reverse last / or ? (=> previous match)


x : delete at cursor position
X : delete the character left of the cursor position
s : delete char at current pos and enter insert mode
S : delete whole line and enter insert mode  
D : delete the rest of the line from current cursor pos

Insert + Replace:

a : append after cursor
A : append at end of line
i : insert before
I : insert at beginning of line
o : insert (open) line below
O : insert (open) line above
r : replace the the character at cursor pos
R : start replaceing characters at cursor pos


.      : repeat the last command  
J      : join lines
:e file: load file instead the currently loaded file (force with :e! file)
:r file: insert contents of the given file after the current cursor pos
:! cmd : execute command cmd in a subshell

Basic vi modes

There are two modes of operation: insert (press i in command mode) and command (press ESC in insert mode).

In command mode every key strike is a command to vi - you can navigate the text or enter commands. In insert mode you enter text.

Work with text

lpic/103.8.txt · Last modified: 2014-07 by tb
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0 ipv6 ready