bembry.org
Home / Technology / Linux

VI Reference Sheet

VI is the standard text editor available on all Unix and Linux systems, kind of like Notepad on Windows. This sheet shows some basic VI commands for folks just getting started text editing from a Linux command line.

^ -- Move cursor to beginning of line

% -- Finds matching (, { or { symbol

$ -- Move cursor to end of line

ESC -- Escape button takes you out of edit mode

d -- in visual mode, delete highlighted text

d$ -- Delete to end of line (copy into register)

dd -- Delete entire line (copy into register)

de -- Delete to end of word (copy into register)

CTRL-G -- Show current cursor position

#G -- Go to line # (replace # with number)

i -- Insert text / Start insert mode.

o -- Open a new line under the current line.

p -- Paste contents of register

R -- Replace text as you type (type-over)

r# -- Replace letter under cursor with # (replace # with letter)

u -- Undo

v -- Start visual mode for highlighting text

x -- Delete character under cursor

X -- Capital X. Backspace.

y -- In visual mode, copy highlighted text to register

Command Line Mode:

:e filename -- Open a new editor with "filename"

!dir -- Gives a listing of files in current directory

:help -- Get help while using VI

:j! -- Join current line with the following line

:new -- Open a new empty editor file

:q! -- Quit without saving

:r file -- Insert contents of "file" at cursor position

:%s/oldword/newword/g -- Search for "oldword" and replace with "newword" starting at the current line.

/text -- Search for "text"

:w -- Save the file. Follow with a filename if desired.

:wq -- Save and quit

Restricted access