''"[http://www.vim.org/about.php Vim] is an advanced text editor that seeks to provide the power of the de-facto UNIX editor ‘vi’, with a more complete feature set."''

−

''"[http://www.vim.org/about.php Vim] is an advanced text editor that seeks to provide the power of the de-facto UNIX editor ‘vi’, with a more complete feature set."'' Vim is not a simple text editor like nano or pico. It does require some time to learn, and a great amount of time to master.

+

Vim focuses on keyboard usage, and offers useful features such as syntax highlighting and scripting capabilities. Vim is not a simple text editor, like nano or pico. It does require some time to learn, and a great amount of time to master.

−

−

Vim is designed to make your fingers work as little as possible, and you should never have to use the mouse. This may seem odd, but once you master Vim, you will begin to understand the reasoning.

−

−

== Features ==

−

−

* Vim is very powerful for advanced editing tasks

−

* Extensible configuration options

−

* Simple, robust keybindings

−

* Syntax highlighting

== Installation ==

== Installation ==

Line 21:

Line 16:

[[pacman|Install]] the command line version with the {{Pkg|vim}} package, or you can install the GUI version (which also provides {{ic|vim}}) by installing the {{Pkg|gvim}} package.

[[pacman|Install]] the command line version with the {{Pkg|vim}} package, or you can install the GUI version (which also provides {{ic|vim}}) by installing the {{Pkg|gvim}} package.

−

{{Note|{{Pkg|vim}} is no longer compiled with X server options. For many users, this will mean that standard copy and paste functionality from the X server clipboard will fail to work. If this is a common task for you, consider installing {{Pkg|gvim}} which includes a version of Vim with this support. See {{Bug|14609}} for more information.}}

+

