Vim is an editor built on vi, at the moment it's my favorite shell editor. It is very tweakable and there are many plugins to autocomplete words and functions. In this post I will discuss some features of vim and how they work. Vim is more than just a basic editor.
You can easily navigate with vim.
- Go to the start of a page double tap
- Go to the end of your page
- Jump to the text on the beginning of this line
^ or home-button
- Jump to the end
$ or end-button
- Jump to your last edit
Copy,Cut and Paste
Cut and paste:
- Position the cursor where you want to begin cutting.
- Press v (or upper case V if you want to cut whole lines).
- Move the cursor to the end of what you want to cut.
- Press d.
- Move to where you would like to paste.
- Press p to paste after the cursor, or P to paste before.
To copy you use the same steps, but instead of pressing d you use y.
To cut a line you can just double tap d it. Tap p to paste.
Something handy is that you can also enable your mouse in vim (even in xterm):
Find and replace
You can do find and replace. A vim substitution regex looks like this:
ranges this is the first character after the ":" :
- number an absolute line number
the last line in the file
the whole file. The same as 1,$
position of mark "t"
the next line where text "pattern" matches.
the previous line where text "pattern" matches
the next line where the previously used search pattern matches
the previous line where the previously used search pattern matches
the next line where the previously used substitute pattern matches
the current line
- c confirm each substitution
- g replace all occurrences
- i ignore case
- I do not ignore case
So if we have a text:
Johnny was a little boy but Johnny is no more, for what Johnny thought was H2O was H2SO4!
So if we want to replace "Johnny" with "Bobby" we need to type:
This means, replace, in the whole file, all character sequences that match "Johnny" with "Bobby" ignoring capitalization. If these words were in the text they would match:
johnny Johnny Johnnytonny
You may also write the previous expression like this:
Here we replace "/" to ":". If we want only words to match, so no character sequences (e.g. Johnny but not Johnnytonny). We need to use the word boundary:
If you want to learn about patterns and regexes visit vimregex.com.
Layout and highlighting
It might be that you want some syntax-highlighting or you want to have more space from the sides, or you don't want text wrapping,.. . This can all be done by issuing these commands:
- If you want syntax-highlighting:
- The colors are rather dark by default, so change the scheme by issuing:
- Do not wrap code:
- Use auto-indentation:
- Show partial commands
- Set the textwidth to 80
- Show matching brackets
- If you want line-numbers:
You can use abbreviations to automatically insert another word or sentence instead of the provided word:
:ab rtfm read the fine manual
Whenever you type 'rtfm' followed by punctuation such as a space or comma, the 'rtfm' will be expanded to 'read the fine manual'. This also happens if you type 'rtfm' then press Esc or Enter.
To remove one abbreviation:
To clear all abbreviations:
You can use Ctrl+k after typing a few characters to complete a word. First of all you will need to add a directory. On Debian machines you can find a dictionary here:
To add the american-english dictionary to vim:
Some of the functions you might want to have on by default, instead entering them every time you start a new session. The easiest way to do this is to define a file called
in your homefolder. All of the commands like:
set background=dark syntax on
can be defined in here (every one on a new line). They will automatically be enabled when you start vim.
There are many vim plugins available to provide auto complete. One such plugin is called Omni complete. To enable Omni complete issue:
filetype plugin on set ofu=syntaxcomplete#Complete ab rtfm read the fine manual
You will also needing special files to load auto completion for your specific language. These can be downloaded from vim.org. You will need to place them in your home folder under:
Or for global enable on Debian:
To enable auto complete for python:
See for specific languages:
There are many things you can do with vim, I barely scratched the surface here. If you want more info or deeper understanding visit: