Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
335 lines (277 sloc) 9.69 KB
" Add all directories under $DOTFILES/vim/vendor as runtime paths, so plugins,
" docs, colors, and other runtime files are loaded.
let vendorpaths = globpath("$DOTFILES/vim", "vendor/*")
let vendorruntimepaths = substitute(vendorpaths, "\n", ",", "g")
execute "set runtimepath^=$DOTFILES/vim,".vendorruntimepaths
let vendorpathslist = split(vendorpaths, "\n")
for vendorpath in vendorpathslist
if isdirectory(vendorpath."/doc")
execute "helptags ".vendorpath."/doc"
" Use Vim settings, rather then Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
set nobackup
set nowritebackup
set noswapfile
set history=50 " keep 50 lines of command line history
set ruler " show the cursor position all the time
set showcmd " display incomplete commands
set incsearch " do incremental searching
set vb " turn on visual bell
set nu " show line numbers
set sw=2 " set shiftwidth to 2
set ts=2 " set number of spaces for a tab to 2
set et " expand tabs to spaces
set display=lastline " show as much as possible of the last line if it's too long to fit completely in the window
set wildignore=*.class
" For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
" let &guioptions = substitute(&guioptions, "t", "", "g")
" Don't use Ex mode, use Q for formatting
map Q gq
" This is an alternative that also works in block mode, but the deleted
" text is lost and it only works for putting the current register.
"vnoremap p "_dp
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
syntax on
set hlsearch
" Only do this part when compiled with support for autocommands.
if has("autocmd")
" Enable file type detection.
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on
" Put these in an autocmd group, so that we can delete them easily.
augroup vimrcEx
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
augroup END
set autoindent " always set autoindenting on
endif " has("autocmd")
" Key mappings ****************************************************************
" Easily open and reload vimrc
"<Leader>v brings up my .vimrc
"<Leader>V reloads it -- making all changes active (have to save first)
map <Leader>v :sp $DOTFILES/vimrc<CR>
map <silent> <Leader>V :source $HOME/.vimrc<CR>:if has("gui")<CR>:source $HOME/.gvimrc<CR>:endif<CR>:filetype detect<CR>:exe ":echo 'vimrc reloaded'"<CR>
" In command-mode, typing %/ will replace those chars with the directory of
" the file in the current buffer
cmap %/ <C-r>=expand('%:p:h')<CR>/
" execute current line as shell command, and open output in new window
map <Leader>x :silent . w ! sh > ~/.vim_cmd.out<CR>:new ~/.vim_cmd.out<CR>
" Emacs-like command-mode cursor navigation
cnoremap <C-a> <Home>
cnoremap <C-f> <Right>
cnoremap <C-b> <Left>
cnoremap <Esc>b <S-Left>
cnoremap <Esc>f <S-Right>
" Sessions ********************************************************************
set sessionoptions=blank,buffers,curdir,folds,help,options,resize,tabpages,winpos,winsize,globals
function! AutosaveSessionOn(session_file_path)
augroup AutosaveSession
exec "au VimLeave * mks! " . a:session_file_path
augroup end
let g:AutosaveSessionFilePath = a:session_file_path
echo "Auto-saving sessions to \"" . a:session_file_path . "\""
function! AutosaveSessionOff()
if exists("g:AutosaveSessionFilePath")
unlet g:AutosaveSessionFilePath
augroup AutosaveSession
augroup end
augroup! AutosaveSession
echo "Auto-saving sessions is off"
command! -complete=file -nargs=1 AutosaveSessionOn call AutosaveSessionOn(<f-args>)
command! AutosaveSessionOff call AutosaveSessionOff()
augroup AutosaveSession
au SessionLoadPost * if exists("g:AutosaveSessionFilePath") != 0|call AutosaveSessionOn(g:AutosaveSessionFilePath)|endif
augroup end
" Text formatting ********************************************************************
function! WordWrap(state)
if a:state == "on"
set lbr
set nolbr
com! WW call WordWrap("on")
com! Ww call WordWrap("off")
" White space ****************************************************************
let hiExtraWhiteSpace = "hi ExtraWhitespace ctermbg=red guibg=red"
exec hiExtraWhiteSpace
au ColorScheme * exec hiExtraWhiteSpace
au InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
au BufRead,InsertLeave * match ExtraWhitespace /\s\+$/
" Markdown *******************************************************************
function! PreviewMKD()
let tmpfile = tempname()
exe "write! " tmpfile
exe "silent !preview_mkd " tmpfile
exe "redraw!"
autocmd FileType markdown map <buffer> <Leader>p :call PreviewMKD()<CR>
autocmd FileType markdown call WordWrap("on")
autocmd FileType markdown set noet
" Folding *********************************************************************
function! EnableFolding()
set foldcolumn=2
set foldenable
function! DisableFolding()
set foldcolumn=0
set nofoldenable
set foldmethod=syntax
call DisableFolding()
function! FoldLevelSpaces(lnum)
let line = getline(a:lnum)
let cnt = 2
let pos = match(line, " ")
while pos != -1
let cnt = cnt + 1
let pos = match(line, " ", pos + 1)
return cnt/&tabstop
" Netrw
let g:netrw_liststyle=3
let g:netrw_browse_split=0
let g:netrw_list_hide='^\..*\.swp$'
let g:netrw_altv=1
" Command-T
let g:CommandTMaxFiles=80085
let g:CommandTMaxHeight=20
" VimClojure
let g:vimclojure#ParenRainbow=1
" Copy/paste *****************************************************************
let copy_cmd = ""
if system("which pbcopy") != ""
" On a Mac with pbcopy command
let copy_cmd = "pbcopy"
elseif system("which xclip") != ""
let copy_cmd = "xclip -i -selection clipboard"
if copy_cmd != ""
function! CopyToWindowManagerClipboard(type, copy_cmd, ...)
" This logic is mostly lifted from :help E775
let sel_save = &selection
let &selection = "inclusive"
let reg_save = @@
if a:type == "range"
let @@ = join(getline(a:1,a:2), "\n")
elseif a:0 " Invoked from Visual mode, use '< and '> marks.
silent exe "normal! `<" . a:type . "`>y"
elseif a:type == "command"
let @@ = getline(".")
elseif a:type == "line"
silent exe "normal! '[V']y"
elseif a:type == "block"
silent exe "normal! `[\<C-V>`]y"
silent exe "normal! `[v`]y"
call system(a:copy_cmd, @@)
let &selection = sel_save
let @@ = reg_save
vmap <silent> Y :<C-U>call CopyToWindowManagerClipboard(visualmode(), copy_cmd, 1)<CR>
map <Leader>yy :call CopyToWindowManagerClipboard("command", copy_cmd)<CR>
com! -range Y call CopyToWindowManagerClipboard("range",copy_cmd,<line1>,<line2>)
" Tab titles *****************************************************************
" Useful examples at:
if exists("+showtabline")
function! MyTabLine()
let s = ''
let t = tabpagenr()
let i = 1
while i <= tabpagenr('$')
let buflist = tabpagebuflist(i)
let winnr = tabpagewinnr(i)
let m = 0
for b in buflist
if getbufvar(b, "&modified")
let m += 1
let s .= '%' . i . 'T'
let s .= (i == t ? '%#TabLineSel#' : '%#TabLine#')
let s .= ' '
let s .= i . ':'
if m > 0
let s .= '+'
let s .= ' '
let buf = buflist[winnr - 1]
let buftype = getbufvar(buf, "&buftype")
let file = bufname(buf)
let file = fnamemodify(file, ':p:t')
if buftype == 'help'
let s .= '[Help] '
elseif buftype == 'quickfix'
if empty(getloclist(winnr))
let s .= '[Quickfix List]'
let s .= '[Location List]'
elseif file == ''
let s .= '[No Name]'
let s .= file
let s .= ' '
let i = i + 1
let s .= '%T%#TabLineFill#%='
let s .= (tabpagenr('$') > 1 ? '%999XX' : 'X')
return s
set tabline=%!MyTabLine()
" Colors *********************************************************************
if has("gui_running") || &t_Co == 256
colorscheme jellybeans-ryan
set bg=dark
function! GetColorSchemes()
let colorschemes = {}
for rtpath in split(&runtimepath, ",")
let colorscheme_files = split(glob(rtpath . "/colors/*.vim"), "\n")
for colorscheme_file in colorscheme_files
let colorname = substitute(colorscheme_file, "^.*/\\([^/]\\+\\)\\.vim$", "\\1", "")
let colorschemes[colorname] = colorscheme_file
return colorschemes
function! FListColorSchemes()
call append(0, keys(GetColorSchemes()))
setlocal nomodified nomodifiable bufhidden=delete nonumber nowrap foldcolumn=0 nofoldenable
nnoremap <buffer> <silent> q :<C-U>bdelete<CR>
nnoremap <buffer> <silent> <CR> :<C-U>set t_Co=256<CR>:hi clear<CR>:if exists("syntax_on")<CR>:syntax reset<CR>:endif<CR>:exe "colorscheme ".getline('.')<CR>
command! ListColorSchemes call FListColorSchemes()
Something went wrong with that request. Please try again.