Vi and why it is great
Vi (vim) Cheat Sheet
This editor is a text editor available on all unix-like platforms, meaning any computer other than a windows computer, including from Sun, Apple, etc.
Vi is also powerful for these reasons:
1. It can open any file of any size without crashing the computer
2. It does syntax highlighting for programming, meaning it's easier to read what programming codes you've done
3. It understands "regular expressions" which are ways of searching. So for example, in Word, if you search for "cat", it will return "cat" and "catheter" and "catastrophe", but that's it. In Vi you can match unspecific things like "???" which will find any three-letter word, and for example "?a?" will find "Cat", "sat", "mat".
4. It does not put carriage returns into files automatically. This is important to stop file corruption especially code files like DNA databases or anything else that's very big.
vi has two modes: editing and command. Command mode is used to issue and and all commands, including moving around and saving. Editing mode is just for
inserting text.
To enter command mode, press esc. To enter editing mode, use one of the text insertion commands below.
Commands
These are the most useful commands but the list is not exhaustive. Most commands can be preceeded by a number indicating the number of times to repeat the command.
Keystroke |
Meaning |
:q |
quit |
:w |
write (save) |
:o |
open (load a file) |
! |
used after :w or :q or :wq to force it |
ZZ |
same as :wq |
control-F, control-B |
forward and backward a page |
i |
insert text |
o |
open and insert a new line |
a |
insert and place cursor after current character |
g |
go to line number, eg., 5g, 20g |
n |
next instance of search criterion |
/ |
search |
$ |
end of line |
() |
beginning or end of paragraph |
. (dot, fullstop) |
repeat last command. Eg., 5x is delete 5 letters, typing a dot will redo this |
x |
delete current character |
dd |
delete current line |
r |
replace current character. Eg., re replaces the current letter or number with an e. |
shift-U |
undo |
shift-J |
join two lines, justify |
yp |
copy and paste an entire line |
:1, $ s/\r/ |
get rid of ^M in the file |
:%s/oldText/newText/g |
find all instances of oldText and replace with newText globally |