set nocompatible filetype off " Vundle setup {{{ set rtp+=~/.vim/bundle/Vundle.vim call vundle#begin() Bundle 'gmarik/Vundle.vim' Bundle 'ervandew/supertab' Bundle 'honza/vim-snippets' Bundle 'airblade/vim-gitgutter' Bundle 'ctrlpvim/ctrlp.vim' Bundle 'scrooloose/syntastic' Bundle 'tpope/vim-fugitive' Bundle 'tpope/vim-repeat' Bundle 'tpope/vim-surround' Bundle 'vim-airline/vim-airline' Bundle 'vim-airline/vim-airline-themes' Bundle 'vim-scripts/multvals.vim' Bundle 'altercation/vim-colors-solarized' Bundle 'vim-scripts/Gundo' Bundle 'vim-scripts/django.vim' Bundle 'nelstrom/vim-markdown-folding' Bundle 'tpope/vim-markdown' Bundle 'amperser/proselint' Bundle 'jgdavey/tslime.vim' Bundle 'christoomey/vim-tmux-navigator' Bundle 'nicholaides/words-to-avoid.vim' Bundle 'reedes/vim-wordy' Bundle 'vim-scripts/vim-auto-save' Bundle 'rizzatti/dash.vim' Bundle 'gregsexton/matchtag' call vundle#end() filetype plugin indent on "}}} " Basic stuff {{{ set encoding=utf-8 set scrolloff=3 set modelines=0 set guifont=Inconsolata-dz:h12 set tabstop=4 set shiftwidth=4 set softtabstop=4 set expandtab set cursorline set autoindent set hidden set number set undofile set cpoptions+=$ set cmdheight=2 set laststatus=2 set showcmd set showmode set backspace=indent,eol,start "let mapleader = "." :nmap d DashSearch "save things when we turn our back autocmd BufLeave,FocusLost * silent! wall " save things all the time: let g:auto_save = 1 let g:auto_save_in_insert_mode = 0 "}}} " Statusline setup {{{ " let g:airline_powerline_fonts = 3 if !exists('g:airline_symbols') let g:airline_symbols = {} endif " unicode symbols let g:airline_left_sep = '»' let g:airline_left_sep = '⮀' let g:airline_right_sep = '«' let g:airline_right_sep = '◀' let g:airline_symbols.linenr = '␊' let g:airline_symbols.linenr = '␤' let g:airline_symbols.linenr = '¶' let g:airline_symbols.branch = '⎇' let g:airline_symbols.paste = 'ρ' let g:airline_symbols.paste = 'Þ' let g:airline_symbols.paste = '∥' let g:airline_symbols.whitespace = 'Ξ' " }}} " Abbreviations {{{ " easier markdown links: let @a ='Sr%a()h' " email signature: let @c ='icheers Scott Gilbertson sng@luxagraf.net ' " get rid of line breaks in paragraphs let @p ='g/^./ .,/^$/-1 join' let @d ='=strftime("%Y/%m/%d")' nnoremap "=strftime("%Y/%m/%d")P " }}} " Convenience mappings {{{ "map % "for rewrapping things when composing email map q gq} let g:EasyMotion_leader_key = '' "insert date/time :iab dts strftime("%FT%T%z") "uppercase words nnoremap up :%s/\<./\u&/g "Lowercase words nnoremap down :%s/\<./\l&/g nnoremap cd :lcd %:p:h " sane spelling options nnoremap sp :set spell! spelllang=en_us spell? set spellfile=~/.vim/dict.add map ]s map z= "quicker way to get to the thesaurus: inoremap ,t let g:marked_app = "Marked" noremap ,m :MarkedOpen "Let's just leave the whole w out of it shall we. noremap h noremap j noremap k noremap l " Convert curly quotes to straight. {{{ " Any argument causes substitute to confirm changes. function! ToStraight(line1, line2, args) let flags = 'eg' let range = a:line1 . ',' . a:line2 if empty(a:args) let range = 'silent ' . range else let flags .= 'c' endif let search = @/ exe range . "s/[‘’]/'/" . flags exe range . 's/[“””]/"/' . flags nohl let @/ = search endfunction command! -nargs=? -range ToStraight call ToStraight(, , '') nnoremap ,str :%ToStraight " Keep search matches in the middle of the window. nnoremap n nzzzv nnoremap N Nzzzv " Easier to type, and I never use the default behavior. noremap H ^ noremap L $ vnoremap L g_ nnoremap nnoremap inoremap inoremap inoremap inoremap nnoremap j gj nnoremap k gk " Make os x clipboard work set clipboard=unnamedplus " Visual mode pressing * or # searches for the current selection " Super useful! From an idea by Michael Naumann vnoremap * :call VisualSelection('f') vnoremap # :call VisualSelection('b') nnoremap g :GundoToggle imap jj "yank a line, not a line and some more nnoremap Y y$ nnoremap it /\vit's\|its " Fuck you, help key. noremap :checktime inoremap :checktime "nnoremap ww mz:%s/\s\+$//:let @/=''`z " zt is okay for putting something at the top of the screen, but when I'm " writing prose I often want to put something at not-quite-the-top of the " screen. zh is "zoom to head level" nnoremap zh mzzt10`z " Easier linewise reselection of what you just pasted. nnoremap V V`] " Indent/dedent/autoindent what you just pasted. " HTML tag closing inoremap :call InsertCloseTag()a " Select (charwise) the contents of the current line, excluding indentation. " Great for pasting Python lines into REPLs. nnoremap vv ^vg_ " Sudo to write cnoremap w!! w !sudo tee % >/dev/null " Insert Mode Completion {{{ inoremap inoremap inoremap " }}} " }}} " Searching ------------------------------------------------------------------- {{{ nnoremap / /\v vnoremap / /\v set ignorecase set smartcase set gdefault set incsearch set noshowmatch set hlsearch nnoremap :noh " }}} " Tab Completion -------------------------------------------------------------- {{{ set wildmode=list:longest,list:full set wildignore+=*.o,*.obj,.git,*.rbc,*.class,.svn,vendor/gems/* "}}} "Trying ranger function! RangeChooser() let temp = tempname() " The option "--choosefiles" was added in ranger 1.5.1. Use the next line " with ranger 1.4.2 through 1.5.0 instead. "exec 'silent !ranger --choosefile=' . shellescape(temp) if has("gui_running") exec 'silent !xterm -e ranger --choosefiles=' . shellescape(temp) else exec 'silent !ranger --choosefiles=' . shellescape(temp) endif if !filereadable(temp) redraw! " Nothing to read. return endif let names = readfile(temp) if empty(names) redraw! " Nothing to open. return endif " Edit the first item. exec 'edit ' . fnameescape(names[0]) " Add any remaning items to the arg list/buffer list. for name in names[1:] exec 'argadd ' . fnameescape(name) endfor redraw! endfunction command! -bar RangerChooser call RangeChooser() nnoremap ,nt :RangerChooser " Backups ----------------------------------------------------------------------{{{ set backup " enable backups set noswapfile " it's 2013, Vim. set undodir=~/.vimtmp/undo// " undo files set backupdir=~/.vimtmp/backup// " backups set directory=~/.vimtmp/swap// " swap files " Make those folders automatically if they don't already exist. if !isdirectory(expand(&undodir)) call mkdir(expand(&undodir), "p") endif if !isdirectory(expand(&backupdir)) call mkdir(expand(&backupdir), "p") endif if !isdirectory(expand(&directory)) call mkdir(expand(&directory), "p") endif " Make Vim able to edit crontab files again. set backupskip=/tmp/*,/private/tmp/*" " }}} "Thesaurus set thesaurus+=/Users/sng/.mthesaur.txt "}}} " Notes (AKA NValt in Vim){{{ " NValt style searching with Ack to quicklist command! -nargs=1 Nvs :Ack -i -n "" $NOTES_DIR command! -nargs=1 Ngrep vimgrep "" $NOTES_DIR/*.txt|:cw noremap n :Ngrep noremap v :Nvs " }}} " Filetype stuff {{{ augroup ft_vim au! au FileType vim setlocal foldmethod=marker au FileType help setlocal textwidth=78 augroup END " If the current buffer has never been saved, it will have no name, " call the file browser to save it, otherwise just save it. nnoremap :if expand("%") == ""browse confirm welseconfirm wendif au BufRead,BufNewFile *.twig set filetype=html autocmd BufRead,BufNewFile *.css,*.scss,*.less setlocal foldmethod=marker foldmarker={,} " turn on sentences level undo for prose: function s:undosentences () inoremap . .u inoremap ! !u inoremap ? ?u inoremap : :u setl wrap linebreak textwidth=0 wrapmargin=0 synmaxcol=999 filetype=markdown spell endfunction " txt, text, md and markdown are markdown files au BufEnter,BufRead,BufNewFile *.{text,txt,md,markdown} call s:undosentences() " syntastic and proselint let g:syntastic_check_on_open = 1 let g:syntastic_check_on_wq = 0 let g:syntastic_markdown_checkers = ['proselint'] " wrap python and other files: function s:mypythonsettings() highlight BadWhitespace ctermbg=red guibg=red "set foldmethod=indent "set textwidth=79 endfunction au BufRead,BufNewFile *.py,*.pyw,*.c,*.h call s:mypythonsettings() "}}} " Colors {{{ syntax on set background=dark let g:solarized_termtrans = 1 colorscheme solarized set t_Co=256 " force vim to use 256 colors let g:solarized_termcolors=256 "}}} " Folding {{{ set foldlevelstart=0 " Space to toggle folds. nnoremap za vnoremap za " Make zO recursively open whatever fold we're in, even if it's partially open. nnoremap zO zczO " "Focus" the current line. Basically: " " 1. Close all folds. " 2. Open just the folds containing the current line. " 3. Move the line to a little bit (15 lines) above the center of the screen. " 4. Pulse the cursor line. My eyes are bad. " " This mapping wipes out the z mark, which I never use. " " I use :sus for the rare times I want to actually background Vim. nnoremap mzzMzvzz15`z:Pulse function! MyFoldText() " {{{ let line = getline(v:foldstart) let nucolwidth = &fdc + &number * &numberwidth let windowwidth = winwidth(0) - nucolwidth - 3 let foldedlinecount = v:foldend - v:foldstart " expand tabs into spaces let onetab = strpart(' ', 0, &tabstop) let line = substitute(line, '\t', onetab, 'g') let line = strpart(line, 0, windowwidth - 2 -len(foldedlinecount)) let fillcharcount = windowwidth - len(line) - len(foldedlinecount) return line . '…' . repeat(" ",fillcharcount) . foldedlinecount . '…' . ' ' endfunction " }}} set foldtext=MyFoldText() " Disable commands for creating and deleting folds. "noremap zf "noremap zF "noremap zd "noremap zD noremap zE " }}} " Plugins {{{ " Formd stuff" {{{ " convert markdown inline links to reference " a function to execute formd and return the cursor back " to it's original position within the buffer. " This script assumes formd is in your path at: " ~/bin/formd/formd function! Formd(option) :let save_view = winsaveview() :let flag = a:option :if flag == "-r" :%! ~/bin/formd/formd -r :elseif flag == "-i" :%! ~/bin/formd/formd -i :else :%! ~/bin/formd/formd -f :endif :call winrestview(save_view) endfunction " formd mappings nmap mr :call Formd("-r") nmap mi :call Formd("-i") nmap m :call Formd("-f") "}}} " Unite for all the things {{{ "nnoremap :Unite file_rec/async "nnoremap ,s :Unite grep:. "nnoremap r :Unite -no-split -buffer-name=mru -start-insert file_mru "nnoremap l :Unite -no-split -buffer-name=buffer buffer "let g:unite_source_history_yank_enable = 1 "nnoremap y :Unite history/yank "nnoremap ,n :cd ~/notes :Unite file "nnoremap ,l :cd ~/sites/luxagraf :Unite file "nnoremap ,h :cd ~/sites/longhandpixels/_posts:Unite file "nnoremap ,f :cd ~/business/freelance\ writing/:Unite file "}}} "Trying Ctrl P for a while nnoremap r :CtrlPMRU nnoremap l :CtrlPBuffer nnoremap ,. :CtrlP nnoremap ,a :CtrlP app/ nnoremap ,d :CtrlP $HOME/notes/ nnoremap ,l :CtrlP $HOME/Sites/luxagraf let g:ctrlp_custom_ignore = { \ 'dir': '\v[\/]\.(git|hg|svn|venv)$', \ 'file': '\v\.(pyc|so|dll)$', \ } " Wordy config {{{ nnoremap ,w :Wordy "}}} nnoremap :TlistToggle "}}} " " make YCM compatible with UltiSnips (using supertab) let g:ycm_key_list_select_completion = ['', ''] let g:ycm_key_list_previous_completion = ['', ''] let g:SuperTabDefaultCompletionType = '' " better key bindings for UltiSnipsExpandTrigger let g:UltiSnipsExpandTrigger = "" let g:UltiSnipsJumpForwardTrigger = "" let g:UltiSnipsJumpBackwardTrigger = ""