Improve your vim experience: tips and tricks
I recently switched to vim7 and discovered this lovely thing called Omnicompletion.
Combined with stuff like vimtags it can deliver an experience very similar to
big IDEs, with a nice menu popping up and displaying a list of available
functions for that object.
The other big improvement is 256
colors support and a new theme taking advantage of it. It sounds like eye-candy
but it's a pure functional enhancement, making me able to read code a lot
faster than I used to be when lots of stuff looked like the same. And
smoother colors are also nicer to the eyes for long coding sessions. Tabs are
much nicer than buffers and the minibuffer plugin, and an enhanced status line
can save you quite a few keystrokes and provide some very useful information
Omnicompletion
Quoting from the docs:This could also be called "intellisense", but that is a trademark. It is a smart kind of completion. The text in front of the cursor is inspected to figure out what could be following.You activate it by pressing C-X C-O which calls whatever is defined as omnifunc to get a list of the items to display in the drop down menu. By default several languages are supported but this unfortunately doesn't include python. For that you want to download pythoncomplete which provides a function to be used as omnifunc and additional handles a mini buffer with inline documentation for the function/object currently selected. Popup's default behavior is imho quite awkward so I had to add some lines to my ~/.vimrc:
" Make omnicompletation useful " http://www.vim.org/tips/tip.php?tip_id=1386 set completeopt=longest,menuone,preview inoremapYou might also want to change the popupmenu's default colours to something nicer:pumvisible() ? "\ " : "\ u\ " inoremap pumvisible() ? "\ c-n>" : "\ c-n>\ c-r>=pumvisible() \ ? \"\\ down>\" : \"\"\ cr>" inoremap pumvisible() ? "\ c-n>" : "\ c-x>\ c-o>\ c-n>\ \ c-p>\ c-r>=pumvisible() ? \"\\ down>\" : \"\"\ cr>"
" make the popupmenu's colours less ugly (default bright pink is horrible) highlight Pmenu ctermfg=0 ctermbg=2 gui=NONE highlight PmenuSel ctermfg=0 ctermbg=7 gui=NONE highlight PmenuSbar ctermfg=7 ctermbg=0 gui=NONE highlight PmenuThumb ctermfg=0 ctermbg=7 gui=NONE
256 colorscheme
Most of the high colours colourschemes are for gvim, with very few choices for console, altho such good ones that you probably wont ever need anything else. I personally use inkpot, but desert256 and calmar's are also very good. You can find all of them in my ~.vim/colors/ directory.I've had many comments about the default 8bit colours scheme being enough but I reckon that you dont know what you're losing until you get a 256one running. It's much nicer on the eyes, and makes reading tons of code faster, identifying blocks, functions etc is way quicker.
Tabs
If you have ever edited more than a file at time you got to hate it and installed the minibuffer plugin, so you could actually see what files you had open without goin crazy. But you can do better, and start using the new tabs functionality, which creates a line at the top of your screen, similar to the status line, with a nice tab for each file open. You can easily go through them with A-PGUP/DOWN and display any sort of info you find useful just by overriding the tabline variable.
Status bar
I find useful to have my statusbar always displayed and put some extra info in it so I can tell immediately size of the file, full path, cursor position in % within the file, type and last modified date. Stick this in your vimrc:
set laststatus=2 " A status line will be used to separate windows
" 'laststatus' = 2 -> always a status line
set statusline=%<%F%h%m%r%h%w%y\ %{&ff}\ %{strftime(\"%c\",getftime( \
expand(\"%:p\")))}%=\ lin:%l\,%L\ col:%c%V\ pos:%o\ ascii:%b\ %P
tSkeleton : File Templates and Code Skeletons
For blogging with vim I came up with some kind of template, but soon find myself to face some shortcomings of that quick-and-dirty approach. tSkeleton solves them all and I'm now using templating in a lot more places: for coding it provides me with standard things like path to the interpreters and GPL licence headers; with mutt it gives me useful email templates to write to customers or things like reports.[click to enlarge]