{{Note|The {{Pkg|vim}} package is meant to be as lightweight as possible; hence, it does not support Python, Lua, and Ruby interpreters, nor does it support X server options (this means that it will not support copy and paste from the X clipboard). If you require these options, install the {{Pkg|gvim}} package instead (it includes the {{ic|vim}} binary as well). The {{ic|herecura-stable}} unofficial repository also provides a couple different Vim / gVim variants:

−

−

{{Note|The vim package is meant to be as lightweight as possible, hence it does not support Python, Lua, and Ruby interpreters. If you require their support, choose the gvim package, which includes the vim binary. The {{ic|herecura-stable}} unofficial repository provides a couple different vim / gvim variants:

{{hc|$ pacman -Slq herecura-stable &#124; grep vim|

{{hc|$ pacman -Slq herecura-stable &#124; grep vim|

vim-cli

vim-cli

Line 35:

Line 28:

}}

}}

+

{{Note|There are some visualization problems in KDE using {{Pkg|gvim}} from official repositories. In that case you can install {{ic|vim-gvim-qt}} from {{ic|herecura-stable}} or {{AUR|vim-qt}}

+

}}

==Usage==

==Usage==

−

This is a basic overview on how to use vim. Alternately, you could use {{Ic|vimtutor}} to further familiarize yourself. Vim has four different modes:

+

This is a basic overview on how to use Vim. Alternately, running {{Ic|vimtutor}} or {{Ic|gvimtutor}} will launch vim's tutorial, which takes about 25-30 minutes.

you will see a blank document (providing that somefile.txt does not exist. If it does, you will see what is in there). You will not be able to edit right away – you are in Command Mode. In this mode you are able to issue commands to vim with the keyboard.

+

you will see a blank document (providing that somefile.txt does not exist. If it does, you will see what is in there). You will not be able to edit right away – you are in Command Mode. In this mode you are able to issue commands to Vim with the keyboard.

−

{{Note|Vim is an example of classic Unix-style ware. This means that it is not flashy, and it will not hold your hand. It does not come with built-in paperclips and games. It will allow you to get the job done however, and quickly too. Also, all commands are case sensitive. Sometimes the uppercase versions are “blunter” versions ({{keypress|s}} will replace a character, {{keypress|S}} will replace a line), other times they are completely different commands ({{keypress|j}} will move down, {{keypress|J}} will join two lines).}}

+

{{Note|Vim is an example of classic Unix-style ware. It has a steep learning curve, but once you get started, you will find that it is extremely powerful. Also, all commands are case sensitive. Sometimes the uppercase versions are “blunter” versions ({{keypress|s}} will replace a character, {{keypress|S}} will replace a line), other times they are completely different commands ({{keypress|j}} will move down, {{keypress|J}} will join two lines).}}

You insert text (stick it before the cursor) with the {{keypress|i}} command. {{keypress|I}} (uppercase '''i''') inserts text at the beginning of the line. You append text (place text after the cursor, what most people expect) with {{keypress|a}}. Typing {{keypress|A}} will place the cursor at the end of the line.

You insert text (stick it before the cursor) with the {{keypress|i}} command. {{keypress|I}} (uppercase '''i''') inserts text at the beginning of the line. You append text (place text after the cursor, what most people expect) with {{keypress|a}}. Typing {{keypress|A}} will place the cursor at the end of the line.

Line 58:

Line 55:

Return to command mode at any time by pressing {{keypress|Esc}}.

Return to command mode at any time by pressing {{keypress|Esc}}.

−

===Moving Around===

+

===Moving around===

−

In vim, you can move the cursor with the arrow keys, but this isn't the '''vim way'''. You’d have to move your right hand all the way from the standard typing position all the way to the arrow keys, and then back. Not fun.

+

In Vim, you can move the cursor with the arrow keys, but this isn't the '''Vim way'''. You’d have to move your right hand all the way from the standard typing position all the way to the arrow keys, and then back. Not fun.

−

In vim you can move down by pressing {{keypress|j}}. You can remember this because the “j” hangs down. You move the cursor back up by pressing {{keypress|k}}. Left is {{keypress|h}} (it's left of the “j”), and right is {{keypress|l}} (lowercase '''L''').

+

In Vim you can move down by pressing {{keypress|j}}. You can remember this because the “j” hangs down. You move the cursor back up by pressing {{keypress|k}}. Left is {{keypress|h}} (it's left of the “j”), and right is {{keypress|l}} (lowercase '''L''').

{{keypress|^}} will put the cursor at the beginning of the line, and {{keypress|$}} will place it at the end.

{{keypress|^}} will put the cursor at the beginning of the line, and {{keypress|$}} will place it at the end.

Line 68:

Line 65:

{{Note|{{keypress|^}} and {{keypress|$}} are commonly used in regular expressions to match the beginning and ending of the line. Regular expressions are very powerful and are commonly used in *nix environment, so maybe it is a little bit tricky now, but later you will notice “the idea” behind the use of most of these key mappings.}}

{{Note|{{keypress|^}} and {{keypress|$}} are commonly used in regular expressions to match the beginning and ending of the line. Regular expressions are very powerful and are commonly used in *nix environment, so maybe it is a little bit tricky now, but later you will notice “the idea” behind the use of most of these key mappings.}}

−

To advance a word, press the {{keypress|w}} key. {{keypress|W}} will include more characters in what it thinks is a word (e.g. underscores and dashes as a part of a word). To go back a word, {{keypress|b}} is used. Once again, {{keypress|B}} will include more characters in what vim considers a word. To advance to the end of a word, use {{keypress|e}}, {{keypress|E}} includes more characters.

+

To advance a word, press the {{keypress|w}} key. {{keypress|W}} will include more characters in what it thinks is a word (e.g. underscores and dashes as a part of a word). To go back a word, {{keypress|b}} is used. Once again, {{keypress|B}} will include more characters in what Vim considers a word. To advance to the end of a word, use {{keypress|e}}, {{keypress|E}} includes more characters.

To advance to the beginning of a sentence, {{keypress|(}} will get the job done. {{keypress|)}} will do the opposite, moving to the end of a sentence. For an even bigger jump, {{keypress|{}} will move the the beginning a whole paragraph. {{keypress|<nowiki>}</nowiki>}} will advance to the end of a whole paragraph.

To advance to the beginning of a sentence, {{keypress|(}} will get the job done. {{keypress|)}} will do the opposite, moving to the end of a sentence. For an even bigger jump, {{keypress|{}} will move the the beginning a whole paragraph. {{keypress|<nowiki>}</nowiki>}} will advance to the end of a whole paragraph.

Line 82:

Line 79:

The {{keypress|x}} command will delete the character under the cursor. {{keypress|X}} will delete the character before the cursor. This is where those number functions get fun. {{keypress|6x}} will delete 6 characters. Pressing {{keypress|.}} (dot) will repeat the previous command. So, lets say you have the word "foobar" in a few places, but after thinking about it, you’d like to see just “foo”. Move the cursor under the "b", hit {{keypress|3x}}, move to the next "foobar" and hit {{keypress|.}} (dot).

The {{keypress|x}} command will delete the character under the cursor. {{keypress|X}} will delete the character before the cursor. This is where those number functions get fun. {{keypress|6x}} will delete 6 characters. Pressing {{keypress|.}} (dot) will repeat the previous command. So, lets say you have the word "foobar" in a few places, but after thinking about it, you’d like to see just “foo”. Move the cursor under the "b", hit {{keypress|3x}}, move to the next "foobar" and hit {{keypress|.}} (dot).

−

The {{keypress|d}} will tell vim that you want to delete something. After pressing {{keypress|d}}, you need to tell vim what to delete. Here you can use the movement commands. {{keypress|dW}} will delete up to the next word. {{keypress|d^}} will delete up unto the beginning of the line. Prefacing the delete command with a number works well too: {{keypress|3dW}} will delete the next three words. {{keypress|D}} (uppercase) is a shortcut to delete until the end of the line (basically {{keypress|d$}}). Pressing {{keypress|dd}} will delete the whole line.

+

The {{keypress|d}} will tell Vim that you want to delete something. After pressing {{keypress|d}}, you need to tell Vim what to delete. Here you can use the movement commands. {{keypress|dW}} will delete up to the next word. {{keypress|d^}} will delete up unto the beginning of the line. Prefacing the delete command with a number works well too: {{keypress|3dW}} will delete the next three words. {{keypress|D}} (uppercase) is a shortcut to delete until the end of the line (basically {{keypress|d$}}). Pressing {{keypress|dd}} will delete the whole line.

To delete then replace the current word, place the cursor on the word and execute the command {{keypress|cw}}. This will delete the word and change to insert mode. To replace only a single letter use {{keypress|r}}.

To delete then replace the current word, place the cursor on the word and execute the command {{keypress|cw}}. This will delete the word and change to insert mode. To replace only a single letter use {{keypress|r}}.

−

===Undo and Redo===

+

===Undo and redo===

−

vim has a built-in clipboard (also known as a buffer). Actions can be undone with {{keypress|u}} and redone with {{keypress|Ctrl+r}}.

+

Vim has a built-in clipboard (also known as a buffer). Actions can be undone with {{keypress|u}} and redone with {{keypress|Ctrl+r}}.

−

===Visual Mode===

+

===Visual mode===

Pressing {{keypress|v}} will put you in visual mode . Here you can move around to select text, when you’re done, you press {{keypress|y}} to yank the text into the buffer (copy), or you may use {{keypress|c}} to cut. {{keypress|p}} pastes after the cursor, {{keypress|P}} pastes before. {{keypress|V}}, Visual Line mode, is the same for entire lines. {{keypress|Ctrl+v}} is for blocks of text.

Pressing {{keypress|v}} will put you in visual mode . Here you can move around to select text, when you’re done, you press {{keypress|y}} to yank the text into the buffer (copy), or you may use {{keypress|c}} to cut. {{keypress|p}} pastes after the cursor, {{keypress|P}} pastes before. {{keypress|V}}, Visual Line mode, is the same for entire lines. {{keypress|Ctrl+v}} is for blocks of text.

Line 96:

Line 93:

{{Note|Whenever you delete something, that something is placed inside a buffer and is available for pasting.}}

{{Note|Whenever you delete something, that something is placed inside a buffer and is available for pasting.}}

−

===Search and Replace===

+

===Search and replace===

−

To search for a word or character in the file, simply use {{keypress|/}} and then the characters your are searching for and press enter. To view the next match in the search press {{keypress|n}}.

+

To search for a word or character in the file, simply use {{keypress|/}} and then the characters your are searching for and press enter. To view the next match in the search press {{keypress|n}}, press {{keypress|N}} for the previous match.

To search and replace use the substitute {{keypress|:s/}} command. The syntax is: {{Ic|[range]s///[arguments]}}. For example:

To search and replace use the substitute {{keypress|:s/}} command. The syntax is: {{Ic|[range]s///[arguments]}}. For example:

Line 118:

Line 115:

}}

}}

−

===Saving and Quitting===

+

===Saving and quitting===

To save and/or quit, you will need to use Ex mode. Ex mode commands are preceded by a {{keypress|:}}. To write a file use {{keypress|:w}} or if the file doesn’t have a name {{ic|''':w''' filename}}. Quitting is done with {{keypress|:q}}. If you choose not to save your changes, use {{keypress|:q!}}. To save and quit {{keypress|:x}}.

To save and/or quit, you will need to use Ex mode. Ex mode commands are preceded by a {{keypress|:}}. To write a file use {{keypress|:w}} or if the file doesn’t have a name {{ic|''':w''' filename}}. Quitting is done with {{keypress|:q}}. If you choose not to save your changes, use {{keypress|:q!}}. To save and quit {{keypress|:x}}.

−

=== Additional Commands ===

+

=== Additional commands ===

# Pressing {{keypress|s}} will erase the current letter under the cursor, and place you in insert mode. {{keypress|S}} will erase the whole line, and place you in insert mode.

# Pressing {{keypress|s}} will erase the current letter under the cursor, and place you in insert mode. {{keypress|S}} will erase the whole line, and place you in insert mode.

Line 132:

Line 129:

==Configuration==

==Configuration==

−

Vim's personal configuration file is located in the home directory: {{ic|~/.vimrc}}. Advanced users tend to keep a well-tailored {{ic|~/.vimrc}}. The global configuration file is located at {{ic|/etc/vimrc}}. The fall-back {{Ic|$VIM}} variable is defined as {{ic|/usr/share/vim/}}. For example, to create a global colorscheme the {{ic|*.vim}} colorscheme file should be stored in {{ic|/usr/share/vim/vimfiles/}}.

+

Vim's user-specific configuration file is located in the home directory: {{ic|~/.vimrc}}, and files are located inside {{ic|~/.vim/}} The global configuration file is located at {{ic|/etc/vimrc}}. Global files are located inside {{ic|/usr/share/vim/}}.

−

Currently, the vim global configuration in Arch Linux is very basic and differs from many other distributions' default vim configuration file. To get some commonly expected behaviors (like syntax highlighting, return to the line of the last edit...), consider using vim's example configuration file:

+

The Vim global configuration in Arch Linux is very basic and differs from many other distributions' default Vim configuration file. To get some commonly expected behaviors (such as syntax highlighting, returning to the last known cursor position), consider using Vim's example configuration file:

−

cp /etc/vimrc /etc/vimrc.bak

+

# mv /etc/vimrc /etc/vimrc.bak

−

cp /usr/share/vim/vim73/vimrc_example.vim /etc/vimrc

+

# cp /usr/share/vim/vim73/vimrc_example.vim /etc/vimrc

−

===Backup Files===

+

===Wrap searches===

−

Vim by default creates a backup of an edited file in the same directory as the file called {{ic|filename~}}. To prevent clutter, many users tell vim to use a backup directory:

+

With this option the ''search next'' behaviour allows to jump to the beginning of the file, when the end of file is reached. Similarly, ''search previous'' jumps to the end of the file when the start is reached.

−

−

set backupdir=~/.vim/backup,/tmp

−

−

Or, it's possible to even disable this behavior:

−

−

set nobackup

−

set nowritebackup

−

set noswapfile ! (additionally disable swap files)

−

−

===Wrap Searches===

set wrapscan

set wrapscan

−

=== Spell Checking ===

+

=== Spell checking ===

set spell

set spell

Line 165:

Line 152:

# pacman -Ss vim-spell

# pacman -Ss vim-spell

−

Language dictionaries can also be found at the [http://ftp.vim.org/vim/runtime/spell/ Vim FTP archive]. Put the downloaded dictionar(y/ies) into the {{ic|~/.vim/spell}} folder and set the dictionary by typing: {{ic|:setlocal spell spelllang<nowiki>=</nowiki>LL}}

+

Language dictionaries can also be found at the [http://ftp.vim.org/vim/runtime/spell/ Vim FTP archive]. Put the downloaded dictionar(y/ies) into the {{ic|~/.vim/spell}} folder and set the dictionary by typing: {{ic|1=:setlocal spell spelllang=LL}}

* You can enable spell checking for arbitrary file types (e.g. *.txt) by using the FileType plugin and a custom rule for file type detection. To enable spell checking for any file ending in {{ic|*.txt}}, create the file {{ic|/usr/share/vim/vimfiles/ftdetect/plaintext.vim}}, and insert the line {{ic|autocmd BufRead,BufNewFile *.txt setfiletype plaintext}} into that file. Next, insert the line {{ic|autocmd FileType plaintext setlocal spell spelllang<nowiki>=</nowiki>en_us}} into your {{ic|~/.vimrc}} or {{ic|/etc/vimrc}}, and then restart vim.}}

+

* To enable spelling in two languages (for instance English and German), add {{ic|1=set spelllang=en,de}} into your {{ic|~/.vimrc}} or {{ic|/etc/vimrc}}, and then restart Vim.

+

* You can enable spell checking for arbitrary file types (e.g. *.txt) by using the FileType plugin and a custom rule for file type detection. To enable spell checking for any file ending in {{ic|*.txt}}, create the file {{ic|/usr/share/vim/vimfiles/ftdetect/plaintext.vim}}, and insert the line {{ic|autocmd BufRead,BufNewFile *.txt setfiletype plaintext}} into that file. Next, insert the line {{ic|1=autocmd FileType plaintext setlocal spell spelllang=en_us}} into your {{ic|~/.vimrc}} or {{ic|/etc/vimrc}}, and then restart Vim.}}

* In PuTTY, the normal highlight/copy behaviour is changed because Vim enters visual mode when the mouse is used. To select text with the mouse normally, hold down the {{keypress|Shift}} key while selecting text.

+

+

===Traverse line breaks with arrow keys===

+

+

By default, pressing {{keypress|←}} at the beginning of a line, or pressing {{keypress|→}} at the end of a line, will not let the cursor traverse to the previous, or following, line.

+

+

The default behavior can be changed by adding {{ic|1=set whichwrap=b,s,<,>,[,]}} to your {{ic|~/.vimrc}} file.

=== Example ~/.vimrc ===

=== Example ~/.vimrc ===

Line 182:

Line 187:

An example [[Vim/.vimrc|Vim configuration]].

An example [[Vim/.vimrc|Vim configuration]].

−

==Merging Files (Vimdiff)==

+

==Merging files (vimdiff)==

−

Vim includes a diff editor (a program that can merge differences between two files). Begin with {{Ic|vimdiff file1 file2}}; to use:

+

Vim includes a diff editor (a program that can merge differences between two files). vimdiff will open colored windows each showing the content of the file with colored highlights of the differences, line by line. You are left with two modes: the insert one, which let you edit the file, and the screen mode, which let you move around windows and lines. Begin by running {{Ic|vimdiff file1 file2}}. Some example commands are found below:

−

]c : - next difference

+

;{{keypress|]c}} : next difference

−

[c : - previous difference

+

;{{keypress|[c}} : previous difference

−

Ctrl+w +w - switch windows

+

;{{keypress|Ctrl+w+w}} : switch windows

−

do - diff obtain

+

;{{keypress|i}} : enter Insert mode

−

dp - diff put

+

;{{keypress|Esc}} : exit Insert mode

−

zo - open folded text

+

;{{keypress|p}} : paste a line

−

zc - close folded text

+

;{{keypress|do}} : diff obtain. when cursor is on a highlighted difference and changes from other window will move into the current one

−

:diffupdate - re-scan the files for differences

+

;{{keypress|dp}} : diff put. same as diff obtain but will put the changes from current windows into the other one

Once your file has been correctly edited taking account changes in file.pacnew:

+

# mv file file.bck

+

# mv file.pacnew file

+

Check if your new file is correct, then remove your backup:

+

# rm file.bck

+

+

==Vim tips==

Specific user tricks to accomplish tasks.

Specific user tricks to accomplish tasks.

−

===Line Numbers===

+

===Line numbers===

# Show line numbers by {{Ic|:set number}}.

# Show line numbers by {{Ic|:set number}}.

# Jump to line number {{Ic|:<line number>}}.

# Jump to line number {{Ic|:<line number>}}.

−

===Substitute on Lines===

+

===Substitute on lines===

To only substitute between certain lines:

To only substitute between certain lines:

Line 226:

Line 244:

See also [http://vim.wikia.com/wiki/Restore_cursor_to_file_position_in_previous_editing_session this] tip in Vim Wiki.

See also [http://vim.wikia.com/wiki/Restore_cursor_to_file_position_in_previous_editing_session this] tip in Vim Wiki.

−

===Empty space at the bottom of gvim windows===

+

===Empty space at the bottom of gVim windows===

−

When using a [[window manager]] configured to ignore window size hints, gvim will fill the non-functional area with the GTK theme background color.

+

When using a [[window manager]] configured to ignore window size hints, gVim will fill the non-functional area with the GTK theme background color.

−

A solution is to disable the menubar in {{ic|.vimrc}}, this will make the gvim window behave as it should, filling up the entire area:

+

The solution is to adjust how much space gVim reserves at the bottom of the window. Take note that if you set it to zero, you won't be able to see the bottom horizontal scrollbar, if you have one. Put the following line in {{ic|~/.vimrc}}:

−

set go-=m "remove menubar

+

set guiheadroom=0

−

Another solution is to make a more pleasing background color: just put the following lines in {{ic|~/.gtkrc-2.0}}:

Revision as of 13:37, 14 June 2013

zh-CN:Vimzh-TW:Vim"Vim is an advanced text editor that seeks to provide the power of the de-facto UNIX editor ‘vi’, with a more complete feature set."

Vim focuses on keyboard usage, and offers useful features such as syntax highlighting and scripting capabilities. Vim is not a simple text editor, like nano or pico. It does require some time to learn, and a great amount of time to master.

Installation

Install the command line version with the vim package, or you can install the GUI version (which also provides vim) by installing the gvim package.

Note: The vim package is meant to be as lightweight as possible; hence, it does not support Python, Lua, and Ruby interpreters, nor does it support X server options (this means that it will not support copy and paste from the X clipboard). If you require these options, install the gvim package instead (it includes the vim binary as well). The herecura-stable unofficial repository also provides a couple different Vim / gVim variants:

Basic editing

If you start Vim with:

$ vim somefile.txt

you will see a blank document (providing that somefile.txt does not exist. If it does, you will see what is in there). You will not be able to edit right away – you are in Command Mode. In this mode you are able to issue commands to Vim with the keyboard.

Note: Vim is an example of classic Unix-style ware. It has a steep learning curve, but once you get started, you will find that it is extremely powerful. Also, all commands are case sensitive. Sometimes the uppercase versions are “blunter” versions (Template:Keypress will replace a character, Template:Keypress will replace a line), other times they are completely different commands (Template:Keypress will move down, Template:Keypress will join two lines).

Moving around

In Vim, you can move the cursor with the arrow keys, but this isn't the Vim way. You’d have to move your right hand all the way from the standard typing position all the way to the arrow keys, and then back. Not fun.

Note: Template:Keypress and Template:Keypress are commonly used in regular expressions to match the beginning and ending of the line. Regular expressions are very powerful and are commonly used in *nix environment, so maybe it is a little bit tricky now, but later you will notice “the idea” behind the use of most of these key mappings.

Repeating commands

If a command is prefixed by a number, then that command will be executed that number of times over (there are exceptions, but they still make sense, like the Template:Keypress command). For example, pressing Template:Keypress then “Help! ” then Template:Keypress will print “Help! Help! Help!“. Pressing Template:Keypress will advance you two paragraphs. This comes in handy with the next few commands…

Deleting

The Template:Keypress command will delete the character under the cursor. Template:Keypress will delete the character before the cursor. This is where those number functions get fun. Template:Keypress will delete 6 characters. Pressing Template:Keypress (dot) will repeat the previous command. So, lets say you have the word "foobar" in a few places, but after thinking about it, you’d like to see just “foo”. Move the cursor under the "b", hit Template:Keypress, move to the next "foobar" and hit Template:Keypress (dot).

To delete then replace the current word, place the cursor on the word and execute the command Template:Keypress. This will delete the word and change to insert mode. To replace only a single letter use Template:Keypress.

Configuration

Vim's user-specific configuration file is located in the home directory: ~/.vimrc, and files are located inside ~/.vim/ The global configuration file is located at /etc/vimrc. Global files are located inside /usr/share/vim/.

The Vim global configuration in Arch Linux is very basic and differs from many other distributions' default Vim configuration file. To get some commonly expected behaviors (such as syntax highlighting, returning to the last known cursor position), consider using Vim's example configuration file:

Wrap searches

With this option the search next behaviour allows to jump to the beginning of the file, when the end of file is reached. Similarly, search previous jumps to the end of the file when the start is reached.

set wrapscan

Spell checking

set spell

With this setting, Vim will highlight incorrectly spelled words. Place the cursor on a misspelled word and enter Template:Keypress to view spelling suggestions.

Only English language dictionaries are installed by default, more can be found in the official repositories. To get the list of available languages type:

# pacman -Ss vim-spell

Language dictionaries can also be found at the Vim FTP archive. Put the downloaded dictionar(y/ies) into the ~/.vim/spell folder and set the dictionary by typing: :setlocal spell spelllang=LL

To enable spelling in two languages (for instance English and German), add set spelllang=en,de into your ~/.vimrc or /etc/vimrc, and then restart Vim.

You can enable spell checking for arbitrary file types (e.g. *.txt) by using the FileType plugin and a custom rule for file type detection. To enable spell checking for any file ending in *.txt, create the file /usr/share/vim/vimfiles/ftdetect/plaintext.vim, and insert the line autocmd BufRead,BufNewFile *.txt setfiletype plaintext into that file. Next, insert the line autocmd FileType plaintext setlocal spell spelllang=en_us into your ~/.vimrc or /etc/vimrc, and then restart Vim.

Syntax highlighting

Using the mouse

Vim has the ability to make use of the mouse, but requires xterm's mouse reporting feature.

See the example .vimrc below to enable the mouse.

Use xterm. In your console: export TERM=xterm-256color or export TERM=xterm

Notes:

This even works in PuTTY over SSH.

In PuTTY, the normal highlight/copy behaviour is changed because Vim enters visual mode when the mouse is used. To select text with the mouse normally, hold down the Template:Keypress key while selecting text.

Traverse line breaks with arrow keys

By default, pressing Template:Keypress at the beginning of a line, or pressing Template:Keypress at the end of a line, will not let the cursor traverse to the previous, or following, line.

The default behavior can be changed by adding set whichwrap=b,s,<,>,[,] to your ~/.vimrc file.

Example ~/.vimrc

Merging files (vimdiff)

Vim includes a diff editor (a program that can merge differences between two files). vimdiff will open colored windows each showing the content of the file with colored highlights of the differences, line by line. You are left with two modes: the insert one, which let you edit the file, and the screen mode, which let you move around windows and lines. Begin by running vimdiff file1 file2. Some example commands are found below:

Empty space at the bottom of gVim windows

When using a window manager configured to ignore window size hints, gVim will fill the non-functional area with the GTK theme background color.

The solution is to adjust how much space gVim reserves at the bottom of the window. Take note that if you set it to zero, you won't be able to see the bottom horizontal scrollbar, if you have one. Put the following line in ~/.vimrc: