Editor: vim

From Dreamwidth Notes
Jump to: navigation, search

vim is a console-based cross-platform editor. While it's mostly used by Linux and other Unix users, there are builds for Windows and almost every other operating system; it's also included on every Mac running OS X. There is also a graphical version called GVim.

It's a very powerful editor, but it also has a fairly steep learning curve.

vim is a modeful editor. It has two modes: "normal" mode and insert mode. In normal mode -- the mode that vim usually starts in -- keypresses perform actions like moving the cursor around, deleting text, and so forth. In insert mode, keypresses insert the typed characters into the document, much like most editors. You can go from normal mode to insert mode using the i key or the [Ins] key, amongst others. You get back to normal mode by pressing the [Esc] key.

Documentation

Useful commands

In command mode, the text can be searched by entering a slash and then typing the text one is looking for. If you want to see the next hit of the search, type "n".

Saving is done by entering ":w" and then hitting enter, quitting by ":q" and if you want to save and quit, the two are just concatenated to ":wq"

Configuration and Customization

There are many ways to configure Vim to your liking. On Linux/Unix/Mac OS X, vim's configuration file is called .vimrc and it lives in your home directory.

In addition to the multitude of things you can set up in your .vimrc, there are also many plugins available. Go to the Vim site for information on those.

Setting up Vim for coding

Add the following to your .vimrc file:

set tabstop=4
set shiftwidth=4
set softtabstop=4
set smarttab
set smartindent
set expandtab
set autoindent

If you want Vim to do more while you are coding:

syntax on
filetype on
filetype plugin on
filetype indent on

Syntax highlighting

The commands set bg=dark and set bg=light change vim's syntax highlighting schemes to be more useful if your terminal has a dark background or a light background, respectively. Like most commands, you can either include them in your .vimrc, or type them in normal mode preceded by a colon (eg :set bg=dark).

If the syntax highlighting vim has chosen looks bizarre, you can see what filetype vim has automatically guessed with the command :set syntax. If it's not correct, you can fix the highlighting by setting the correct value yourself -- eg, :set syntax=perl, :set syntax=html, etc.

Other useful configuration and commands

set number / set nonumber: display or hide the line numbers on the left-hand side of the screen.

Other references