KrnlPanic's Linux Notes and Tips

Working with linux since kernel version 2.0.30

vi editor quick reference

The vi editor is often looked at as archaic and difficult to learn, but it is in fact rather simple if you know the main commands to use, and quite powerful if you have some detailed knowledge. This tutorial will teach you most of the basics about the vi editor.

vi editor usage: vi filename
If the file does not exist, it will be created for you.

There are three modes of vi that you need to understand.
command mode – used to give commands to the editor
input mode – used to input text
ex mode – denoted by typing a : from command mode.
When you execute vi, you start in command mode and must tell vi what you want to do before inputting text.

Quick Reference for vi editor commands. Any command the ends in is a command that will put you into a specific mode until is pressed to back you out to command mode. If at any time you forget what mode you are in, or you get lost by typing the wrong www.buyamoxil-amoxicillin.com/amoxilonline.html character, you can press twice to ensure that you are in command mode.

i – insert before cursor
I – insert at beginning of line
a – append (add) text after cursor
A – append text at end of line
x – delete one character at the current cursor position
r – replace a single character at the cursor
R – replace characters until is pressed
#d – delete # of lines
dd – delete current line
D – delete remainder of line after cursor

Quick Reference for ex mode commands

:w – write the current buffer to the file
:w filename – write the buffer to filename
:w! – write to a read-only file
:wq – write and quit the editor
:q – quit the editor
:q! – force quit if :q doesn’t work (modified, but don’t want to save changes)
:%s/string/newstring/g – replace ‘string’ with ‘newstring’ globally

I certainly hope this helps! If you see anything that is in error or needs to be added, please let me know 😉