Difference between revisions of "Editor: vim"

From Dreamwidth Notes
Jump to: navigation, search
(Setting up Vim for coding)
(oops! dropped important detail -- vim starts in normal mode! <_<;)
 
(4 intermediate revisions by 4 users not shown)
Line 1: Line 1:
vim is a console-based cross-platform editor, mostly used by Lunix and other Unix users. It can be a very powerful, but also difficult to learn tool.
+
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.
  
vim has two modes, an insertion mode that you can access by using the [Ins] key, and the command mode it starts with, which you can get back to with [Esc]
+
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==
 +
 
 +
* The [http://vimdoc.sourceforge.net/htmldoc/usr_toc.html vim user guide] is included with vim, but it can be easier to browse online.
 +
* The [http://vimdoc.sourceforge.net/htmldoc/help.html#reference_toc vim reference guide] explains how everything in vim works, in gory detail.
  
 
==Useful commands==
 
==Useful commands==
Line 9: Line 16:
 
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"
 
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"
  
==Setting up Vim for coding==
+
==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 [http://www.vim.org/ Vim] site for information on those.
 +
 
 +
===Setting up Vim for coding===
  
 
Add the following to your .vimrc file:
 
Add the following to your .vimrc file:
Line 28: Line 41:
 
  filetype indent on
 
  filetype indent on
  
There are many ways to configure Vim to your liking, included plugins. Go to the [http://www.vim.org/ Vim] site for information on those. There is also a graphical version called GVim, with clients for Linux, Windows, and the Mac to name a few.
+
===Syntax highlighting===
 +
 
 +
The commands <tt>set bg=dark</tt> and <tt>set bg=light</tt> 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 <tt>:set bg=dark</tt>).
 +
 
 +
If the syntax highlighting vim has chosen looks bizarre, you can see what filetype vim has automatically guessed with the command <tt>:set syntax</tt>. If it's not correct, you can fix the highlighting by setting the correct value yourself -- eg, <tt>:set syntax=perl</tt>, <tt>:set syntax=html</tt>, etc.
 +
 
 +
===Other useful configuration and commands===
 +
 
 +
<tt>set number</tt> / <tt>set nonumber</tt>: display or hide the line numbers on the left-hand side of the screen.
 +
 
 +
==Other references==
 +
 
 +
* http://vimregex.com/ -- vim's regular expression syntax
 +
* http://vimdoc.sourceforge.net/htmldoc/pi_netrw.html
  
 
[[Category: Editors]]
 
[[Category: Editors]]

Latest revision as of 03:22, 17 April 2013

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