From charlesreid1

Vim is a very handy, full-featured, lightweight text editor available on all Unix systems. Vim and Emacs are two of the most common text editors available on Unix systems.

See: Vim wikipedia article

Vim/Common Actions





You can find plenty of documentation available for Vim here:

You can also type :help from Vim, which will open Vim help, and you can navigate from there.

This documentation is also available online here:



The .vimrc file initializes your Vim environment whenever you start up Vim. This is where you specify, e.g., default color schemes, turn on autoindent, etc.

Handy link - with this capital O + escapekeys fiasco:


Searching in Vim utilizes regular expressions.


To search for an expression, type:


Find and Replace

To find and replace an expression, type:


where the g means "global", i.e. replace all instances of "peanutbutter" with "jelly" (instead of just the first instance).

Using Regular Expressions

You can also utilize regular expressions in either finding or finding and replacing. For example, you can search for a 2-digit number by using:




Vim has a really handy feature that allows you to divide the screen of the text editor into multiple sections, called windows.

:sp - split the current window into two parts, horizontally - "top" and "bottom"

:vsp - split the current window into two parts, vertically - "left" and "right"

To open multiple files and split them into their own windows, use the -o and -O command-line options.

The following will open these 3 files split horizontally:

$ vim -o file1 file2 file3

and this will open the three files split vertically:

$ vim -O file1 file2 file3


Like windows, tabs provide a way to handle several files at once. However, windows allow you to open and look at multiple files at once. Tabs, on the other hand, like browser tabs, allow you to look at one file at a time but still have other files open, for easy switching back and forth between open files.

Tab commands include:

:tabnew - creates a new tab and switches to it

:tabnext - go to the next tab

:tabn - ditto

:tabprevious - go to the previous tab

:tabp - ditto

:tabfirst - switch to first tab (good if you have lots of tabs open)

:tabfir - ditto

:tablast - switch to last tab

:tabf something* - find tabs with open files whose names match "something*"

:tabs - list all open tabs and what files they are open to

Interfacing with the Shell

Vim Ex Mode

This link on Stack Overflow is the source of information for this, and it has been battle-tested:

led me to learn about how to use vim from the command line - without actually opening vim. This is very handy for doing those tasks that vim is particularly good at. Especially when I know the right escape characters for some awful regular expression, and it works great in vim, but it chokes the system sed on a fish bone `` somewhere.

Search/Replace in Single File From Command Line

For a single file, can run a vim-like search:

$ ex -s +%s/foo/bar/g -cwq file.txt
$ ex -s '%s/foo/bar/g' -cwq file.txt

Search/Replace in Multiple Files From Command Line

$ ex -s +'bufdo!%s/foo/bar/g' -cxa *.*

A more complicated example:

ex -s +'bufdo!%s/\(visualization..[jc]s\)/c3\/\1/g' -cxa *.*

Search/Replace in Multiple Subdirectories

To find replace recursively:

$ ex -s +'bufdo!%s/foo/bar/g' -cxa **/*.*