Skip to content

Instantly share code, notes, and snippets.

@stsievert
Created May 23, 2015 22:23
Show Gist options
  • Save stsievert/6c5fb0a3a106fa426e54 to your computer and use it in GitHub Desktop.
Save stsievert/6c5fb0a3a106fa426e54 to your computer and use it in GitHub Desktop.
vim configuration
" REQUIRED INSTALL:
" > brew install macvim --with-cscope --with-lua --HEAD
" lua not required but HEAD required for breakindent
"
" QUICK REFACTOR
" * hover over word, press `*`
" * use :%s//newName/g to replace all occurences
" MARKDOWN PREVIEW
" * <leader>md to open up safari and view it live
" ULTISNIPS
" * <cntrl-f> to autocomplete. `template` used most often as snippet.
set nocompatible " be iMproved
" map leader key to <Space>
let mapleader = " "
let g:mapleader = " "
" set a save-every-write
inoremap <Esc> <Esc>:w<CR>: <CR>
" use jk/kj to get back to normal/command mode
imap jk <Esc>
"imap kj <Esc>
imap Jk <Esc>
imap jK <Esc>
imap JK <Esc>
call plug#begin('~/.vim/plugged')
Plug 'LaTeX-Box-Team/LaTeX-Box'
Plug 'scrooloose/nerdcommenter'
Plug 'kien/rainbow_parentheses.vim'
Plug 'godlygeek/tabular'
Plug 'wellle/targets.vim'
Plug 'sirver/UltiSnips'
Plug 'honza/vim-snippets'
Plug 'altercation/vim-colors-solarized'
Plug 'tpope/vim-markdown'
Plug 'mhinz/vim-startify'
Plug 'tpope/vim-rsi'
Plug 'haya14busa/incsearch.vim'
Plug 'shime/vim-livedown'
Plug 'Valloric/YouCompleteMe'
call plug#end()
" how (gui)vim looks
set printfont=Source\ Code\ Pro:h7
set guifont=Source\ Code\ Pro:h12
set guicursor+=a:blinkon0 " no blinking!
set breakindent
set title " set the title to filename
set shortmess " limited "Hit <Enter> to continue" prompts
set scrolloff=4
set background=light
colorscheme solarized
set relativenumber
set nosmartindent " no annoying comment thing (comment<CR>comment)
set guioptions-=r " remove the scroll bars
set guioptions-=l
set guioptions-=b
set noerrorbells " keep Vim silent
set spell!
set display=lastline " display the last line for long wrapped lines (ie, latex)
highlight CursorLineNr term=bold guibg=#eee9d4
autocmd ColorScheme * highlight CursorLineNr guibg=#eee9d4 term=bold
" how vim behaves
set autochdir " auto change to directory of file?
set formatoptions-=t " don't insert a newline when we get to 80chars!
set history=50 " keep a long history
nnoremap ' za
" easier folding of functions
syntax on " highlight syntax!
" make moving around easier
noremap gj j
noremap gk k
noremap j gj
noremap k gk
" custom leader maps
nnoremap <leader>g gqip
" unwrapping paragraphs (80 col)
noremap <Leader>w vipJ<CR>
" wrapping paragraphs (oo col)
nmap <leader>p :let @+ = expand("%:p:h")<CR>
" get path of file easily
nmap <silent> <leader><leader>c :nohlsearch<CR>
" to clear search results
nnoremap U :redo<CR>
" undo u, redo U
nmap <Leader>z 1z=
" spelling correction
nmap <Leader>z 1z=
" spelling correction
" text width
set textwidth=80 " the textwidth
" tabs
set expandtab " spaces for tab
set tabstop=4 " what counts as a tab?
set shiftwidth=4 " tab for autoindent
set autoindent " autoindent
set softtabstop=4 " for <Delete> when at a tab
" searching
set incsearch " search as you type
set hlsearch " highlight search terms
set ignorecase " case insensitive search
" folding
" press zc (-close) and zo (-open) to open
set foldmethod=indent
set foldlevel=10 " Max folding depth
set foldnestmax=10 " deepest fold
set nofoldenable " don't fold by default
" encode utf-8 by default
let printencoding='utf-8'
set encoding=utf-8
set fileencodings=ucs-bom,utf-8,latin1
" backing up
set nobackup " because we save every <Esc>
set noswapfile " because we save so often
""""""" INDIVIDUAL PLUGIN SETTINGS
" change number of files to see on new vim window
let g:startify_show_files_number = 20
let g:startify_bookmarks = ['~/.vimrc', '~/.zshrc', '~/.vim/UltiSnips/python.snippets','~/.vim/UltiSnips/tex.snippets']
" Livedown: for markdown preview in browser
nmap <Leader>md :LivedownPreview<CR>
" tabular
vnoremap <Leader>t :Tabular<space>/
" rainbow parens
let g:rbpt_colorpairs = [
\ [ '13', '#6c71c4'],
\ [ '5', '#d33682'],
\ [ '1', '#dc322f'],
\ [ '9', '#cb4b16'],
\ [ '3', '#b58900'],
\ [ '2', '#859900'],
\ [ '6', '#2aa198'],
\ [ '4', '#268bd2'],
\ ]
let g:rbpt_colorpairs = [
\ ['brown', 'RoyalBlue3'],
\ ['Darkblue', 'SeaGreen3'],
\ ['darkgray', 'DarkOrchid3'],
\ ['darkgreen', 'firebrick3'],
\ ['darkcyan', 'RoyalBlue3'],
\ ['darkred', 'SeaGreen3'],
\ ['darkmagenta', 'DarkOrchid3'],
\ ['brown', 'firebrick3'],
\ ['gray', 'RoyalBlue3'],
\ ['black', 'SeaGreen3'],
\ ['darkmagenta', 'DarkOrchid3'],
\ ['Darkblue', 'firebrick3'],
\ ['darkgreen', 'RoyalBlue3'],
\ ['darkcyan', 'SeaGreen3'],
\ ['darkred', 'DarkOrchid3'],
\ ['red', 'firebrick3'],
\ ]
au VimEnter * RainbowParenthesesToggle
au BufEnter * RainbowParenthesesLoadRound
au BufEnter * RainbowParenthesesLoadSquare
au BufEnter * RainbowParenthesesLoadBraces
" Ultisnips
let g:UltiSnipsExpandTrigger="<c-f>"
let g:UltiSnipsListSnippets="<c-s-tab>"
" YouCompleteMe
" don't complete on everything
let g:ycm_filetype_blacklist = {'notes' : 1, 'markdown' : 1, 'text' : 1, 'latex' : 1, 'tex' : 1}
" Specific filetypes
fun! LaTeXQuote(action)
" Relying on buffer local variables requires 'hidden'. If you do
" not like this, QuoteStart will be reset every time the buffer is
" loaded. At least according to the docs.
" Furthermore, the mappings failed to work with
" vim -u NONE -c "so latexquotes.vim" -c "e tmp.tex"
" Something in my setup makes it work properly, though.
if !exists("b:QuoteStart")
let b:QuoteStart=1
endif
let val=b:QuoteStart
let b:QuoteStart=1-b:QuoteStart
if a:action == "insert"
if val
return "``"
else
return "''"
endif
elseif a:action == "switch"
if b:QuoteStart
echo "Start LaTeX Quote"
else
echo "End LaTeX Quote"
endif
endfun
function! TexSetup()
" don't break lines earlier
set textwidth=0
" conceal level
set cole=2
let g:tex_conceal="abmgs"
" disable paren matching (lines 1220-1227 in auctex.vim)
let g:LatexBox_completion_close_braces=0
let g:auctex_complete_braces = 0
let g:LatexBox_viewer = "open /Applications/Skim.app"
" compile and view respectively
nmap <leader>l \ll
nmap <leader>o \lv
" make the undercurl go away for bad spelling
hi SpellBad guisp=blue gui=underline guifg=NONE guibg=NONE ctermfg=NONE ctermbg=NONE cterm=underline term=underline
" spelling
set spell
" Set up mappings for " and a way to switch between start and end quotes
au BufEnter *.tex imap " <C-R>=LaTeXQuote("insert")<CR>
au BufEnter *.tex nmap <F2> :call LaTeXQuote("switch")<CR>
endfunction
function! MarkdownSetup()
autocmd Filetype markdown set spell
autocmd Filetype markdown set syntax=markdown
autocmd Filetype markdown set textwidth=79
setlocal spelllang=en_us
" make the undercurl go away for bad spelling
hi SpellBad guisp=blue gui=underline guifg=NONE guibg=NONE ctermfg=NONE ctermbg=NONE cterm=underline term=underline
endfunction
function! PythonSetup()
" Python autocompletion
" Load the whole plugin
setlocal expandtab shiftwidth=4 softtabstop=4
"let g:pymode = 1
" setting up UltiSnips
"let g:UltiSnipsUsePythonVersion = 2
" make the undercurl go away for bad spelling
hi SpellBad guisp=blue gui=underline guifg=NONE guibg=NONE ctermfg=NONE ctermbg=NONE cterm=underline term=underline
setlocal nospell
endfunction
function! AllSetup()
" make the undercurl go away for bad spelling
hi SpellBad guisp=blue gui=underline guifg=NONE guibg=NONE ctermfg=NONE ctermbg=NONE cterm=underline term=underline
" for wrapping the display lines on a long single line
set wrap
set linebreak
set nolist
let &showbreak = ''
set spelllang=en_us
hi SpellBad guisp=blue gui=underline guifg=NONE guibg=NONE ctermfg=NONE ctermbg=NONE cterm=underline term=underline
endfunction
autocmd BufNew,BufNewFile,BufRead *.txt,*.text,*.md,*.markdown set filetype=markdown
autocmd BufNewFile,BufReadPost *.md set filetype=markdown
autocmd BufNew,BufNewFile,BufRead *.tex set filetype=tex
autocmd BufNew,BufNewFile,BufRead *.c set filetype=c
"" specific file types and their config
autocmd Filetype tex call TexSetup()
autocmd Filetype markdown call MarkdownSetup()
autocmd Filetype python call PythonSetup()
autocmd Filetype * call AllSetup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment