Skip to content

Instantly share code, notes, and snippets.

@mcgrew
Created September 24, 2009 15:25
Show Gist options
  • Save mcgrew/192802 to your computer and use it in GitHub Desktop.
Save mcgrew/192802 to your computer and use it in GitHub Desktop.
.vimrc
" .vimrc
" Smart tabbing / autoindenting
set undolevels=100
set nocompatible
set autoindent
set smartindent
set smarttab
" Convert tabs to spaces
"set expandtab
" Allow backspace to back over lines
set backspace=2
set exrc
" Set tab width to 2.
set shiftwidth=2
set tabstop=2
set softtabstop=2
set cino=t0
" I like it writing automatically on swapping
set autowrite
set noshowcmd
if exists('&selection')
set selection=exclusive
endif
if !has("gui_running")
" enable the mouse in terminal
set mouse=a
endif
if has("gui_running")
" set the font to use
set guifont=Courier_New:h10
" Hide the mouse pointer while typing
set mousehide
endif
"Special error formats that handles borland make, greps
"Error formats :
" line = line number
" file = file name
" etype = error type ( a single character )
" enumber = error number
" column = column number
" message = error message
" _ = space
" file(line)_:_etype [^0-9] enumber:_message
" [^"] "file" [^0-9] line:_message
" file(line)_:_message
" [^ ]_file_line:_message
" file:line:message
" etype [^ ]_file_line:_message
" etype [^:]:__file(line,column):message = Borland ??
" file:line:message
" etype[^_]file_line_column:_message
set efm=%*[^\ ]\ %t%n\ %f\ %l:\ %m,%\\s%#%f(%l)\ :\ %t%*[^0-9]%n:\ %m,%*[^\"]\"%f\"%*[^0-9]%l:\ %m,%\\s%#%f(%l)\ :\ %m,%*[^\ ]\ %f\ %l:\ %m,%f:%l:%m,%t%*[^\ ]\ %f\ %l:\ %m,%t%*[^:]:\ \ %f(%l\\,%c):%m,%f:%l:%m,%t%*[^\ ]\ %f\ %l\ %c:\ %m
" This changes the status bar highlight slightly from the default
" " set highlight=8b,db,es,mb,Mn,nu,rs,ss,tb,vr,ws
"I like things quiet
"set visualbell
" Give some room for errors
set cmdheight=2
" always show a status line
"au VimEnter * set laststatus=2
set laststatus=2
set ruler
" Use a viminfo file
set viminfo='20,\"50
"set path=.,d:\wave,d:\wave\include,d:\wave\fdt
"set textwidth=80 " always limit the width of text to 80
"set textwidth=120 " always limit the width of text to 120
"set backup " keep a backup file
"set backupext=.bak
" Like having history
set history=100
" Map Y do be analog of D
map Y y$
" Toggle paste
map zp :set paste! paste?<CR>
" From the vimrc of 'Peppe'
" So I can get to ,
noremap g, ,
" Go to old line + column
noremap gf gf`"
noremap <C-^> <C-^>`"
" Switch off search pattern highlighting.
"set nohlsearch
set hlsearch
"Toggle search pattern hilighting and display the value
map <F7> :set hlsearch! hlsearch?<CR>
imap <F7> <C-O><F7>
" Map F9 to code completion
imap <F9> <C-x><C-o>
" Map F8 to list (showing tab & eol characters)
map <F8> :set list! list?<CR>
imap <F8> <C-O><F8>
"Ctags mapping for <alt n> and <alt p>
map <M-n> :cn<CR>z.:cc<CR>
map <M-p> :cp<CR>z.:cc<CR>
set shellpipe=2>&1\|tee
"set shellpipe=\|grep\ -v\ NOTE:\|tee
" Set nice colors
" background for normal text is light grey
" Text below the last line is darker grey
" Cursor is green
" Constants are not underlined but have a slightly lighter background
" highlight Normal guibg=grey95
highlight Cursor guibg=Red guifg=NONE
highlight Visual guifg=Sys_HighlightText guibg=Sys_Highlight gui=NONE
" highlight NonText guibg=grey90
" highlight Constant gui=NONE guibg=grey95
" highlight Special gui=NONE guibg=grey95
if has("gui_running")
"if &columns < 90 && &lines < 32
" win 90 32
au GUIEnter * win 90 32
" endif
" Make external commands work through a pipe instead of a pseudo-tty
set noguipty
endif
" Map control-cr to goto new line without comment leader
imap <C-CR> <ESC>o
" Look at syntax attribute
nmap <F4> :echo synIDattr(synID(line("."), col("."), 1), "name")<CR>
nmap <S-F4> :echo synIDattr(synID(line("."), col("."), 0), "name")<CR>
" delete the swap file
nmap \\. :echo strpart("Error Deleted",7*(0==delete(expand("%:p:h")."/.".expand("%:t").".swp")),7)<cr>
nmap <F2> :ConqueTermSplit bash<CR>
nmap <F3> :ConqueTermVSplit bash<CR>
" delete prev word
imap <C-BS> <c-w>
set joinspaces
" Today
if !exists('usersign')
let usersign=$username
endif
imap <F2> <C-R>=strftime("%d%b%Y")." ".usersign.":"<CR>
if has("menu")
imenu 35.60 &Insert.&Date<tab>F2 <c-r>=strftime("%d%b%Y")." ".usersign.":"<CR>
menu 35.60 &Insert.&Date<tab>F2 "=strftime("%d%b%Y")." ".usersign.":"<CR>p
imenu 35.60 &Insert.Date\ and\ &Username <c-r>=strftime("%d%b%Y")<CR>
menu 35.60 &Insert.Date\ and\ &Username "=strftime("%d%b%Y")<CR>p
endif
"set listchars=eol:¶,tab:›…,trail:_
" Enable 'wild menus'
set wildmenu
set showfulltag
set display+=lastline
set printoptions=syntax:y,wrap:y
" Switch on syntax highlighting.
syntax on
" set up some shortcuts for html editing (I can never remember these)
"map <F9>dtd1s :0<CR><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><CR><ESC>
"map <F9>dtd1t :0<CR>I<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><CR><ESC>
"map <F9>dtd1f :0<CR>I<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"><CR><ESC>
"map <F9>dtd11 :0<CR>I<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><CR><ESC>
"map <F9>dtd20 :0<CR>I<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0 Level 2//EN"><CR><ESC>
"map <F9>dtd30 :0<CR>I<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 3.0//EN"><CR><ESC>
"map <F9>dtd32 :0<CR>I<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><CR><ESC>
"map <F9>dtd4s :0<CR>I<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><CR><ESC>
"map <F9>dtd4t :0<CR>I<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><CR><ESC>
"map <F9>dtd4f :0<CR>I<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd"><CR><ESC>
"map <F9>dtd5 :0<CR>I<!DOCTYPE html><CR><ESC>
map <F9>dtd :0<CR>I<!DOCTYPE html><CR><ESC>
"Map F4 to create documentation comment blocks
"Map F6 to create a comment
"Map Shift+F6 to uncomment
function Python_settings( )
map <F4> ^y0o<ESC>0DpA<TAB>"""<ESC>yypO:Parameters:<CR><CR>rtype:<SPACE><CR>return:<SPACE><ESC>3k0
map <F6> :s/^/#/<CR>:let @/=""<CR>
map <S-F6> :s/^#//<CR>:let @/=""<CR>
endfunction
function Sh_settings( )
map <F4> ^y0O<ESC>0DpA##<SPACE><ESC>yypPA<SPACE>
map <F6> :s/^/#/<CR>:let @/=""<CR>
map <S-F6> :s/^#//<CR>:let @/=""<CR>
endfunction
function Sql_settings( )
map <F4> ^y0O<ESC>0DpA--<SPACE><ESC>yypPA<SPACE>
map <F6> :s/^/-- /<CR>:let @/=""<CR>
map <S-F6> :s/^-- //<CR>:let @/=""<CR>
endfunction
function Default_settings( )
map <F4> ^y0O<ESC>0DpA/**<CR><SPACE>*/<ESC>O*<SPACE><ESC>yyppA@param<SPACE><ESC>pA@return<SPACE><ESC>3kA
map <F6> :s/^/\/\//<CR>:let @/=""<CR>
map <S-F6> :s/^\/\///<CR>:let @/=""<CR>
endfunction
" Settings based on filetype
autocmd bufenter,bufcreate *
\ if &ft == "python"
\ | call Python_settings( )
\ | elseif &ft == "sql"
\ | call Sql_settings( )
\ | elseif &ft == "sh"
\ | call Sh_settings( )
\ | else
\ | call Default_settings( )
\| endif
autocmd bufnewfile *.html call setline(1,"<!DOCTYPE html>")
autocmd bufnewfile *.php call setline(1,"<?php") | call setline(2,"?>")
autocmd bufnewfile *.sh call setline(1,"#!/bin/bash")
map! <F4> <C-O><F4>
map! <F6> <C-O><F6>
"Map <F1> to <ESC>, since I hit it all the time by mistake.
map <F1> <ESC>
imap <F1> <ESC>
"Map Ctrl+t to adjust tab width
map <C-t>1 :set tabstop=1<CR>:set softtabstop=1<CR>:set shiftwidth=1<CR>
map <C-t>2 :set tabstop=2<CR>:set softtabstop=2<CR>:set shiftwidth=2<CR>
map <C-t>3 :set tabstop=3<CR>:set softtabstop=3<CR>:set shiftwidth=3<CR>
map <C-t>4 :set tabstop=4<CR>:set softtabstop=4<CR>:set shiftwidth=4<CR>
map <C-t>5 :set tabstop=5<CR>:set softtabstop=5<CR>:set shiftwidth=5<CR>
map <C-t>6 :set tabstop=6<CR>:set softtabstop=6<CR>:set shiftwidth=6<CR>
map <C-t>7 :set tabstop=7<CR>:set softtabstop=7<CR>:set shiftwidth=7<CR>
map <C-t>8 :set tabstop=8<CR>:set softtabstop=8<CR>:set shiftwidth=8<CR>
map <C-t>9 :set tabstop=9<CR>:set softtabstop=9<CR>:set shiftwidth=9<CR>
"
" show line numbers
set number
" I usually use a dark terminal background
set background=dark
" Ignore whitespace in vimdiff
set diffopt+=iwhite
" Highlight long lines
set colorcolumn=81
" Turn off line wrapping
set nowrap
"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment