In my earlier post on setting up Vim on Windows I already talked about a few vimrc changes to make vim behave on windows and look a bit better.
I learned that checking out other people’s vimrc files is a great way to learn how you can configure vim to become the kick-ass text editor you always wanted. In this post I’m going to run over the settings I have in my _vimrc file to make vim work better for me. Feel free to copy bits you find useful.
If you don’t know what that vimrc file is, or how to edit it, check out my previous post on how to set things up.
I tend to document my vimrc changes with some comments. That way I still know what I was trying to do months later and or what lines can be removed when a wicked plugin makes them obsolete. Most of it is self-explanatory, so I’ll just paste them right here.
First some system settings.
" Activate all the handy Windows key-bindings we're used to.
" Have gvim behave properly on Windows.
" Use unicode/utf-8 encoding by default for keyboard, display and files.
" Set a more convenient leader key on an AZERTY layout than the default backslash
let mapleader = ","
Now let’s make things prettier.
First, we need to set a nicer fixed-width font, Consolas in this case. Then I hide the toolbar which I never use. Then, of course, a nice theme.
" Set a nicer font.
" Hide the toolbar.
" Set theme.
Then a number of visual things to make programming, editing and searching text easier.
" Display line and column number in bottom ruler.
" Display the line numbers.
" Turn sounds off.
" Shows a horizontal highlight on the line with the cursor.
" Activate highlighting search pattern matches & incremental search.
" Incremental search means your cursor will jump to the first match as you
" Allow using to kill the current search highlighting.
" Activate case-insensitive & smart case search (if a capital letter is used
" in your search query, Vim will search case-sensitive).
" Set wildchar visual completion awesomeness.
" This is enhanced command line completion and it rocks.
" Turning on line wrapping and line-break for easy text-file editing.
" Line-break wraps full words at the end of a sentence for readability.
Programming settings. Who would have thought!
Tweak tab settings according to your religious preference of course. I can’t say I have used the folding a lot, but these settings come from another .vimrc somewhere, and they seem sensible.
" Activate syntax highlighting.
" Set tabs to 4 characters and expand to spaces, activate smart indentation.
" See tabstop help for more info.
" Setting tabstop & softtabstop to the same value to avoid messy layout with mixed tabs & spaces.
" Enabled folding on indent level. That way it works on any code & html, xml
" Setting foldlevelstart ensures that for newly opened files folds are open
" unless they are 10 levels deep.
set foldnestmax=10 " no more than 10 fold levels please
At the end of my vimrc I add my custom tweaks. They might not be useful for everybody, but they work well for me.
First, some syntax highlighting for file types vim doesn’t know about by default for .NET development.
" Set syntax highlighting for some .NET file types as XML files, cause that's what they are really.
autocmd BufNewFile,BufReadPost *.config set filetype=xml
autocmd BufNewFile,BufReadPost *.csproj set filetype=xml
autocmd BufNewFile,BufReadPost *.sln set filetype=xml
Then, some key mappings to access plugin features or plain vim commands quicker.
" Add a mapping to open a new tab with CTRL-T.
" F11 toggles menu visibility
nnoremap :if &go=~#'m'set go-=melseset go+=mendif
" cd sets path to the path of the file in the current buffer.
nnoremap cd :cd %:p:h
" Open the NERDTree on the path of the file in the current buffer.
nnoremap t :NERDTree %:p:h
That’s about it. I hope this helps to get your own .vimrc set up the way you want it to. I’m not a vim expert so there are probably better ways to do some of these things. I you know how, feel free to let me know in the comments. I’m eager to learn some nice vim hacks.
As I said before, don’t just copy paste stuff in your vimrc you don’t understand. Take a look at the vim help first. Also, check out other people’s vimrc and see how they do things. There are plenty of good blog posts around on the subject and a github search turns up some good stuff too.
[ Interested in learning more about Vim? Check out the concise Mastering Vim Quickly ebook to get productive fast in Vim. ]