KoblentsBlog Photography
Contact About
Helpful .vimrc Additions
Like all of you, I love vim, but occasionally want more out of it, or for it not to do something. Sometimes these are features that exist on one linux machine I use and I immediately know I must have it on mine. Sometimes something just gets too annoying. Here are useful things I've found:
That you want some sort of syntax highlighting and auto-indenting is almost a given. You may want to do more, such as auto-expanding tabs, setting tab width, changing syntax highlighting, changing tabbing behavior, and so on. I keep it simple:
syntax on
set cindent
I like to see code below the line at which my cursor is currently pointing. Sometimes the cursor is at the bottom of the screen, though, and by default, you don't see the next lines. Similarly, if the cursor is at the top of the screen, you don't see the previous lines. Here's a nifty way to make sure the cursor is never at the top or bottom unless it's the beginning or the end of the file:
set scrolloff=20     " experiment with this value till it's to your liking
How many times have you typed :W or :Q or :Wq or :WQ? Your finger is already pressing shift, so not lifting the shift button quickly enough happens often.
command -bang W w<bang>
command -bang Q q<bang>
command -bang WQ wq<bang>
command -bang Wq wq<bang>
You edit a file, close it, open it back up... wouldn't it be nice if the cursor was where you left it? You can change parameters here to your liking.
" Tell vim to remember certain things when we exit
"  '10  :  marks will be remembered for up to 10 previously edited files
"  "100 :  will save up to 100 lines for each register
"  :20  :  up to 20 lines of command-line history will be remembered
"  %    :  saves and restores the buffer list
"  n... :  where to save the viminfo files
set viminfo='10,\"100,:20,%,n~/.viminfo

function! ResCur()
        if line("'\"") <= line("$")
        normal! g`"
        return 1

augroup resCur
        autocmd BufWinEnter * call ResCur()
augroup END
Ches Koblents
July 30, 2012
« Newer Older »
© Copyright Koblents.com, 2012-2017