Home

vim

Introduction

Common usage

Move the cursor

Open multiple files

up

Introduction

Vim is a highly configurable text editor built to make creating and changing any kind of text very efficient. It is included as "vi" with most UNIX systems and with Apple OS X.

up

Common usage

* type: vim file-name.

* press "i", "o", or "a", switch to insert mode, input the text you need.

* press "Esc", switch to command mode, then type ":wq" to save and quit the vim(just type "q" to quit if you didn't make any change, or "q!" quit without change).

up

Move the cursor

The basics
The first and the last
Moving Relative to the Screen
Jump between words
Moving cursor by searching a single character
Just move screen
Others
up

Open multiple files

Split the screen to open multiple files
Use -d option to see the difference between two files

vim -d file1 file2

Image which shows difference between two files

Use -o option or :split command split the screen horizontally:

vim -o file1 file2
OR vim file1, then :split file2

Image for split command

Use -O option or :vsplit(or vsp) command split the screen vertically:

vim -O file1 file2
OR vim file1, then :vsp file2

image for vsplit command

You can navigate between each split by using the key combination ctrl-wand then the direction key in which you want to move.

Use -p option or :tabnew command to open multiple files in tabs:

vim -p file1 file2
OR vim file1, then :tabnew file2.
use :tabn(ext) or gt to go to the next tab page. Wraps around from the last to the first one.
use :tabp(revious) or gT to go to the previous tab page. Wraps around from the first one to the last one.
Other usage like "tabn {count}" can be found by using the command ":help tabn".

image for vim tab

Buffers

A buffer is something that is loaded into the memory, so it can be used in the immediate future.

The command ":edit(or :e) filename" is used to open a new file into a new buffer, and switch to this new buffer.
Image for vim's edit command

If you want add a file to the buffer list, without loading it, let it stay in the background, you can use the command ":badd(or:bad) filename".
Image for vim's badd command

There are three commands to list the open buffers:
:ls, :files, or :buffers.
Image for list buffers