Other than the default stuff of course. As you can see, my additions are quite pathetic so far (only been into vim for a few months):<p><pre><code> set expandtab
set sts=2
if v:progname =~? "gvim"
colorscheme twilight
endif</code></pre>
I just keep swap files and backup ones in my .vim/ directory<p><pre><code> set backupdir=~/.vim/backup
set backup
set directory=~/.vim/tmp
</code></pre>
This to see line numbers on the left (i find it a bit more readable instead of watching at the bottom-right)<p><pre><code> set number
</code></pre>
added a simple way to speedup my writing with (I know it's crappy but it works ...until you need to add just one bracket/quote)<p><pre><code> " autocomplete parenthesis, brackets and braces
inoremap ( ()<Left>
inoremap [ []<Left>
inoremap { {}<Left>
" autocomplete quotes
inoremap ' '<Esc>:call QuoteInsertionWrapper("'")<CR>a
inoremap " "<Esc>:call QuoteInsertionWrapper('"')<CR>a
inoremap ` `<Esc>:call QuoteInsertionWrapper('`')<CR>a
function! QuoteInsertionWrapper (quote)
let col = col('.')
if getline('.')[col-2] !~ '\k' && getline('.')[col] !~ '\k'
normal ax
exe "normal r".a:quote."h"
end
endfunction
</code></pre>
and mapped f1/f2 to switch buffer<p><pre><code> noremap <f1> :bprev!<CR>
noremap <f2> :bnext!<CR>
</code></pre>
<i>Some of this wall of text was stolen from a nice, but a bit too big, vimrc i found somewhere</i><p>If you need something specific try <a href="http://vim.wikia.com/" rel="nofollow">http://vim.wikia.com/</a>
Do this to prevent yourself from learning the arrow keys while learning:<p><pre><code> map <down> <nop>
map <left> <nop>
map <right> <nop>
map <up> <nop>
imap <down> <nop>
imap <left> <nop>
imap <right> <nop>
imap <up> <nop>
</code></pre>
(There's actually a recently reported bug that causes the up arrow to do some strange things, but you get the idea).
Most of what I use was copied from this excellent site:
<a href="http://www.vi-improved.org/vimrc.php" rel="nofollow">http://www.vi-improved.org/vimrc.php</a>
Didn't we have one of these threads a little while ago? Ah yes, here we go:<p><a href="http://news.ycombinator.com/item?id=821100" rel="nofollow">http://news.ycombinator.com/item?id=821100</a><p>Here's a repost of my comment from that thread:<p>I've been using Vim for over ten years now, across several jobs and platforms and tasks, so my .vimrc and .gvimrc have gathered quite a bit of cruft. I keep them in a git repository along with my various other generically useful config files, and just check them out on each new machine I get an account on.<p>There's too much stuff in these files to describe what everything does, but there's a lot of comments, so along with the Vim online help you should be able to figure everything out:<p>.vimrc: <a href="http://paste.ubuntu.com/270714/" rel="nofollow">http://paste.ubuntu.com/270714/</a><p>.gvimrc: <a href="http://paste.ubuntu.com/270716/" rel="nofollow">http://paste.ubuntu.com/270716/</a><p>Highlights include a single key-binding for stepping through every buffer in every tab, consistent mouse-handling between console-vim and gvim, and code to automatically make gvim inherit the GNOME default monospace font.
<p><pre><code> colors torte
syn on
set expandtab
set tabstop=4
set shiftwidth=4
set ruler
set ignorecase
set autoindent
set smartindent
set hlsearch
set incsearch
set backspace=indent,eol,start
set laststatus=2
autocmd BufEnter * :syntax sync fromstart
"set hidden
set history=1000
runtime macros/matchit.vim
set wildmenu
"set wildmode=list:longest
set wildmode=longest:full,full
set title
set scrolloff=3
autocmd BufEnter *.rb :set ts=2 sw=2
"let c_space_errors=1
</code></pre>
I'm kinda unsure what good posting this will do...
This crap has accumulated over the years, so I'm not sure if any of it is obsolete or unneeded, but here's what I found in mine:<p><pre><code> set expandtab " Convert tabs to spaces
set tabstop=4 " <TAB> four spaces
set shiftwidth=4 " Shift width four spaces (for auto indent)
set noautoindent " Turn off autoindent by default
set smartindent " Use smart indent instead
set incsearch " Use incremental searches (cool)
set backspace=2 " Set backspace mode to allow backspacing in insert mode
set ruler " Show position of cursor in status line
set showmatch " Show matching parens/braces when writing code
set wh=55 " Minimum window height
set textwidth=78 " Maximum line width when writing comments
" Speed up response to ESC key
set notimeout
set ttimeout
set timeoutlen=100
" Make completion more like bash
set wildmode=longest,list
" Cure hangs during compiles?
set swapsync=
" For fuck's sake, don't throw away the indent when i hit #
inoremap # X^H#
" Disable auto-commenting of // in C/C++
au FileType c,cpp setlocal comments-=://
" Highlight trailing whitespace
hi TrailingSpace ctermbg=1
au filetype c,cpp,python match TrailingSpace "\s\+\n"</code></pre>
Nothing.<p>I work on many different systems from time to time. I don't like to get too used to things that aren't universal. I have found out (the hard way) that relying on convenience can bite you in the ass when it's 3AM and you've been up for 67 consecutive hours and you execute some keystrokes from habit and they don't do what you expected.<p>I'll admit, I probably cripple my productivity overall for working this way, but it's what I'm used to.
<a href="http://bitbucket.org/natw/dotfiles/src/tip/.vimrc" rel="nofollow">http://bitbucket.org/natw/dotfiles/src/tip/.vimrc</a><p>some parts I haven't seen mentioned otherwise:<p><pre><code> set statusline=[TYPE=%Y]\ [ENC=%{&fenc}]\ [ASCII=\%03.3b]\ [HEX=\%02.2B]\ [POS=%04l,%04v][%p%%]
hi StatusLine term=bold,reverse cterm=bold ctermfg=7 ctermbg=0
hi StatusLineNC term=reverse cterm=bold ctermfg=8
</code></pre>
gives me a nice status bar with some good info<p><pre><code> set t_Co=256
colorscheme railscasts
</code></pre>
best color scheme I've found yet, and I don't know how I lived before 256 colors<p><pre><code> set noerrorbells
set novisualbell
set t_vb=
</code></pre>
This might be redundant, but I hate error bells SO MUCH. This might be even more important than "set nocompatible".<p><pre><code> map ^P :set paste!<CR>:set paste?<CR>
</code></pre>
in python mode at least, autoindent will usually mess up pasted text<p>Plus the usual 4 space soft tab, autoindent stuff. I also highly suggest keeping your dotfiles in some kind of version control. It is definitely fun to see them grow, and I can't imagine working on multiple systems without it.
Mainly for python scripting, but works decently for most editing I do.<p><pre><code> syntax on " syntax highlighting
set tabstop=4 " PEP-8 uses 4 spaces per indentation level
set shiftwidth=4 " shifting (PEP-8)
set expandtab " spaces instead of tabs (PEP-8, and just bettter in general)
filetype on " file type detection
filetype indent on " special indentation rules for file type
filetype plugin on " auto-completion rules for file type
set hls " highlight search terms (:noh to turn off temporarily)
set ignorecase " ignore case for searches (:set noignorecase to turn off)
set incsearch " search as you type
colorscheme darkblue " slightly nicer colour scheme
set scrolloff=15 " keep 15 lines of context on both sides of cursor when scrolling
</code></pre>
<a href="http://github.com/paulgb/settings/blob/9ebf793bcf202589c74f387eda2cd7f88385a6bf/.vimrc" rel="nofollow">http://github.com/paulgb/settings/blob/9ebf793bcf202589c74f3...</a>
Some I like:<p><pre><code> " Keep cycled-away buffers open (preserving undo,
" allowing buffer switch without write)
set hidden
" Facilities for handling pasting into vim, preserving
" indentation of the pasted text.
" This will make <F4> start paste mode and <F5> stop paste mode.
" Note that typing <F5> in paste mode inserts <F5>, since in paste
" mode everything is inserted literally, except the 'pastetoggle' key
" sequence.
map <F4> :set paste<CR>
map <F5> :set nopaste<CR>
imap <F4> <C-O>:set paste<CR>
imap <F5> <nop>
set pastetoggle=<F11>
" Toggle line-numbers with key sequence Ctrl-N-N:
nmap <C-N><C-N> :set invnumber <CR>
" Consolidate swapfiles to keep working directories clean
set directory=~/.vim/swap</code></pre>
Been through some changes lately - this is the trimmed down of my .gvimrc (MacVim).
" window settings
set lines=70
set columns=200
set fileencoding=utf8<p><pre><code> set incsearch
set ignorecase
set hlsearch
" make the status line more useful
set statusline=%F%m%r%h%w[%L][%{&ff}]%y[%p%%][%04l,%04v]
set nocompatible
" backspace mode
set bs=2
" highlitt current line and add line numbers
set cursorline
set number
" yummy
set guifont=Monaco:h11.00
" turn off the scrollbars and the rest of the crap
set guioptions=eg
""set foldenable
""set foldmethod=indent
filetype plugin on
filetype on
" autoindenting
set cindent
set smartindent
set autoindent
" display improvements
set list
" show indents
set listchars=tab:\.\ ,trail:-
set ruler
set showcmd
" i use tabs instead of spaces, wanna make something of it?
set noexpandtab
set tabstop=4
set shiftwidth=4
set softtabstop=4
" temp files
set backupdir=~/.vim/bak
set directory=~/.vim/tmp
" colorz
syntax on
colorscheme herald " molokai, zenburn, darkburn, vibrantink
" PLUGINZ
" allml settings
let g:allml_global_maps = 1
let g:HiMtchBrkt=1
let g:SCMDiffCommand="/opt/subversion/bin/svn"
inoremap <C-B> <ESC>:call PhpDocSingle()<CR>
nnoremap <C-B> :call PhpDocSingle()<CR>
vnoremap <C-B> :call PhpDocRange()<CR>
" PHP specific fixes
" highlights interpolated variables in sql strings and does sql-syntax highlighting. yay
autocmd FileType php let php_sql_query=1
" does exactly that. highlights html inside of php strings
autocmd FileType php let php_htmlInStrings=1
" discourages use oh short tags. c'mon its deprecated remember
autocmd FileType php let php_noShortTags=1
" settings for cake
au BufNewFile *.ctp set filetype=php
au BufRead *.ctp set filetype=php</code></pre>
set nocompatible<p>set backspace=indent,eol,start<p>if has("vms")
set nobackup
else
set backup
endif
set history=50
set ruler
set showcmd
set incsearch<p>map Q gq<p>inoremap <C-U> <C-G>u<C-U><p>if has('mouse')
set mouse=a
endif<p>if &t_Co > 2 || has("gui_running")
syntax on
set hlsearch
endif<p>if has("autocmd")<p><pre><code> filetype plugin indent on
augroup vimrcEx
au!
autocmd FileType text setlocal textwidth=78
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
augroup END
</code></pre>
else<p><pre><code> set autoindent
</code></pre>
endif<p>if !exists(":DiffOrig")
command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
\ | wincmd p | diffthis
endif<p>colors zenburn<p>:filetype plugin on<p>set et
set sw=4
set smarttab
set lbr<p>set t_Co=256<p>set backupdir=./.backup,.,/tmp
set directory=.,./.backup,/tmp<p>set nobackup
set nowritebackup<p>set number<p>compiler ruby<p>autocmd Filetype ruby source ~/.vim/ruby-macros.vim
nnoremap <silent> <F8> :TlistToggle<CR><p>let Tlist_Auto_Open=1<p>:set title titlestring=%<%f\ %([%{Tlist_Get_Tagname_By_Line()}]%)<p>set virtualedit=all
A good line to memorize:<p><pre><code> :set et sts=4 sw=4 ts=4
et = expandtab (spaces instead of tabs)
ts = tabstop (the number of spaces that a tab equates to)
sw = shiftwidth (the number of spaces to use when indenting
-- or de-indenting -- a line)
sts = softtabstop (the number of spaces to use when expanding tabs)
</code></pre>
Also you might want to move 'colorscheme twilight' into the ~/.gvimrc file instead; it makes the .vimrc file cleaner when you separated out all of the gui-specific stuff.<p>My full vimrc and setup is here: <a href="http://github.com/bsandrow/vimc" rel="nofollow">http://github.com/bsandrow/vimc</a><p>{edit}
Another good one:<p><pre><code> noremap Y y$
</code></pre>
By default Y is mapped to the equivalent of yy. This makes Y act like the 'copy/yank' equivalent of D.
{/edit}
Here are just a couple things I find really useful day to day. I used to have a timeout that would revert to normal mode from insert mode after about 30 seconds if idle, but I got tired of that after about six months and just got in the habit of hitting Escape when I finished with an insert action. I did it just now, even though this is a textarea.<p><pre><code> " For (ab)use with :sp
map <C-j> <C-W>j<C-W>_
map <C-k> <C-W>k<C-W>_
set wmh=0 so=999 winheight=999
nnoremap i :noh<CR>i
" \s is global-replace-this-word
:nnoremap <Leader>s :%s/\<<C-r><C-w>\>//g<Left><Left></code></pre>
The interesting stuff only:<p><pre><code> set showbreak=>\
set wildignore=*.bak,*.pyc,*.swp
set wildmenu
set wildmode=list:longest
</code></pre>
This is actually quicker than reaching for ESC most of the time:<p><pre><code> inoremap <C-s> <ESC>
vnoremap <C-s> <ESC>
</code></pre>
Tab switching:<p><pre><code> noremap <C-l> gt
noremap <C-h> gT
</code></pre>
Something useful for syntax file writing:<p><pre><code> noremap <F6> :echo synIDattr(synID(line("."), col("."), 1), "name")<CR></code></pre>
Most of my .vim folder and .vimrc came from andreiz and tomasr. I have it committed to github for easy download on any server I'm working on. <a href="http://github.com/bnmrrs/dotfies" rel="nofollow">http://github.com/bnmrrs/dotfies</a> if anybody would like to check it out.<p><pre><code> map ,q :q!<CR>
map ,s :w<CR>
map ,w :x<CR>
nmap <silent> <F6> :set number!<CR>
</code></pre>
and ctags are especially useful
I think :set wildmenu is great, especially for relative newbies such as myself:<p><pre><code> command! CD cd %:p:h " change to current buffer's directory
set incsearch " Incremental search
set hlsearch " Highlight search
set guifont=Bitstream\ Vera\ Sans\ Mono\ 12
set nowritebackup " no stupid backup files
set noswapfile " no stupid recovery files
set wildmenu " it's wild
set visualbell
set fileformat=unix</code></pre>
Reformat hex-dumps into 32-bit words, 8 words per line.<p>nmap H :s/\v(\S{8})/\1 /g<CR>:s/\v((\S{8} ){8})/\1<C-V><CR>/g<CR>:nohl<CR>
<p><pre><code> "tab completion of words in insert mode
function InsertTabWrapper()
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<tab>"
else
return "\<c-p>"
endif
endfunction
inoremap <tab> <c-r>=InsertTabWrapper()<cr></code></pre>
I used almost everything from thoughtbot articles :<p><a href="http://robots.thoughtbot.com/post/166073596/intro-rails-vim" rel="nofollow">http://robots.thoughtbot.com/post/166073596/intro-rails-vim</a><p>and<p><a href="http://robots.thoughtbot.com/post/159805668/2009-rubyists-guide-to-a-mac-os-x-development" rel="nofollow">http://robots.thoughtbot.com/post/159805668/2009-rubyists-gu...</a>
I do a lot of copying/pasting from my browser (and other random places), so these mappings make my life easier:<p><pre><code> " copy/paste with the system clipboard
map ^P "+gP
map ^C "+y
</code></pre>
Also this, for dealing with DOS-style stuff:<p><pre><code> " map <ctrl>+s to remove ^M from the ends of lines
map ^S :%s\/^M\/\/g</code></pre>
<a href="http://github.com/msanders/vim-files/blob/master/.vimrc" rel="nofollow">http://github.com/msanders/vim-files/blob/master/.vimrc</a><p>Most of it's just my quirks but I think there's some useful bits in there. My vim setup is _heavily_ customized, for better or for worse.
I like autocomplete in my .vimrc<p>function! InsertTabWrapper()
let col = col('.')-1
if !col || getline('.')[col-1]!~'\k'
return "\<tab>"
else
return "\<C-P>"
endif
endfunction
inoremap <tab> <C-R>=InsertTabWrapper()<CR>
Adopted from the mighty tpope's vimrc file, and somewhat dependent on some of the plugins (also in my dotfiles repo on github)<p><a href="http://github.com/csexton/dotfiles/blob/master/home/vimrc" rel="nofollow">http://github.com/csexton/dotfiles/blob/master/home/vimrc</a>
someone mentioned listchars elsewhere, but I prefer these glyphs:<p><pre><code> set listchars=tab:»·,trail:·
set list
</code></pre>
this makes it so all your tabs and trailing whitespace is visible. note, this will make you hate almost every other developer.
It's a little outdated, but I spent some time on tweaking it: <a href="http://amix.dk/vim/vimrc.html" rel="nofollow">http://amix.dk/vim/vimrc.html</a><p>I specially like:<p><pre><code> map <space> /
map <c-space> ?
</code></pre>
And the parenthesis/bracket expanding.
Mine's not very advanced; .gvimrc for MacVim:<p><pre><code> set guifont=Pragmata:h14
set guioptions=egmrLt
set nohlsearch
set number
set ts=3
colors vividchalk
syntax on
</code></pre>
Pragmata is a delicious, delicious font.
Put your vimrc under revision control. Watch it grow from 5 lines to over 500 in the span of a year.<p>It seems like switching the developer bit in the brain for config files does wonders for environment personalization.
Lots: <a href="http://github.com/cdmwebs/dotfiles/raw/master/vimrc" rel="nofollow">http://github.com/cdmwebs/dotfiles/raw/master/vimrc</a><p>Probably time to clean it up a bit.
perhaps of interest:<p><pre><code> " for vertical split, with the pipe dividers hidden
:hi clear vertsplit
:hi vertsplit ctermbg=Black ctermfg=Black
" quit quits all
:nmap :q :qa
:nmap :wq :wqa
" H/L go to beginning/end of line without moving fingers
:nmap H 0
:nmap L $
" turn off matching paren highlighting
let loaded_matchparen = 1</code></pre>
Sorry about how long this is!! This is the culmination of about 1.5 years using VIM as my exclusive text editor for web development. When I started I was using PHP and now I'm using Ruby on Rails. If you have any general questions about VIM, specific questions about my .vimrc, or anything related, ask in the comments and I'll try to answer:<p>set fo=tcqln ic nohls nu sc scs sm tm=200 wim=longest,list nonumber<p>let g:explDetailedList=1<p>" store all of your vim swp files in one place, make sure this directory exists<p>set backupdir=/Users/{YOUR_USERNAME}/vim_swp<p>set directory=/Users/{YOUR_USERNAME}/vim_swp<p>set bs=indent,eol,start<p>set hlsearch<p>" Use incremental searching<p>set incsearch<p>" Set standard setting for PEAR coding standards<p>set tabstop=4<p>set shiftwidth=4<p>" Auto expand tabs to spaces<p>set expandtab<p>" Auto indent after a {<p>set autoindent<p>set smartindent<p>" Linewidth to endless<p>set textwidth=0<p>" Do not wrap lines automatically<p>set wrap<p>" DO NOT Show line numbers by default<p>set nonumber<p>" Jump 5 lines when running out of the screen<p>set scrolljump=5<p>" Indicate jump out of the screen when 3 lines before end of the screen<p>set scrolloff=3<p>" Repair wired terminal/vim settings<p>set backspace=start,eol<p>" This function determines, wether we are on the start of the line text (then tab indents) or<p>" if we want to try autocompletion<p>function InsertTabWrapper()<p><pre><code> let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<tab>"
else
return "\<c-p>"
endif
</code></pre>
endfunction<p>" Remap the tab key to select action with InsertTabWrapper<p>inoremap <tab> <c-r>=InsertTabWrapper()<cr><p>" set list<p>" set listchars=tab:>-,trail:-<p>" set listchars=tab:>-,trail:-,eol:$<p>set ignorecase " caseinsensitive searches<p>set showmode " always show command or insert mode<p>set ruler " show line and column information<p>set showmatch " show matching brackets<p>set formatoptions=tcqor<p>set whichwrap=b,s,<,>,[,]<p>syntax on<p>" Added by chris<p>" from <a href="http://items.sjbach.com/319/configuring-vim-right" rel="nofollow">http://items.sjbach.com/319/configuring-vim-right</a><p>set hidden<p>set history=1000<p>nnoremap ' `<p>nnoremap ` '<p>set smartcase "is case sensitive only if there's a capital letter<p>set title<p>" enables matching if/elseif/else/etc., sort of works<p>runtime macros/matchit.vim<p>"from <a href="http://blog.learnr.org/post/59098925/configuring-vim-some-more" rel="nofollow">http://blog.learnr.org/post/59098925/configuring-vim-some-mo...</a><p>map H ^<p>map L $<p>" End Added by chris<p>let loaded_matchparen = 1<p>nmap <F6> <ESC>:call LoadSession()<CR><p>let s:sessionloaded = 0<p>function LoadSession()<p><pre><code> source Session.vim
let s:sessionloaded = 1
</code></pre>
endfunction<p>function SaveSession()<p><pre><code> if s:sessionloaded == 1
mksession!
end
</code></pre>
endfunction<p>autocmd VimLeave * call SaveSession() "Reopen your session with 'vim -S
Session.vim'
<p><pre><code> " menu for encoding
set wildmenu
set wcm=<Tab>
set ts=4
menu Encoding.koi8-r :e ++enc=koi8-r<CR>
menu Encoding.windows-1251 :e ++enc=cp1251<CR>
menu Encoding.utf-8 :e ++enc=utf-8 <CR>
map <F8> :emenu Encoding.<TAB></code></pre>