KoblentsBlog Photography
Contact About
Ches
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:
12
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:
1
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.
1234
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.
12345678910111213141516171819
" 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
        endif
endfunction

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