vimrc 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  1. """"" My (demuredemeanor) .vimrc
  2. "" Uses tabstop=4; shiftwidth=4; foldmarker={{{,}}};
  3. """"""""vim: set tabstop=4 shiftwidth=4:
  4. "" Above is an attempt at a modeline, which seems to have a issue
  5. "" where long pastes get a new line...
  6. "" https://notabug.org/demure/dotfiles/
  7. "" legacy repo http://github.com/demure/dotfiles
  8. """ Commands at Start """ {{{
  9. "" This one needs to be first
  10. set nocompatible " Choose no comp with legacy vi
  11. if has("syntax")
  12. syntax on " Adds vim color based on file
  13. endif
  14. "" Enable filetype settings
  15. if has("eval")
  16. filetype on
  17. filetype plugin on
  18. filetype indent on
  19. endif
  20. """ Folds Settings """ {{{
  21. if has("folding")
  22. set foldenable " Enable folds
  23. "" These next two would save which folds are open/close, as well
  24. "" as view location, but seems to force set foldmethod=indent...
  25. "au BufWinLeave ?* mkview
  26. "au BufWinEnter ?* silent loadview
  27. set foldmethod=marker
  28. set fillchars=fold:.
  29. highlight Folded ctermfg=Grey ctermbg=Black
  30. "set foldlevelstart=99 " Effectively disable auto folding
  31. """ Foldtext """ {{{
  32. "" Inspired by http://www.gregsexton.org/2011/03/improving-the-text-displayed-in-a-fold/
  33. set foldtext=CustomFoldText()
  34. function! CustomFoldText()
  35. "" Process line
  36. let fs = v:foldstart
  37. let fLinePrep = substitute(getline(fs), '\t', '+---', 'g')
  38. let fLine = substitute(fLinePrep, ' {\{3}', '', 'g')
  39. "" Process line count and fold precentage
  40. let fSize = 1 + v:foldend - v:foldstart
  41. let fSizeStr = " " . fSize . " lines "
  42. let fLineCount = line("$")
  43. let fPercent = printf("[%.1f", (fSize*1.0)/fLineCount*100) . "%] "
  44. "" Process fold level
  45. let fLevel = "{".v:foldlevel."} "
  46. "" Process filler string
  47. let w = winwidth(0) - &foldcolumn - (&number ? 8 : 0)
  48. let expansionString = repeat(".", w - strwidth(fSizeStr.fLine.fPercent.fLevel))
  49. "return fLine . expansionString . fSizeStr . foldPercent . foldLevel
  50. return fLine . fSizeStr . fPercent . fLevel
  51. endfunction
  52. """ End Foldtext """ }}}
  53. endif
  54. """ End Folds Settings """ }}}
  55. "" Stop auto comment on new line
  56. autocmd FileType * setlocal formatoptions-=cro
  57. set shortmess+=atIT " Stop messages at vim launch
  58. runtime macros/matchit.vim " Add '%' matching to if/elsif/else/end
  59. "" Mutt settings
  60. " Support Format-Flowed in email (mutt).
  61. " Because it is a good-ness? http://joeclark.org/ffaq.html
  62. autocmd FileType mail setlocal fo+=aw tw=72
  63. "" vimdiff settings
  64. if &diff
  65. colorscheme slate
  66. endif
  67. """ End Commands at Start """ }}}
  68. """ Plugins """ {{{
  69. if $USER != 'mobile'
  70. """ Setting up Vundle """ {{{
  71. "" From http://www.erikzaadi.com/2012/03/19/auto-installing-vundle-from-your-vimrc/
  72. let iCanHazVundle=1
  73. let vundle_readme=expand('~/.vim/bundle/vundle/README.md')
  74. if !filereadable(vundle_readme)
  75. echo "Installing Vundle.."
  76. echo ""
  77. silent !mkdir -p ~/.vim/bundle
  78. "" Disabled for git url
  79. "silent !git clone https://github.com/gmarik/vundle ~/.vim/bundle/vundle
  80. silent !git clone git://github.com/gmarik/vundle.git ~/.vim/bundle/vundle
  81. let iCanHazVundle=0
  82. endif
  83. set rtp+=~/.vim/bundle/vundle/
  84. """""""call vundle#rc() ""commented out for vundle version bump change??
  85. call vundle#begin()
  86. "" Use git instead of http
  87. let g:vundle_default_git_proto = 'git'
  88. "" Have vundle first...
  89. Plugin 'gmarik/vundle'
  90. """ Bundles """ {{{
  91. ""Add your bundles here
  92. """ Style """ {{{
  93. Plugin 'altercation/vim-colors-solarized' " Solarized theme
  94. Plugin 'syntax-highlighting-for-tintinttpp' " Tintin++ syntax
  95. Plugin 'bling/vim-airline' " Even better than powerline/neatstatus
  96. Plugin 'nathanaelkane/vim-indent-guides' " vim-indent-guides default binding: <Leader>ig
  97. Plugin 'kien/rainbow_parentheses.vim' " Colorize parentheses and similar chars
  98. Plugin 'myusuf3/numbers.vim' " Make num ruler auto switch absolute/rel for insert/norm
  99. Plugin 'mhinz/vim-signify' " Add git diff
  100. Plugin 'mboughaba/i3config.vim' " i3 conf syntax
  101. """ End Style """ }}}
  102. """ Added Interface """ {{{
  103. Plugin 'scrooloose/nerdtree' " File browser
  104. Plugin 'bufexplorer.zip' " buffer browser
  105. Plugin 'sjl/gundo.vim' " Undo history tree
  106. "Plugin 'szw/vim-ctrlspace' " Super buffer controlness, disabled due to never using
  107. Plugin 'haya14busa/incsearch.vim' " Improved incremental searching
  108. Plugin 'spolu/dwm.vim' " dwm like split control
  109. """ End Interface """ }}}
  110. """ Added Functionality """ {{{
  111. Plugin 'tpope/vim-repeat' " Makes '.' repeat work with plugins
  112. Plugin 'scrooloose/nerdcommenter' " Make commenting easy
  113. Plugin 'YankRing.vim' " Improves copy/paste
  114. Plugin 'tpope/vim-fugitive' " git from vim
  115. Plugin 'scrooloose/syntastic' " Code syntax checker
  116. "Plugin 'SearchComplete' " Disabled due to killing UP arrow in search
  117. Plugin 'Lokaltog/vim-easymotion' " <prefix><prefix>motion
  118. Plugin 'chrisbra/csv.vim' " Good CVS file handling
  119. Plugin 'dhruvasagar/vim-table-mode' " Make easy tables
  120. "Plugin 'vim-scripts/Smart-Tabs' " Use \t for indents, and spaces elsewhere
  121. Plugin 'jamessan/vim-gnupg' " Transparent editing of gpg encrypted files
  122. """ End Functionality """ }}}
  123. """ Misc """ {{{
  124. Plugin 'uguu-org/vim-matrix-screensaver' " Add unnecessary matrix screen saver
  125. Plugin 'takac/vim-hardtime' " Plugin to break bad movement habits
  126. """ End Misc """ }}}
  127. ""...All your other bundles...
  128. """ End Bundles """ }}}
  129. call vundle#end() " required
  130. if iCanHazVundle == 0
  131. echo "Installing Bundles, please ignore key map error messages"
  132. echo ""
  133. :PluginInstall
  134. endif
  135. """ End Setting Up Vundle """ }}}
  136. """ Plugin Confs """ {{{
  137. """ NERDtree config """ {{{
  138. "" Starts NERDtree if no file is give to vim at start
  139. "autocmd vimenter * if !argc() | NERDTree | endif
  140. """ End NERDtree """ }}}
  141. """ Vim Repeat Conf """ {{{
  142. "" This is to make repeat work for plugins too
  143. silent! call repeat#set("\<Plug>MyWonderfulMap", v:count)
  144. """ End Vim Repeat """ }}}
  145. """ Better Rainbow Parentheses """ {{{
  146. "" https://github.com/kien/rainbow_parentheses.vim
  147. """ Auto Rainbow """ {{{
  148. au VimEnter * RainbowParenthesesToggle
  149. au Syntax * RainbowParenthesesLoadRound
  150. au Syntax * RainbowParenthesesLoadSquare
  151. au Syntax * RainbowParenthesesLoadBraces
  152. """ End Auto """ }}}
  153. nmap <leader>[ :RainbowParenthesesToggle <CR>
  154. """ End Rainbow Parenthesis """ }}}
  155. """ YankRing Conf """ {{{
  156. "" :h yankring-tutorial
  157. nnoremap <silent> <F3> :YRShow<CR>
  158. inoremap <silent> <F3> <ESC>:YRShow<CR>
  159. map <silent> <prefix>y :YRShow<CR>
  160. let g:yankring_history_dir = '~/.vim'
  161. """ End YankRing """ }}}
  162. """ Solarized Theme """ {{{
  163. "call togglebg#map("<F6>")
  164. if has('gui_running')
  165. set background=light
  166. colorscheme solarized
  167. endif
  168. """ End Solarized """ }}}
  169. """ Gundo Conf """ {{{
  170. "" http://sjl.bitbucket.org/gundo.vim/
  171. nnoremap <F4> :GundoToggle<CR>
  172. """ End Gundo """ }}}
  173. """ Numbers.vim Conf""" {{{
  174. "" https://github.com/myusuf3/numbers.vim
  175. nnoremap <leader>n :NumbersToggle<CR>
  176. """ End Nunmbers.vim """ }}}
  177. """ Vim Indent Guides """ {{{
  178. "" https://github.com/nathanaelkane/vim-indent-guides
  179. "" <Leader>ig
  180. let g:indent_guides_auto_colors = 0
  181. "autocmd VimEnter,Colorscheme * :hi IndentGuidesOdd guibg=red ctermbg=236
  182. autocmd VimEnter,Colorscheme * :hi IndentGuidesOdd guibg=red ctermbg=240
  183. autocmd VimEnter,Colorscheme * :hi IndentGuidesEven guibg=green ctermbg=244
  184. let g:indent_guides_enable_on_vim_startup = 1
  185. "let g:indent_guides_guide_size = 2
  186. let g:indent_guides_start_level = 2
  187. """ End Indent Guides """ }}}
  188. """ Airline Conf """ {{{
  189. "" Added to fix airline (forces status visibility)
  190. set laststatus=2
  191. "" Disable auto echo?
  192. let g:bufferline_echo = 0
  193. "" Remove default mode indicator
  194. set noshowmode
  195. """ End Airline Conf """ }}}
  196. """ Hardtime Conf """ {{{
  197. let g:hardtime_default_on = 1
  198. let g:hardtime_ignore_buffer_patterns = [ "CustomPatt[ae]rn", "NERD.*", "Task.*" ]
  199. """ End Hardtime """ }}}
  200. """ Syntastic Conf """ {{{
  201. let g:syntastic_auto_loc_list=1
  202. """ End Syntastic """ }}}
  203. """ Vim-CtrlSpace Conf """ {{{
  204. "" https://github.com/szw/vim-ctrlspace
  205. "" Make work with airline
  206. let g:airline_exclude_preview = 1
  207. """ End Vim-CtrlSpace """ }}}
  208. """ Incsearch.vim Conf """ {{{
  209. "" https://github.com/haya14busa/incsearch.vim
  210. let g:incsearch#magic = '\v'
  211. map / <Plug>(incsearch-forward)
  212. map ? <Plug>(incsearch-backward)
  213. map g/ <Plug>(incsearch-stay)
  214. """ End Incsearch.vim """ }}}
  215. """ DWM.vim Conf """ {{{
  216. nnoremap <silent> <C-b> :call DWM_New()<CR>
  217. """ End DWM.vim Conf """ }}}
  218. """ End Plugin Confs """ }}}
  219. endif
  220. """ End Plugins """ }}}
  221. """ Theming """ {{{
  222. if has('gui_running')
  223. set background=light
  224. colorscheme solarized
  225. else
  226. colorscheme torte
  227. endif
  228. """ End Theming """ }}}
  229. """ Options """ {{{
  230. """ Assorted """ {{{
  231. set autoread " Reload files changed outside vim
  232. set encoding=utf8 " Sets encoding View
  233. set scrolloff=3 " Show next three lines scrolling
  234. set sidescrolloff=2 " Show next two columns scrolling
  235. set ttyfast " Indicates a fast terminal connection
  236. set splitbelow " New horizontal splits are below
  237. set splitright " New vertical splits are to the right
  238. set history=1000 " Increase command/search history
  239. set confirm " Vim prompts for :q/:qa/:w issues
  240. """ End Assorted """ }}}
  241. """ HUD """ {{{
  242. set number " Adds line numbers
  243. set showcmd " Show incomplete cmds down the bottom
  244. "" Disabled for air-line
  245. "set showmode " Shows input or replace mode at bottom
  246. set ruler " Show position in bottom right
  247. """ End HUD """ }}}
  248. """ Input """ {{{
  249. set virtualedit=block,onemore " Cursor can move one past EOL, and free in Visual mode
  250. " set virtualedit=all " Allow virtual editing, all modes.
  251. set mouse=a " Enable mouse, all modes
  252. set backspace=indent,eol,start " Allow backspace in insert mode
  253. """ End Input """ }}}
  254. """ Mac kill damn bold """ {{{
  255. if has('mac')
  256. set t_Co=256 " FORCE 256 colors in vim
  257. endif
  258. """ End Mac """ }}}
  259. """ Wild Stuffs... """ {{{
  260. set wildmenu " Show list instead of just completing
  261. set wildmode=list:longest,full " Command <Tab> completion, list matches, then longest common part, then all.
  262. "" From http://blog.sanctum.geek.nz/lazier-tab-completion/
  263. if exists("&wildignorecase")
  264. set wildignorecase " Ignore case in file name completion
  265. endif
  266. "" From http://bitbucket.org/sjl/dotfiles/overview
  267. set wildignore+=.hg,.git,.svn " Version control
  268. set wildignore+=*.aux,*.out,*.toc " LaTeX intermediate files
  269. set wildignore+=*.jpg,*.bmp,*.gif,*.png,*.jpeg " binary images
  270. set wildignore+=*.o,*.obj,*.exe,*.dll,*.manifest " compiled object files
  271. set wildignore+=*.spl " compiled spelling word lists
  272. set wildignore+=*.sw? " Vim swap files
  273. set wildignore+=*.DS_Store " OSX bullshit
  274. set wildignore+=*.luac " Lua byte code
  275. set wildignore+=migrations " Django migrations
  276. set wildignore+=*.pyc " Python byte code
  277. set wildignore+=*.orig " Merge resolution files
  278. "" Clojure/Leiningen
  279. set wildignore+=classes
  280. set wildignore+=lib
  281. """ End Wild """ }}}
  282. """ Show Hidden Chars """ {{{
  283. set list " Shows certain hidden chars
  284. set listchars=eol:¬,tab:▶-,trail:~,extends:>,precedes:<,nbsp:·
  285. hi NonText ctermfg=darkgray " Makes trailing darkgray
  286. hi SpecialKey ctermfg=darkgray " Makes Leading darkgray
  287. """ End Hidden Chars """ }}}
  288. """ Spelling """ {{{
  289. set spell " Spelling hilight on
  290. " highlight SpellBad cterm=underline ctermfg=red
  291. hi SpellBad cterm=underline ctermbg=NONE
  292. hi SpellCap cterm=underline ctermbg=NONE
  293. """ End Spelling """ }}}
  294. """ Tab Windows """ {{{
  295. set hidden " Hides buffers, instead of closing, or forcing save
  296. set showtabline=2 " shows the tab bar at all times
  297. set tabpagemax=100 " max num of tabs to open on startup
  298. hi TabLineSel ctermbg=Yellow " Current Tab
  299. hi TabLine ctermfg=Grey ctermbg=DarkGrey " Other Tabs
  300. hi TabLineFill ctermfg=Black " Rest of line
  301. hi Title ctermfg=DarkBlue ctermbg=None " Windows in Tab
  302. """ End Tab Windows """ }}}
  303. """ Tab Key Settings """ {{{
  304. "" prefer tabs now...
  305. set expandtab "" use spaces, not tabs
  306. set tabstop=4 " Set Tab length
  307. set shiftwidth=4 " Affects when you press >>, << or ==. And auto indent.
  308. set shiftround " Uses multiple of shiftwidth when indenting with '<' and '>'
  309. set softtabstop=4 " With space indenting, lets vim delete multiple spaces at once
  310. "" disabled per https://stackoverflow.com/questions/234564/tab-key-4-spaces-and-auto-indent-after-curly-braces-in-vim
  311. " set smarttab " Insert Tabs at ^ per shiftwidth, not tabstop
  312. set autoindent " Always set auto indenting on
  313. set copyindent " Copy prior indentation on autoindent
  314. """ End Tab Key """ }}}
  315. """ Searching """ {{{
  316. " Use real regex search
  317. nnoremap / /\v
  318. vnoremap / /\vi
  319. set hlsearch " Highlight matches
  320. set incsearch " Incremental searching
  321. set ignorecase " Searches are case insensitive...
  322. "" Disabled as was annoying with command completion
  323. "set smartcase " ...unless contains oneplus Cap letter
  324. set showmatch " Show matching brackets/parenthesis
  325. set gdefault " Applies substitutions globally on lines. Append 'g' to invert back.
  326. set synmaxcol=800 " Don't highlight lines longer than 800 chars
  327. set wrapscan " Scan wraps around the file
  328. """ End Searching """ }}}
  329. """ Backup Settings """ {{{
  330. """ Dir Validation """ {{{
  331. if !isdirectory(expand("~/.vim/back/"))
  332. call mkdir(expand("~/.vim/back/"), "p")
  333. endif
  334. if !isdirectory(expand("~/.vim/swap/"))
  335. call mkdir(expand("~/.vim/swap/"), "p")
  336. endif
  337. if !isdirectory(expand("~/.vim/undo/"))
  338. call mkdir(expand("~/.vim/undo/"), "p")
  339. endif
  340. """ End Dir """ }}}
  341. set backup " Enable backups
  342. set undofile " Enable undo file
  343. set undoreload=10000
  344. set backupdir=~/.vim/back/
  345. set directory=~/.vim/swap/ " swap files
  346. set undodir=~/.vim/undo/ " undo files
  347. """ End Backup Settings """ }}}
  348. """ Timeout Settings """ {{{
  349. set timeout " :mapping time out
  350. set timeoutlen=1000 " :mapping time out length
  351. set ttimeout " Key code time out
  352. set ttimeoutlen=50 " key code time out length
  353. """ End Timeout """ }}}
  354. """ End Options """ }}}
  355. """ Aliases """ {{{
  356. command! BI BundleInstall
  357. """ End Aliases """ }}}
  358. """ Functions """ {{{
  359. """ DiffSaved """ {{{
  360. "" To compare current vs saved version
  361. "" http://vim.wikia.com/wiki/Diff_current_buffer_and_the_original_file
  362. "" To get out of diff view you can use the :diffoff command.
  363. function! s:DiffWithSaved()
  364. let filetype=&ft
  365. diffthis
  366. vnew | r # | normal! 1Gdd
  367. diffthis
  368. exe "setlocal bt=nofile bh=wipe nobl noswf ro ft=" . filetype
  369. endfunction
  370. com! DiffSaved call s:DiffWithSaved()
  371. """End DiffSaved """ }}}
  372. """ End Functions """ }}}
  373. """ Key Bindings """ {{{
  374. let mapleader="," " Change the mapleader from '\' to ','
  375. map <leader>/ :noh<return> " <leader>/ will clear search hilights!
  376. """ Quickly edit/reload the vimrc file """ {{{
  377. "" maps the ,ev and ,sv keys to edit/reload .vimrc.
  378. nmap <silent> <leader>ev :tabedit $MYVIMRC<CR>
  379. nmap <silent> <leader>sv :so $MYVIMRC<CR>
  380. """ End reload """ }}}
  381. """ Paste Toggle, for stopping formating of pastes """ {{{
  382. nnoremap <F2> :set invpaste paste?<CR>
  383. set pastetoggle=<F2>
  384. nmap <leader>p :set invpaste paste?<CR>
  385. """ End Paste Toggle """ }}}
  386. """ Vim Tab Window Keysbindings """ {{{
  387. " nnoremap <C-Left> :tabprevious<CR>
  388. " nnoremap <C-Right> :tabnext<CR>
  389. " nnoremap <silent> <A-Left> :execute 'silent! tabmove ' . (tabpagenr()-2)<CR>
  390. " nnoremap <silent> <A-Right> :execute 'silent! tabmove ' . tabpagenr()<CR>
  391. """ End Tab Window Keys """ }}}
  392. """ Navigate Splits """ {{{
  393. "" uses ',' key first
  394. map <leader>h :wincmd h<CR>
  395. map <leader>j :wincmd j<CR>
  396. map <leader>k :wincmd k<CR>
  397. map <leader>l :wincmd l<CR>
  398. map <leader> <Left> :wincmd h<CR>
  399. map <leader> <Down> :wincmd j<CR>
  400. map <leader> <Up> :wincmd k<CR>
  401. map <leader> <Right> :wincmd l<CR>
  402. """ End Navigate Splits """ }}}
  403. """ Toggle colorcolumn """ {{{
  404. highlight ColorColumn ctermbg=Brown
  405. function! g:ToggleColorColumn()
  406. if &colorcolumn != ''
  407. setlocal colorcolumn&
  408. else
  409. setlocal colorcolumn=77
  410. endif
  411. endfunction
  412. nnoremap <silent> <leader>L :call g:ToggleColorColumn()<CR>
  413. """ End Toggle colorcolumn """ }}}
  414. """ Cross Hairs """ {{{
  415. hi CursorLine cterm=NONE ctermbg=darkgrey ctermfg=white guibg=darkred guifg=white
  416. hi CursorColumn cterm=NONE ctermbg=darkgrey ctermfg=white guibg=darkred guifg=white
  417. nnoremap <Leader>+ :set cursorline! cursorcolumn!<CR>
  418. """ End Cross Hair """ }}}
  419. """ DiffOrig """ {{{
  420. "command DiffOrig let g:diffline = line('.') | vert new | set bt=nofile | r # | 0d_ | diffthis | :exe "norm! ".g:diffline."G" | wincmd p | diffthis | wincmd p
  421. command! DiffOrig let g:diffline = line('.') | vert new | set bt=nofile | r # | 0d_ | diffthis | :exe 'norm! '.g:diffline.'G' | wincmd p | diffthis | wincmd p
  422. nnoremap <Leader>do :DiffOrig<cr>
  423. nnoremap <leader>dc :q<cr>:diffoff<cr>:exe "norm! ".g:diffline."G"<cr>
  424. """ End DiffOrig """ }}}
  425. """ Sudo Save Edit """ {{{
  426. "" Use :W to sudo save, may mess with permissions
  427. command! WW w !sudo tee % > /dev/null
  428. """ End Sudo Save """ }}}
  429. """ Typo Commands """ {{{
  430. "" http://blog.sanctum.geek.nz/vim-command-typos/
  431. if has("user_commands")
  432. command! -bang -nargs=? -complete=file E e<bang> <args>
  433. command! -bang -nargs=? -complete=file W w<bang> <args>
  434. command! -bang -nargs=? -complete=file Wq wq<bang> <args>
  435. command! -bang -nargs=? -complete=file WQ wq<bang> <args>
  436. command! -bang Wa wa<bang>
  437. command! -bang WA wa<bang>
  438. command! -bang Q q<bang>
  439. command! -bang QA qa<bang>
  440. command! -bang Qa qa<bang>
  441. endif
  442. """ End Typo """ }}}
  443. """ End Key Bindings """ }}}
  444. """ Notes To Self """ {{{
  445. "" Consider:
  446. " set foldopen=
  447. """ End Notes """ }}}