set nocompatible
filetype off
" Vundle setup {{{
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Bundle 'gmarik/Vundle.vim'
Bundle 'ervandew/supertab'
Bundle 'airblade/vim-gitgutter'
Bundle 'scrooloose/syntastic'
Bundle 'tpope/vim-fugitive'
Bundle 'tpope/vim-surround'
Bundle 'vim-scripts/multvals.vim'
Bundle 'altercation/vim-colors-solarized'
Bundle 'vim-scripts/django.vim'
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 'tmhedberg/SimpylFold'
Bundle 'nvie/vim-flake8'
Bundle 'francoiscabrol/ranger.vim'
Bundle 'junegunn/fzf'
Bundle 'junegunn/fzf.vim'
Bundle 'chengzeyi/fzf-preview.vim'
Bundle 'alok/notational-fzf-vim'
call vundle#end()
filetype plugin indent on
"}}}
"
" Basic stuff {{{
set encoding=utf-8
set scrolloff=3
set modelines=0
set guifont=Inconsolata:h16
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=1
set laststatus=1
set showcmd
set showmode
set backspace=indent,eol,start
let mapleader = ","
"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
"}}}
" Abbreviations {{{
" easier markdown links:
let @a ='Sr%a()h'
let @s ='Sr%a(){: rel=nofollow}17h'
" email signature:
let @c ='icheers
Scott Gilbertson
sng@luxagraf.net '
let @w ='icheers
Scott Gilbertson
scott_gilbertson@condenast.com'
let @t ='iThank you for your help.
'
let @h ="iHello, my name is Scott Gilbertson and and I am a product writer with WIRED's Gear team. I am reaching out because we're working on an article about "
let @b ='tag=w050b-20'
let @n ='tag=wirednl-20'
let @d ='
'
" get rid of line breaks in paragraphs
let @p ='g/^./ .,/^$/-1 join'
" }}}
" Convenience mappings {{{
"for rewrapping things when composing email
map q gq}
"uppercase words
nnoremap up :%s/\<./\u&/g
"Lowercase words
nnoremap down :%s/\<./\l&/g
"conver to emdash
nnoremap - :%s/ -- /—/g
nnoremap t TlistToggle
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
nnoremap ;m :%s/
$//
"Let's just leave the whole w out of it shall we.
noremap h
noremap j
noremap k
noremap l
nmap n :NV!
" 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')
"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
" 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`]
" 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 :Ranger
" 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+=/home/lxf/.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
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 mzzMzvzz8`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()
augroup javascript_folding
au!
au FileType javascript setlocal foldmethod=syntax
augroup END
" Disable commands for creating and deleting folds.
"noremap zf
"noremap zF
"noremap zd
"noremap zD
noremap zE
" }}}
" Plugins {{{
"Ctrl P {{{
"nnoremap r :CtrlPMRU
"nnoremap m :CtrlPBuffer
"nnoremap . :CtrlP
"nnoremap w :CtrlP ~/writing/wired/
"nnoremap a :CtrlP app/
"nnoremap d :CtrlP $HOME/notes/
"nnoremap l :CtrlP $HOME/writing/luxagraf/
let g:ctrlp_custom_ignore = {
\ 'dir': '\v[\/]\.(git|hg|svn|venv|site|static)$',
\ 'file': '\v\.(pyc|so|dll)$',
\ }
"}}}
"FZF {{{
let g:fzf_preview_window='right:60%'
let g:fzf_history_dir = '~/.local/share/fzf-history'
set grepprg=rg\ --vimgrep\ --smart-case\ --hidden\ --follow
nnoremap . :FZF
nnoremap r :History
nnoremap w :FZF ~/writing/conde/wired/
nnoremap a :FZF app/
nnoremap l :Rg
nnoremap g :BLines
"}}}
" FZF Notational Velocity plugin {{{
let g:nv_search_paths = ['~/notes', '~/writing/luxagraf/', '~/documents/bookmarks/']
"}}}
"
" SimpylFold Python folding plugin {{{
let g:SimpylFold_docstring_preview = 0
"}}}
" make YCM compatible with UltiSnips (using supertab)
let g:ycm_key_list_select_completion = ['', '']
let g:ycm_key_list_previous_completion = ['', '']
let g:SuperTabDefaultCompletionType = ''
nnoremap :NV
let g:markdown_folding = 1
let g:markdown_fold_style = 'nested'
nmap i :%s/
//g
nmap # :%s/### /###/g
imap jj
vmap r :'<,'>:w !espeak &> /dev/null
xnoremap "+y y:call system("wl-copy", @")
nnoremap "+p :let @"=substitute(system("wl-paste --no-newline"), '', '', 'g')p