vimrc 17 KB

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