The vimrc File
The Heart of Your Vim Setup
Your vimrc file is an incredibly powerful, incredibly useful thing. Anything you can do in command-line mode you can do in your vimrc file. This makes it possible to make settings (e.g. :set textwidth=80) in the command-line mode and then make them permanent in your vimrc file by just doing the exact same thing but in a file instead of in the running Vim session.
Where it is
Depending on what operating system you’re running on the vimrc file will be in a slightly different place. However, no matter where it actually is you can reference it from within Vim using the $MYVIMRC variable.
On Unix (Linux, OS X, whatever…)
On these operating systems, the vimrc file defaults to being in your home directory at ~/.vimrc. If it’s not there then just create it by editing it and saving it.
On all of the MS Windows variants you’ll also find this in your HOME Directory but most people don’t know where that is ;). I’m not going to try and tell you where it is, specifically and leave that up to Wikipedia’s Home Directory Page. In general however it is one directory up from the directory that contains your “Documents” (e.g. “My Documents” in Windows XP). The major difference is that it’s named slightly differently than it is in Unix: it’s named _vimrc.
What’s it for?
Everything. Ok, that’s not strictly true but at this stage in the game it’s more than sufficient to look at it that way. In practice you’ll find that plugins and many other types of file type specific configuration will make use of Vim’s extensive capabilities in its runtime structure, outside of the vimrc file but that sort of thing comes… later.
Generally you should think of your vimrc file as holding your own personal option settings, mappings, functions, commands and whatever else you need to customize Vim for your personal use.
Specific Examples
Here we’ll get more specific and actually look at some real contents of a vimrc file.
Lukas’ Weblog » Blog Archive » meisterluk’s advent calendar: Books, References …:
December 25th, 2009 at 6:17 pm
[...] Wyatt’s Blog: A great Vim-Lover. Great Tutorial Videos, vimrc and his C++ [...]
Rick Sinclair:
December 7th, 2010 at 9:15 pm
Derek,
I’m trying to use your vimrc file. Should I be concerned as to whether I have the required plugins? In other words, I am wondering if your vimrc file is trying to use plugins that I simply have not dropped into the /.vim/plugin folder.
Right now, it appears I do not even have a plugin folder in my home directory. I have only just installed the 7.3 version of vim from vim.org (as my ubuntu repository only had 7.2).
Finally, what is the difference between gVim (graphical Vim) and Vim – should I be running gvim or vim? (Sorry if it seems I am completely clueless.)
Derek Wyatt:
December 8th, 2010 at 3:26 am
The plugins are basically optional. I wouldn’t be too concerned about it.
As for the difference between Vim and gVim, the basic is pretty simple :) Vim runs inside the terminal, is generally limited in terms of its potential colours, and is also limited in terms of its physical dimensions of the terminal, as well as being limited by the terminal’s ability to display “special” characters. GVim is sexier in terms of its colours, dimensions, etc… all that good stuff. I rarely use the terminal version unless I’m running it remotely in a terminal window on another machine.
Rick Sinclair:
December 8th, 2010 at 8:08 am
Launching the GVim brought up only a white screen. Lauching gvim within the terminal showed these errors:
Error detected while processing /home/ricalsin/.vimrc:
line 460:
E185: Cannot find color scheme xoria256
line 931:
E185: Cannot find color scheme xoria256
I’m thinking it’s due to not having the plugins, so I’m checking that out now…
Rick Sinclair:
December 8th, 2010 at 8:12 am
..obviously, I shouldn’t be pasting the text twice… (-: Sorry. Still trying to find the cause of the one error.
Derek Wyatt:
December 8th, 2010 at 8:25 am
That’s just the colour scheme that you don’t have. Either download it from http://www.vim.org and put it in ~/.vim/colors or just comment out that line in the vimrc
Rick Sinclair:
December 8th, 2010 at 10:28 am
For me, it proved a little more difficult due to some settings for the 256 color and also calling that xoria256.vim from within both the vim and gvim. This link had nice instructions: http://www.vim.org/scripts/script.php?script_id=2140
Read you vimrc file. Very nice of you to share that hard-earned work and discovery. Thanks, Derek!
Daniel:
March 15th, 2011 at 1:31 pm
Hi derek, I’m having problems with my vimrc, I’m using gvim ver 7.6, in Ubuntu Maverick latest Ver. I’ve created the .vimrc from inside gvim and saved it in my home and changed the colorscheme plus the font to a custome “Monospace:12″ but then when I launch gvim it shows errors then I press enter and gvim opens anyway, but the font is way letterspaced the font is wrong and the theme is not showing, I have placed all the colorschemes in /usr/share/vim/vim72/colors cause I wasn’t sure If I should created a colors folder in my home vim folder.
any direccions would be appreciated, thanks.
Error:
An error has been detected when processing /home/danilux/.vimrc:
line 3
E185: can’t find colorscheme anotherDark
Derek Wyatt:
March 15th, 2011 at 5:08 pm
A few things :)
1) You can’t be using 7.6 – it looks like you’re using 7.2, but if you’re not then putting things in /usr/share/vim/vim72 won’t help you because that’s clearly for version 7.2. Typing vim –version will show you what directory that Vim is interested in.
2) the absolute simplest way to get a colour scheme working in your personal environment is to stick it in ~/.vim/colors
3) Your font probably isn’t right. The simplest thing to do is type ‘:set guifont=*’ and then use the font selector that pops up to choose your font. Once it looks the way you want, and you’ve closed the dialog, then type ‘:set guifont’. You’ll see how Vim has interpreted this and it will show you what you should put in your vimrc.
Daniel:
March 15th, 2011 at 8:07 pm
1)Yep, your absolutely right, 7.2 here. The vim -version did not show me any directory what so ever though.
2) That worked, I create the .vim and colors folder and now it’s working, I think it had something to do with the :set runtimepath? that did not have the path to where I was placing the colors before, but it did was the ~/ path.
One last question, for the plugins, like nerdTree, sparkup and others, should I also put them now inside the new ~/.vim/ folder and create inside a plugin folder like I did with the colors or those should be in another place like etc or usr for vim.
Derek Wyatt:
March 16th, 2011 at 2:55 am
Everything that you customize should go in ~/.vim. Failing to do that will make sure you have a pain in the ass upgrading Vim.
I also recommend that you use ‘pathogen’. Read up on it here: http://tammersaleh.com/posts/the-modern-vim-config-with-pathogen
Daniel:
March 16th, 2011 at 10:58 pm
That pathogen sure makes it a lot easier. Thanks for your time man.
shrsv:
May 25th, 2011 at 2:12 am
I’ve created a vimrc file generator.
Try it online here: http://vimrcgen.sourceforge.net/
In case you want an offline version: http://sourceforge.net/p/vimrcgen/home/
Marcin:
August 27th, 2011 at 4:21 pm
I got inspired :) and published my own vimrc file here:
http://atp-vim.sf.net/help.shtml
fergal:
September 1st, 2011 at 10:39 am
when i first started using vim on windows, it took me a while to find where i should be saving my .vimrc, until i realised i could just do
:echo $HOME
to display my home directory, or
:e $HOME/.vimrc
to edit my vimrc directly. works on unix too!
Phiri:
November 7th, 2011 at 2:27 am
Great introduction to ~/.vimrc –I found it useful. Thank you for taking the time to write this. It would have been quite useful if you had included reference to place where those getting started could obtain more information.
Getting VIM setup for Ruby on Rails — Shaun Ambrose:
March 31st, 2012 at 8:58 am
[...] Information on the vimrc file: http://www.derekwyatt.org/vim/the-vimrc-file/ [...]