Vim

vim Logo
Vim Logo

Vim is a well-known text editor used by all UNIX systems. It is based on vi ("visual") and which is based on ex again. The main advantages of Vim are less system requirements, configurability and it's spread. The most important opponent of Vim is the GNU Emacs editor. Vim is free and OpenSource.

Development of Vim text editor
Vim history

Getting started

CLI

Vim does not require any graphical user interface and can be started throughout the Command Line Interface / a terminal. In general, you don't have to type Vim, because in general vi starts vim. You can set the filename as the second argument (maybe a new file?)

vi Vim_file

Use option -R to view a file in readonly-mode

vi -R Vim_file

Use the UNIX manual man vi to get any further information. Use vimtutor to get a built-in tutorial.

Basics of Vim – modes and submit commands

There are two modes: Insert- and Commandline-Mode. After starting vim, you are in Commandline-Mode. You can always get into Commandline-Mode by pressing Esc. In Commandline-Mode press i to switch into Insert-Mode. To write the text "Hello World!" in a new file, use the following commands:

vi new_file

i

Hello World

:wq

Why did I highlight the commands differently? Well... the first command is a bash command (your shell has to proceed it). The second command is a Vim-command and will be inserted to the Vim command line (at the bottom of the Vim screen). And the last command is an ex-command. Vim tells ex to proceed the command (w = write; q = quit). Ex-commands always start with a colon. Prepend it, if not specified!

viStart vi
vi filenameStart vi and load file $filename
vi -R filename... in read-only Mode
iEnter Insert-Mode
wwrite file
qquit Vim
q!force quitting Vim (→ without saving changes)
Vim in Readonly Mode
Vim in Read-Only mode
ZZSave file and quit editor
iEnter Insert-Mode
ls
:ls
  1 %a  "file1.html"     line 1
  2     "file2.html"     line 13

show all opened files
eReload file
e!Force reloading file (→ without saving changes)

Navigation

hleft (one letter)
jdown (one line)
kup (one line)
lright (one letter)

GOTO

0(zero) jump to the beginning of the line
$jump to the end of the line
bprevious word
Bprevious word (but don't consider punctuations and symbols)
wnext word
Wnext word, but don't consider punctuations and symbols
+jump to 0 of the next line
-jump to 0 of the previous line
eend; jump to the end of the current word
Eend; jump to the end of the current word (but don't consider punctuations and symbols)

You can use the commands multiple times by prepending numbers. 5B will jump 5 words backwards.

Modifying and Buffering

aappend; append text to the current cursor position
cchange; only useful in combination with movement command
ddelete; delete content (and copy it to the buffer)
pput; insert content from the buffer
yyank; copy content into the buffer

You can use the commands multiple times by prepending numbers. 5B will jump 5 words backwards. c2b will change the two previous words.

redo and undo

redoredo
undoundo
uundo
Uundo all changes in current line unless you didn't move away

Stuff

Rtoggle to replacement mode (exit by pressing Esc)
~change letter at current position to uppercase/lowercase
dddelete the whole current line
Pput; insert content from the buffer BEFORE the cursor
xptranspose two letters
Jmerge two lines (append next line to current one)

You can use the commands multiple times by prepending numbers. 5B will jump 5 words backwards. c2b will change the two previous words.

Insert-Commands

Aappend text to end of line
Iinsert text at end of line
oopen line; create new empty line below current cursor position
OOpen line; create new empty line after current cursor position
ssubstitute; replace a letter
SSubstitute; replace a line

After executing those commands, you will be in insertion mode

Building commands

(command)(text unit)

eg. cw
eg. dw
eg. yw

(command)(number)(text unit) ...equals to...
(number)(command)(text unit)

eg. c2b
eg. 2cb

Examples

Object copy change delete
1 word yw cw dw
2 words without symbol consideration 2yW / y2W 2cW / c2W 2dW / d2W
3 word backwards 3yb / y3b 3cb / c3b 3db / d3b
1 line yy / Y cc dd
until end of line y$ c$ / C d$ / D
to beginning of line y0 c0 d0
single characters y1 / yh r x / X
5 characters 5y1 5s 5x

set

wm=10set wrapmargin to 10
nushow number of line