diff options
Diffstat (limited to '.vimrc')
-rw-r--r-- | .vimrc | 466 |
1 files changed, 466 insertions, 0 deletions
@@ -0,0 +1,466 @@ +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 <silent> <leader>d <Plug>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")<CR>' +nnoremap <F5> "=strftime("%Y/%m/%d")<CR>P +" }}} +" Convenience mappings {{{ + +"map <tab> % +"for rewrapping things when composing email +map <leader>q gq} +let g:EasyMotion_leader_key = '<Leader>' + +"insert date/time +:iab <expr> dts strftime("%FT%T%z") +"uppercase words +nnoremap <leader>up :%s/\<./\u&/g<cr> +"Lowercase words +nnoremap <leader>down :%s/\<./\l&/g<cr> + + +nnoremap <leader>cd :lcd %:p:h<cr> + +" sane spelling options +nnoremap <leader>sp :set spell! spelllang=en_us spell?<CR> +set spellfile=~/.vim/dict.add +map <silent> <C-U> ]s +map <silent> <C-I> z= +"quicker way to get to the thesaurus: +inoremap ,t <c-x><c-t> + +let g:marked_app = "Marked" +noremap ,m :MarkedOpen <cr> + +"Let's just leave the whole w out of it shall we. +noremap <C-h> <C-w>h +noremap <C-j> <C-w>j +noremap <C-k> <C-w>k +noremap <C-l> <C-w>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(<line1>, <line2>, '<args>') +nnoremap ,str :%ToStraight<cr> +" 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 <left> <nop> +nnoremap <right> <nop> +inoremap <up> <nop> +inoremap <down> <nop> +inoremap <left> <nop> +inoremap <right> <nop> +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 <silent> * :call VisualSelection('f')<CR> +vnoremap <silent> # :call VisualSelection('b')<CR> + +nnoremap <leader>g :GundoToggle<CR> + +imap jj <Esc> +"yank a line, not a line and some more +nnoremap Y y$ +nnoremap <leader>it /\vit's\|its <cr> +" Fuck you, help key. +noremap <F1> :checktime<cr> +inoremap <F1> <esc>:checktime<cr> + +"nnoremap <leader>ww mz:%s/\s\+$//<cr>:let @/=''<cr>`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<c-u>`z + +" Easier linewise reselection of what you just pasted. +nnoremap <leader>V V`] + +" Indent/dedent/autoindent what you just pasted. + +" HTML tag closing +inoremap <C-_> <space><bs><esc>:call InsertCloseTag()<cr>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 <c-f> <c-x><c-f> +inoremap <c-]> <c-x><c-]> +inoremap <c-l> <c-x><c-l> + +" }}} + +" }}} + + + +" Searching ------------------------------------------------------------------- {{{ +nnoremap / /\v +vnoremap / /\v +set ignorecase +set smartcase +set gdefault +set incsearch +set noshowmatch +set hlsearch +nnoremap <leader><space> :noh<cr> +" }}} +" 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 :<C-U>RangerChooser<CR> + +" 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 "<args>" $NOTES_DIR +command! -nargs=1 Ngrep vimgrep "<args>" $NOTES_DIR/*.txt|:cw +noremap <leader>n :Ngrep +noremap <leader>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 <silent> <C-S> :if expand("%") == ""<CR>browse confirm w<CR>else<CR>confirm w<CR>endif<CR> +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 . .<C-g>u + inoremap ! !<C-g>u + inoremap ? ?<C-g>u + inoremap : :<C-g>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 <Space> za +vnoremap <Space> 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 <c-z> mzzMzvzz15<c-e>`z:Pulse<cr> + +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 <Nop> +"noremap zF <Nop> +"noremap zd <Nop> +"noremap zD <Nop> +noremap zE <Nop> +" }}} +" 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 <leader>mr :call Formd("-r")<CR> +nmap <leader>mi :call Formd("-i")<CR> +nmap <leader>m :call Formd("-f")<CR> +"}}} +" Unite for all the things {{{ + +"nnoremap <C-p> :Unite file_rec/async<cr> +"nnoremap ,s :Unite grep:.<cr> +"nnoremap <leader>r :<C-u>Unite -no-split -buffer-name=mru -start-insert file_mru<cr> +"nnoremap <leader>l :<C-u>Unite -no-split -buffer-name=buffer buffer<cr> +"let g:unite_source_history_yank_enable = 1 +"nnoremap <leader>y :Unite history/yank<cr> +"nnoremap ,n :cd ~/notes <cr>:Unite file <cr> +"nnoremap ,l :cd ~/sites/luxagraf <cr>:Unite file <cr> +"nnoremap ,h :cd ~/sites/longhandpixels/_posts<cr>:Unite file <cr> +"nnoremap ,f :cd ~/business/freelance\ writing/<cr>:Unite file <cr> +"}}} +"Trying Ctrl P for a while +nnoremap <leader>r :CtrlPMRU<cr> +nnoremap <leader>l :CtrlPBuffer<cr> +nnoremap ,. :CtrlP<cr> +nnoremap ,a :CtrlP app/<cr> +nnoremap ,d :CtrlP $HOME/notes/<cr> +nnoremap ,l :CtrlP $HOME/Sites/luxagraf<cr> +let g:ctrlp_custom_ignore = { + \ 'dir': '\v[\/]\.(git|hg|svn|venv)$', + \ 'file': '\v\.(pyc|so|dll)$', + \ } +" Wordy config {{{ +nnoremap ,w :Wordy<space> +"}}} +nnoremap <silent> <F8> :TlistToggle<CR> +"}}} +" +" make YCM compatible with UltiSnips (using supertab) +let g:ycm_key_list_select_completion = ['<C-n>', '<Down>'] +let g:ycm_key_list_previous_completion = ['<C-p>', '<Up>'] +let g:SuperTabDefaultCompletionType = '<C-n>' + +" better key bindings for UltiSnipsExpandTrigger +let g:UltiSnipsExpandTrigger = "<tab>" +let g:UltiSnipsJumpForwardTrigger = "<tab>" +let g:UltiSnipsJumpBackwardTrigger = "<s-tab>" + |