Tutorial by Examples

The .vimrc file (pronounced Vim-wreck) is a Vim configuration file. It holds commands that will be executed by Vim every time it starts. By default the file is empty or non-existent; you can use it to customize your Vim environment. To find out where Vim expects the vimrc file to be stored, open V...
If you don't know which options you should use, you may be interested in the :options command. This will open a split with all Vim options listed and with their current value displayed. There are 26 sections to display all options you can try. e.g. 4 displaying text scroll number of lines t...
Whatever you do to customize Vim, it should NEVER happen outside of $HOME: on Linux, BSD and Cygwin, $HOME is usually /home/username/, on Mac OS X, $HOME is /Users/username/, on Windows, $HOME is usually C:\Users\username\. The canonical location for your vimrc and your vim directory is at ...
There are three kinds of options: boolean options, string options, number options. To check the value of an option, use :set option? to check the value of an option, use :verbose set option? to also see where it was last set. Setting boolean options set booloption " Set boo...
Don't put comments after mappings, it will break things. Use :map <F6> to see what is mapped to <F6> and in which mode. Use :verbose map <F6> to also see where it was last mapped. :map and :map! are too generic. Use :n[nore]map for normal mode mappings, :i[nore]map for insert ...
Like most scripting languages, vimscript has variables. One can define a variable with the :let command: let variable = value and delete it with :unlet: unlet variable In Vim, variables can be scoped by prepending a single letter and a colon to their name. Plugin authors use that feature to...
Don't forget the bang to allow Vim to overwrite that command next time you reload your vimrc. Custom commands must start with an uppercase character. Examples command! MyCommand call SomeFunction() command! MyOtherCommand command | Command | command See :help user-commands.
Don't forget the bang to allow Vim to overwrite that function next time you reload the script where the function is defined. Custom functions must start either with an uppercase character (global functions), or with s: (script local functions), or they must be prefixed with the name associated to...
Autocommand groups are good for organization but they can be useful for debugging too. Think of them as small namespaces that you can enable/disable at will. Example augroup MyGroup " Clear the autocmds of the current group to prevent them from piling " up each time you rel...
if v:version >= 704 " Do something if Vim is the right version. endif if has('patch666') " Do something if Vim has the right patch-level. endif if has('feature') " Do something if Vim is built with 'feature'. endif See :help has-patch and :help feature-li...
Commonly you would use :set to set options to your liking in your .vimrc. There are many options that can be changed. For example, in order to use spaces for indentation: :set expandtab :set shiftwidth=4 :set softtabstop=4
Switch syntax highlighting on, when the terminal has colors if &t_Co > 2 || has("gui_running") syntax on end Show trailing whitespace and tabs. Showing tabs can be especially useful when looking for errors in Makefiles. set list listchars=tab:\|_,trail:. highlight Specia...
Vim comes with several pre-installed color schemes. In Linux, the color schemes that come with Vim are stored in /usr/share/vim/vim74/colors/ (where 74 is your version number, sans periods); MacVim stores them in /Applications/MacVim.app/Contents/Resources/vim/runtime/colors. Changing Color Schemes...
To enable - type: :set number or :set nu. To disable - type: :set nonumber or :set nonu. To enable enumerating relative to the cursor location - type: :set relativenumber. To disable enumerating relative to the cursor location - type: :set norelativenumber. Note: To change whether the curren...
Vim plugins are addons that can be used to change or enhance functionality of vim. There is a good list of plugins at vimawesome

Page 1 of 1