scriptencoding utf-8 set encoding=utf-8 " Store the current system name so that we can conditionally set configs for " different platforms let s:uname = system("echo -n \"$(uname)\"") let s:vim_dir = $HOME . "/.vim" function! IsWindows() if s:uname =~ "mingw" return 1 endif return 0 endfunction let mapleader="," set nocompatible filetype off """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " PLUGINS """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" call plug#begin('~/.vim/plugged') Plug 'mattn/webapi-vim' " Required by gist-vim Plug 'mattn/gist-vim' Plug 'bling/vim-airline' Plug 'tpope/vim-obsession' Plug 'tpope/vim-fugitive' Plug 'tpope/vim-classpath' Plug 'tpope/vim-dispatch' Plug 'craigemery/vim-autotag' " DISABLED since it requires vim 7.3.598+ and I don't have that on my macbook " Plug 'Valloric/YouCompleteMe' Plug 'rking/ag.vim' Plug 'scrooloose/syntastic' Plug 'nelstrom/vim-qargs' " Colors Plug 'reedes/vim-colors-pencil' Plug 'nanotech/jellybeans.vim' Plug 'sickill/vim-monokai' Plug 'elixir-lang/vim-elixir' Plug 'chmllr/elrodeo-colorscheme' Plug 'altercation/vim-colors-solarized' " Clojure Plug 'kien/rainbow_parentheses.vim' Plug 'guns/vim-clojure-highlight' Plug 'guns/vim-clojure-static' Plug 'tpope/vim-fireplace', { 'for': 'clojure' } call plug#end() filetype plugin indent on """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " BASIC EDITING CONFIGURATION """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " allow unsaved background buffers and remember marks/undo for them set hidden set history=10000 set expandtab set tabstop=2 set shiftwidth=2 set softtabstop=2 set autoindent set laststatus=2 set showmatch set incsearch set dictionary+=/usr/share/dict/words "set clipboard=unnamed " yank and paste with the system clipboard set number set hlsearch " make searches case-sensitive only if they contain upper-case characters set ignorecase smartcase " highlight current line set cmdheight=2 set switchbuf=useopen set numberwidth=5 set showtabline=2 set winwidth=79 if IsWindows() " Just assume we don't have a zsh shell set shell=bash else set shell=zsh endif " Prevent Vim from clobbering the scrollback buffer. See " http://www.shallowsky.com/linux/noaltscreen.html set t_ti= t_te= " keep more context when scrolling off the end of a buffer set scrolloff=3 " Store temporary files in a central spot set backup set backupdir=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp set directory=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp " allow backspacing over everything in insert mode set backspace=indent,eol,start " display incomplete commands set showcmd " Spell checking autocomplete set complete+=kspell " Enable highlighting for syntax syntax on " 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. " use emacs-style tab completion when selecting files, etc set wildmenu set wildmode=longest,list,full set wildignore+=*/tmp/*,*/log/*,*.so,*.swp,*.zip,*/rdoc/* set colorcolumn=90 " Show trailing whitespace set list listchars=tab:»·,trail:· " Adding this since the esc remap on the 'i' key had a long delay when pressed set timeoutlen=300 ttimeoutlen=0 " Allow undo when doing back into a closed file set undolevels=1000 set undoreload=10000 " Keep undo history across sessions by storing it in a file if has('persistent_undo') let undo_dir = expand(s:vim_dir . '/undo') " Create dirs if IsWindows() let mkdir = 'mkdir ' else let mkdir = 'mkdir -p ' endif :silent call system(mkdir . s:vim_dir) :silent call system(mkdir . undo_dir) let &undodir = undo_dir " Persist undo set undofile endif " When loading text files, wrap them and don't split up words. au BufNewFile,BufRead *.txt setlocal wrap au BufNewFile,BufRead *.txt setlocal lbr " Remove trailing whitespace on save all files. au BufWritePre * :%s/\s\+$//e " Fix vim's background colour erase - http://snk.tuxfamily.org/log/vim-256color-bce.html if &term =~ '256color' " Disable Background Color Erase (BCE) so that color schemes " work properly when Vim is used inside tmux and GNU screen. " See also http://snk.tuxfamily.org/log/vim-256color-bce.html set t_ut= endif " Disable arrow keys map map map map imap imap imap imap " Notes and other helpers map pn :sp ~/.personal-files/brain/writing/stack.txt map sn :sp ~/.personal-files/documents/software-notes/clojure.md map rn :sp ~/.work-files/dive-networks/files/notes/refactoring-notes.md """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Run build script """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" function! RunBuildScript() let l:existing_buf = bufwinnr("__build_output_log__") let l:current_buf = bufnr("%") " Save current buffer in case there are unsaved changes silent! wall if l:existing_buf > 0 silent! exe l:existing_buf . " wincmd w" "execute 'botright sb' l:existing_buf else botright sp __build_output_log__ setlocal buftype=nofile resize 10 endif " Clear the buffer normal! ggdG " Output compile log into buffer let l:output = system("./build.sh") call append(0, split(l:output, '\v\n')) go silent! exe l:existing_buf. " wincmd w" endfunction nnoremap b :call RunBuildScript() nnoremap bb :bw! """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Lisp """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Rainbow parens ala rainbow_parentheses.vim au VimEnter * RainbowParenthesesToggle au Syntax * RainbowParenthesesLoadRound au Syntax * RainbowParenthesesLoadSquare au Syntax * RainbowParenthesesLoadBraces """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Schemes """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " properly indent schemes (scheme, racket, etc) autocmd bufread,bufnewfile *.lisp,*.scm,*.rkt setlocal equalprg=scmindent.rkt """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " COLORS """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" let s:default_bg = 'dark' let s:dark_theme = 'pencil' let s:light_theme = 'pencil' let g:airline_theme = 'pencil' if s:default_bg =~ 'light' " The order that these are set matters for some themes exe 'colorscheme ' . s:light_theme set background=light else exe 'colorscheme ' . s:dark_theme set background=dark endif " Switch between light and dark map l :call ChangeBgTheme('dark') map ll :call ChangeBgTheme('light') function! ChangeBgTheme(bg) if a:bg =~ 'light' let s:theme = s:light_theme else let s:theme = s:dark_theme endif exe 'colorscheme ' . s:theme exe 'set background=' . a:bg " Have to run this twice to get the plugin to set the colors exec ":RainbowParenthesesToggle" exec ":RainbowParenthesesToggle" endfunction """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " CUSTOM AUTOCMDS """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" augroup vimrcEx " Clear all autocmds in the group autocmd! autocmd FileType text setlocal textwidth=78 " Jump to last cursor position unless it's invalid or in an event handler autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif autocmd FileType ruby,haml,eruby,yaml,html,javascript,sass,cucumber set ai sw=2 sts=2 et autocmd FileType python set sw=4 sts=4 et " Indent p tags autocmd FileType html,eruby if g:html_indent_tags !~ '\\|p\>' | let g:html_indent_tags .= '\|p\|li\|dt\|dd' | endif " Spell check autocmd BufRead,BufNewFile *.md setlocal spell spelllang=en_us augroup END """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " STATUS LINE """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" :set statusline=%<%f\ (%{&ft})\ %-4(%m%)%=%-19(%3l,%02c%03V%) """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " HIGHLIGHT TODO, NOTE, FIXME, etc """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" augroup vimrc_bugs au! au Syntax * syn match MyBugs /\v<(FIXME|BUG|DEPRECATED|OPTIMIZE):/ \ containedin=.*Comment,vimCommentTitle augroup END hi def link MyBugs Todo augroup vimrc_notes au! au Syntax * syn match MyNotes /\v<(IDEA|NOTE|QUESTION|WARNING|IMPORTANT):/ \ containedin=.*Comment,vimCommentTitle augroup END hi def link MyNotes WildMenu """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " GIT """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" map gb :Gblame """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " SEARCHING """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " TODO: Not sure if I still need this map gs :let @/ = "" " Replace the selected text in all files within the repo function! GlobalReplaceIt(confirm_replacement) if exists(':Ggrep') " let term = @/ " if empty(term) call inputsave() let l:term = input('Enter search term: ') call inputrestore() " else " echo '\nReplacing '.term " endif call inputsave() let l:replacement = input('Enter replacement: ') call inputrestore() if a:confirm_replacement let l:confirm_opt = 'c' else let l:confirm_opt = 'e' endif execute 'Ggrep '.l:term execute 'Qargs | argdo %s/'.l:term.'/'.l:replacement.'/g'.l:confirm_opt.' | update' else echo "Unable to search since you're not in a git repo" endif endfunction map gg :call GlobalReplaceIt(0) map gr :call GlobalReplaceIt(1) function! Search() let l:term = input('Grep search term: ') if l:term != '' exec 'Ag "' . l:term . '"' endif endfunction map s :call Search() """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " MISC KEY MAPS """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " insert an end tag with imap end " insert a clojure lambda imap (fn [x] " Mapping ESC in insert mode and command mode to double i "imap ii "cmap ii " suspend process nmap z " Quickly edit/reload the vimrc file nmap ev :vsp $MYVIMRC nmap rv :so $MYVIMRC " remap saving and quiting nmap w :w nmap q :q nmap qq :q! nmap x :x :ca Wa wa :ca WA wa :ca WQ wq :ca Wq wq :ca W w :ca Q q command! Q q " Bind :Q to :q command! Qall qall " Disable Ex mode map Q if exists(':terminal') " Terminal mapping map t :terminal tnoremap e tnoremap h tnoremap j tnoremap k tnoremap l nnoremap h nnoremap j nnoremap k nnoremap l endif " Map ctrl-movement keys to window switching map map map map " Make it easier to jump around the command line. The default behaviour is " using the arrow keys with or without shift :cnoremap :cnoremap " Window splitting - couldn't figure out how to remap v & n to " & map m :vsplit map mm :split " Delete a word forward and backward map a daw map d ciw " Map paste and nonumber map p :set paste! paste? map o :set number! number? " Spell checking map j :exec &spell==&spell? "se spell! spelllang=en_us" : "se spell!" map = z= " Clear the search buffer (highlighting) when hitting return function! MapCR() nnoremap :nohlsearch endfunction call MapCR() nnoremap " Replace currently selected text with default register without yanking it vnoremap p "_dP """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " ABBREVIATIONS """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" :ab teh the :ab taht that :ab kewyord keyword :ab indentity identity :ab indetity identity """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " MULTIPURPOSE TAB KEY """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" function! InsertTabWrapper() let l:col = col('.') - 1 if !l:col || getline('.')[l:col - 1] !~ '\k' return "\" else return "\" endif endfunction inoremap =InsertTabWrapper() inoremap """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " RENAME CURRENT FILE """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" function! RenameFile() let l:old_name = expand('%') let l:new_name = input('New file name: ', expand('%'), 'file') if l:new_name != '' && l:new_name != l:old_name exec ':saveas ' . l:new_name exec ':silent !rm ' . l:old_name redraw! endif endfunction map n :call RenameFile() """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " PROMOTE VARIABLE TO RSPEC LET """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" function! PromoteToLet() :normal! dd " :exec '?^\s*it\>' :normal! P :.s/\(\w\+\) = \(.*\)$/let(:\1) { \2 }/ :normal == endfunction :command! PromoteToLet :call PromoteToLet() :map pl :PromoteToLet """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " MARKDOWN """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Use Marked.app to preview Markdown files... nnoremap pp :silent !open -a Marked.app '%:p' """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " SELECTA -- find files with fuzzy-search """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Run a given vim command on the results of fuzzy selecting from a given shell " command. See usage below. function! SelectaCommand(choice_command, selecta_args, vim_command) try let l:selection = system(a:choice_command . " | selecta " . a:selecta_args) catch /Vim:Interrupt/ " Swallow the ^C so that the redraw below happens; otherwise there will be " leftovers from selecta on the screen redraw! return endtry redraw! exec a:vim_command . " " . l:selection endfunction " Find all files in all non-dot directories starting in the working directory. " Fuzzy select one of those. Open the selected file with :e. nnoremap f :call SelectaCommand("find * -type f ! -path 'resources/public/js/*' ! -path 'resources/.sass-cache/*' ! -path 'target/*'", "", ":e") """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " NERDTREE """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" "nmap d :NERDTreeToggle "nmap ff :NERDTreeFind """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " GIST VIM """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" let g:gist_detect_filetype = 1 let g:gist_open_browser_after_post = 1 let g:gist_show_privates = 1 let g:gist_post_private = 1 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " VIM-CLOJURE-STATIC """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Default let g:clojure_fuzzy_indent = 1 let g:clojure_align_multiline_strings = 1 let g:clojure_fuzzy_indent_patterns = ['^match', '^with', '^def', '^let'] let g:clojure_fuzzy_indent_blacklist = ['-fn$', '\v^with-%(meta|out-str|loading-context)$'] """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " C-TAGS """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" set tags+=tags;$HOME