My .vimrc is about as minimalistic as the tax code. I have split it up into
several files and I source a lot of plugins, I make liberal use of the ruby vim
bindings. In fact, I just tar up my whole ~/.vim directory. If you are
interested in the whole thing, let me know, but here is my .vimrc.
================= BEGIN .vimrc =====================
"xterm settings
set t_AF=[%?%p1%{8}%<%t3%p1%d%e%p1%{22}%+%d;1%;m
set t_AB=[%?%p1%{8}%<%t4%p1%d%e%p1%{32}%+%d;1%;m
set t_kb=
fixdel
"Eterm settings for 16 colors {{{
"set t_Co=16
"set t_AF=[%?%p1%{8}%<%t3%p1%d%e%p1%{22}%+%d;1%;m
"set t_AB=[%?%p1%{8}%<%t4%p1%d%e%p1%{32}%+%d;1%;m
"set t_kb=
"fixdel
"}}}
"Turn on syntax highlighting {{{
if !exists("syntax_on")
syntax on
endif
"}}}
"Some custom default settings {{{
filetype plugin indent on "Turn filetype indent and plugins on
set tabstop=3 "set tabstop to 3
set shiftwidth=3 "make tabs be the same width as 3 spaces
"set backspace=2 "make backspace work how I expect
"set textwidth=80 "80 is the standard, too bad, 100 makes more
sense nowadays
set nocompatible "why would I not want to use all of vim's features?
set nobackup "these files get annoying, so turn it off
set nohlsearch "highlighting the current search is annoying
set incsearch "convenient when typing in a regex
set ruler "show cursor position
set showmatch "temporarily highlight the matching parens,
brackets, etc...
set modeline "this will allow modelines to work
set formatoptions=tcqn "This is my preference
set guioptions-=T "give me more screen real estate
set guioptions-=m "ditto
set guioptions-=r "ditto
set guioptions-=l "ditto
set foldcolumn=2 "make the nice little fold column 2 cols wide
set history=500 "set the command history to 500 entries
set wrapscan "allow searches to wrap around the end of the file
set tags=~/.vim/systags,tags; "This searches for a tags file from the cwd to
the root of the filesystem
set formatprg=astyle "astyle is a good source code reformatter
set number "turn on line numbering
set laststatus=2 "always display the status line
set awa "Autosave always instead of prompting
set viminfo='50,\"50 "Some viminfo settings
set scrolloff=5 "Leave 5 lines above and below the cursor when at
top and bottom of screen
set ul=250 "Set the max number of undos
set vb "Set visual bell
set fillchars=fold:- "Fill the fold line with spaces (type alt-space
to get the fill char)
set foldmethod=marker "Fold manually to maintain control
set diffopt=filler,iwhite "ignore whitespace when diffing...
set cinoptions=>1s,:1s,p1s,t0, "whatever this does, I like it :)
set cinwords=if,else,while,do,for,switch,case "these are pretty good
defaults
":wq:wqa:wqa!set statusline=%<%f\ %h%m%r\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \
%{VimBuddy()}%=%l,%c%V\ \ \ \ \ %P "Set my statusline
set
foldtext='+'.v:folddashes.substitute(GetFirstLineWithChars(),'\\\/\\\/\\\|\\*\\','','g')
set wildmenu "term menus for command mode
set wildmode=list:longest,full "ditto
"From Perl Best Practices" by Damian Conway and O'Reilly books
"set autoindent "Preserve current indent on new lines
set textwidth=78 "Wrap at this column
set backspace=indent,eol,start "Make backspaces delete sensibly
set expandtab "Convert all tabs typed to spaces
set shiftround "Indent/outdent to nearest tabstop
set matchpairs+=<:> "Allow % to bounce between angles too
"end From Perl Best Practices" by Damian Conway and O'Reilly books
"if this does not hold for a particular language change it in
after/syntax/XXX.vim
let b:commentchars="//"
let g:openmarker="\{\{\{" "This is for my folding function
let g:closemarker="\}\}\}" "This is for my folding function
"These settings are for minibufexpl.vim plugin
let g:miniBufExplSplitBelow=0
let g:miniBufExplMapWindowNavVim=1
"These settings are for the vimspell plugin
"let spell_executable="aspell"
"let g:netrw_ftp=1
"let g:netrw_ignorenetrc=1
"let g:netrw_win95ftp=1
"netrw settings
let g:netrw_ftpmode="ascii"
colorscheme midnight2 "set default colorscheme to midnight2
set shellslash
"VCSCommand plugin settings
let VCSCommandDeleteOnHide=1 "Delete temporary VCS buffers when the window
is closed
"}}}
"keymaps {{{
"map the tab completion
inoremap <silent> <tab> <c-r>=InsertTabWrapper()<cr>
inoremap <silent> <s-tab> <c-r>=RevInsertTabWrapper()<cr>
inoremap <silent> <c-tab> <tab>
"inoremap <silent> <bs> <c-r>=HungryBackspaceWrapper()<cr>
map <silent> zf :call PrintFoldMarker()<cr>
nmap <silent> cd :CD<cr>
nmap <silent> <leader>a :AS<cr>z10<cr><c-w>j
nmap <silent> m= :set guioptions+=m<cr>
nmap <silent> m- :set guioptions-=m<cr>
nmap <silent> ^r :call Resize()<cr>
"nmap <silent> <leader>c :call Makecoutstatements()<cr>
nmap <silent> <leader>gdb :call Make_GDB_Breakpoint_At_Cursor()<cr>
"The following edits my vimrc.
nmap <silent> <leader>rc :sp ~/.vimrc<cr>
nmap <silent> <leader>src :so ~/.vimrc<cr>
nmap <silent> <leader>mid :sp ~/.vim/colors/midnight2.vim<cr>
nmap <silent> <leader>my :sp ~/.vim/macro/myfuncs.vim<cr>
nmap <silent> <leader>smy :so ~/.vim/macro/myfuncs.vim<cr>
nmap <silent> <leader>re 80<c-w>+
nmap <silent> <right> :cn<cr>
nmap <silent> <left> :cp<cr>
nmap <silent> <up> :crewind<cr>
nmap <silent> <down> :copen 5<cr>
nmap <silent> <m-down> :cclose<cr>
nmap <silent> <leader><leader> V%zf
nmap <silent> K :Man <c-r>=expand("<cword>")<cr><cr>
nmap <silent> <leader>syn :syn sync fromstart<cr>
imap <silent><F2> <Esc>v`^me<Esc>gi<C-o>:call Ender()<CR>
nmap <silent> dp dp]c
"VCScommand mapping
nmap <Leader>cN :set noscb<cr>:40vs<cr>:VCSAnnotate<cr><c-w>k:wq<cr>gg:set
scb<CR>:set nowrap<CR><C-w>lgg:set scb<CR>:set nowrap<CR>
"}}}
"Source other configuration oriented files {{{
ru! macro/myfuncs.vim
ru! macro/scheme_func.vim
ru! macro/fortunes.vim
ru! macros/matchit.vim
ru! ftplugin/man.vim
"so $HOME/vimfiles/abbrev.vim
"so $HOME/.vim/plugin/a.vim
"}}}
"Custom auto commands {{{
if !exists("set_au")
let set_au = 1
"au bufnewfile *.c,*.h,*.java call Make_C_or_Java_SourceTemplate()
"au bufnewfile *.cpp call Make_cpp_template()
au bufnewfile *.rb call Make_Ruby_Template()
au bufreadpost *.cpp,*.c,*.h,*.java syn match semicolon #;$# | hi semicolon
guifg=red gui=bold ctermfg=1
"au bufreadpost *.cpp,*.c,*.h call Generate_Highlighting()
au bufreadpre,bufnewfile *.flex set ft=flex
au bufreadpre,bufnewfile twcslog set ft=twcslog
au bufreadpre,bufnewfile twcslog.* set ft=twcslog
au bufreadpre,bufnewfile *.bnf set ft=bnf
au bufreadpre,bufnewfile *.java compiler ant
au bufreadpre,bufnewfile *.java so ~/.vim/plugin/jcommenter.vim
au bufreadpre,bufnewfile gdbconf set ft=gdb
"Cerner specific syntax rules
"First remove the *.prg autocommand that comes standard with vim
au! filetypedetect * *.prg
au! filetypedetect * *.inc
au filetypedetect bufnewfile,bufreadpost *.inc,*.prg,*.ccl,*.csa,*.tst set
ft=ccl
endif
"}}}
"cscope settings {{{
if has("cscope")
set csprg=/usr/bin/cscope
set csto=1
set cst
set nocsverb
set cscopequickfix=s-,g-,d-,c-,t-,i-
" add any database in current directory
if filereadable("cscope.out")
cs add 'cscope.out'
" else add database pointed to by environment
elseif $CSCOPE_DB != ""
cs add $CSCOPE_DB
endif
set csverb
nmap <C-_> :cstag <C-R>=expand("<cword>")<CR><CR>
nmap <leader>gs :cs find s <C-R>=expand("<cword>")<CR><CR>
nmap <leader>gg :cs find g <C-R>=expand("<cword>")<CR><CR>
nmap <leader>gd :cs find d <C-R>=expand("<cword>")<CR><CR>
nmap <leader>gc :cs find c <C-R>=expand("<cword>")<CR><CR>
nmap <leader>gt :cs find t <C-R>=expand("<cword>")<CR><CR>
nmap <leader>gi :cs find i <c-r>=expand("%")<cr><cr>
else
set csto=1
endif
"}}}
================= END .vimrc =====================
Here is the file where I put most of my macros/vim functions:
================== BEGIN ~/.vim/macro/myfuncs.vim =====================
"This file contains some misc vim functions to use for my own purposes
"{{{
function! PrintFoldMarker() range
let fl = getline(a:firstline)
let ll = getline(a:lastline)
let l:lastline = a:lastline
"deal with the last line {{{
execute l:lastline
if match(ll, b:commentchars) >= 0
execute "norm! A ".g:closemarker
else
execute "norm! o".b:commentchars.g:closemarker
endif
"}}}
"deal with the first line {{{
execute a:firstline
if match(fl, b:commentchars) >= 0
execute "norm! A ".g:openmarker
else
execute "norm! O".b:commentchars.g:openmarker
endif
"}}}
endfunction
"}}}
"{{{
function! Make_C_or_Java_SourceTemplate()
ruby <<END
c = $curbuf
buf_name = c.name.gsub(/.*\//, '')
c.append 0, "/* file name : #{buf_name}"
c.append 1, " * authors : Michael Brailsford"
c.append 2, " * created : #{Time.now}"
c.append 3, " * copyright : (c) #{Time.now.year} Michael Brailsford"
c.append 4, " */"
buf_name.gsub! /\..*/, ''
if c.name =~ /\.h$/
buf_name.capitalize!
def_name = buf_name.upcase + "_H"
c.append 5, ""
c.append 6, "#ifndef #{def_name}"
c.append 7, "#define #{def_name}"
c.append 8, ""
c.append 9, "class #{buf_name} {"
c.append 10, "\tprivate:"
c.append 11, "\tprotected:"
c.append 12, "\tpublic:"
c.append 13, "\t\t#{buf_name}();"
c.append 14, "\t\t#{buf_name}(#{buf_name} &);"
c.append 15, "\t\t~#{buf_name}();"
c.append 16, "};"
c.append 17, "#endif"
VIM::command ":16"
elsif c.name =~ /\.cpp$/
c.append 5, ""
c.append 6, "#include \"#{buf_name.downcase}.h\""
c.append 7, "//{{{"
c.append 8, "#{buf_name}::#{buf_name}() {"
c.append 9, "}"
c.append 10, "//}}}"
c.append 11, "//{{{"
c.append 12, "#{buf_name}::#{buf_name}(#{buf_name} & other) {"
c.append 13, "}"
c.append 14, "//}}}"
c.append 15, "//{{{"
c.append 16, "#{buf_name}::~#{buf_name}() {"
c.append 17, "}"
c.append 18, "//}}}"
VIM::command ":7"
end
END
endfunction
"}}}
"{{{
function! Make_Ruby_Template()
ruby <<END
#Inserts a source template for ruby files
#This is to avoid these cvs token from being expanded when this file is
commited to cvs.
rev_key_word = "Revizion"
log_key_word = "Loz"
c = $curbuf
c.append 0, "#!/usr/bin/env ruby"
c.append 1, "# file name: #{c.name.gsub /.*\//, ''}"
c.append 2, "# author: Michael Brailsford"
c.append 3, "# created: #{Time.now}"
c.append 4, "# copyright: (c) #{Time.new.year} Michael Brailsford"
c.append 5, "# version: $#{rev_key_word.gsub /z/, 's'}$"
c.append 6, "# contents: "
c.append 7, ""
c.append 8, "=begin"
c.append 9, "\tchange log"
c.append 10, ""
c.append 11, "\t$#{log_key_word.gsub /z/, 'g'}$"
c.append 12, "=end"
$curwin.cursor = [7, 15]
END
endfunction
"}}}
"{{{
function! Makecoutstatements()
ruby <<END
ln, c = $curwin.cursor
bufname = $curbuf.name.gsub(/\.c(pp)?/, '_DEBUG')
bufname = bufname.split("/").last
bufname.upcase!
isdefined = false
firsttime = true
defline = 6
high_count = 0
tmp_str = ""
(1..30).each { |n|
unless isdefined
line = $curbuf[n]
case line
when /^\/\/#define #{bufname}(_[0-9]+)?$/
firsttime = false
tmp = line.split "_"
tmp_str = ""
if tmp.last
high_count = tmp.last.to_i.succ unless tmp.last.to_i <
high_count
else
high_count = 1
end
tmp_str << "#{bufname}_#{high_count.to_s}" unless
high_count == 0
when /^#define #{bufname}(_[0-9]+)?$/
firsttime = false
isdefined = true
bufname = line.split[1]
end
end
}
unless firsttime
bufname = tmp_str unless isdefined
end
$curbuf.append(ln, "#endif")
$curbuf.append(ln-1, "#ifdef #{bufname}")
$curbuf.append defline, "#define #{bufname}" unless isdefined
ln = ln.succ unless isdefined
$curwin.cursor = [ln+2, c]
END
endfunction
"}}}
"{{{
function! Comment_uncomment_defines(def_name)
ruby <<END
def_name = VIM.evaluate "a:def_name"
(1..45).each { |line_num|
line = $curbuf[line_num]
if line =~ /^#define #{def_name}/
$curbuf[line_num] = "//#{line}"
elsif line =~ /^\/\/#define #{def_name}/
$curbuf[line_num] = line.sub(/\/\//, '')
end
}
END
endfunction
"}}}
"{{{
function! Make_GDB_Breakpoint_At_Cursor()
let ln = line(".")
let fname = bufname("%")
let fn = substitute(fname, '.*\/', "", "")
sp .gdbinit
1
exec "norm! Obreak " fn ":" ln
unlet ln
unlet fname
unlet fn
endfunction
"}}}
"{{{
function! InsertTabWrapper()
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<tab>"
elseif pumvisible()
return "\<c-p>"
else
return "\<c-p>"
endif
endfunction
"}}}
"{{{
function! RevInsertTabWrapper()
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<tab>"
elseif pumvisible()
return "\<c-n>"
else
return "\<c-n>"
endif
endfunction
"}}}
"{{{
function! HungryBackspaceWrapper()
let column = col('.')
if column == 1
return "\<esc>kJxi"
elseif column >= 2 && getline('.')[column - 2] =~ '\S'
return "\<bs>"
else
return "\<Esc>d?\\S?e1\<CR>i"
endif
endfunction
"}}}
"{{{
function! Resize()
set lines=50
set co=140
endfunction
"}}}
"{{{
function! Cscope_Setup()
set csprg=/usr/bin/cscope
set csto=0
set cst
set nocsverb
" add any database in current directory
if filereadable("cscope.out")
cs add cscope.out
" else add database pointed to by environment
elseif $CSCOPE_DB != ""
cs add $CSCOPE_DB
endif
set csverb
endif
endfunction
"}}}
"{{{
function! Make_Method_From_Definition()
ruby << END
b = $curbuf
END
endfunction
"}}}
"{{{
function! GetFirstLineWithChars()
let numlines_folded = v:foldend - v:foldstart + 1
let line_num = 0
let charline = matchstr(getline(v:foldstart), '[<a-zA-Z0-9*][^{}]*')
while strlen(charline) == 0
let line_num = line_num + 1
let charline = matchstr(getline(v:foldstart + line_num),
'[<a-zA-Z0-9*][^{}]*')
endw
let return_str="[".numlines_folded." lines folded]: ".charline
return return_str
endfunction
"}}}
"{{{
function! Create_source_header_footer()
ruby <<END
b = $curbuf
buf_name = b.name.gsub(/.*\//, '')
#this is a kludge to avoid cvs changing this script when it is checked into
cvs
rev_key_word = "Revizion"
log_key_word = "Loz"
b.append 0, "/* file name : #{buf_name}"
b.append 1, " * contributors : Michael Brailsford"
b.append 2, " * header inserted : #{Time.now}"
b.append 3, " * copyright : (c) #{Time.now.year} Michael Brailsford"
b.append 4, " * version : $#{rev_key_word.gsub /z/, 's'}$"
b.append 5, " */"
b.append 6, ""
b.append 7, ""
b.append b.count, "/*"
b.append b.count, " * change log"
b.append b.count, " *"
b.append b.count, " * $#{log_key_word.gsub /z/, 'g'}$"
b.append b.count, " */"
END
endfunction
"}}}
"{{{
function! Ender()
let endchar = nr2char(getchar())
execute "normal \<End>a".endchar
normal `e
endfunction
"}}}
================== END ~/.vim/macro/myfuncs.vim =====================
Enjoy!!
-Michael
----- Original Message ----
From: Brent Thomson <[EMAIL PROTECTED]>
To: BYU Unix Users Group <[email protected]>
Sent: Friday, March 16, 2007 10:48:30 AM
Subject: Re: [uug] .vimrc examples
Daniel Dilts wrote:
> Call me a minimalist, but my .vimrc is extremely simple. I don't like
> having to use vim on systems where I don't have my .vimrc, but it is easier
> to use if your custom settings are minimal and can mostly be replaced from
> memory.
>
> set fdm=syntax
> set cindent
> set tabstop=4
> set background=dark
> set shiftwidth=4
> set foldcolumn=4
> syntax enable
Don't forget:
map <S-Insert> <MiddleMouse>
map! <S-Insert> <MiddleMouse>
set wildmode=longest,list
colorscheme desert
The first two commands turn on middle-click pasting. The third makes
tab-completion only complete partial words if there are multiple
matches, instead of completing the first match and then cycling through
the other matches (annoying!). The last applies the end-all, be-all
color scheme, created by our very own Hans Fugal. Thanks, Hans!
-Brent
--------------------
BYU Unix Users Group
http://uug.byu.edu/
The opinions expressed in this message are the responsibility of their
author. They are not endorsed by BYU, the BYU CS Department or BYU-UUG.
___________________________________________________________________
List Info: http://uug.byu.edu/cgi-bin/mailman/listinfo/uug-list
--------------------
BYU Unix Users Group
http://uug.byu.edu/
The opinions expressed in this message are the responsibility of their
author. They are not endorsed by BYU, the BYU CS Department or BYU-UUG.
___________________________________________________________________
List Info: http://uug.byu.edu/cgi-bin/mailman/listinfo/uug-list