vimrc.template 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853
  1. #/root/.vimrc
  2. "
  3. " Personal preference .vimrc file
  4. "
  5. "
  6. " Use vim settings, rather then vi settings (much better!)
  7. " This must be first, because it changes other options as a side effect.
  8. set nocompatible
  9. syntax on
  10. " Change shell
  11. set shell=bash " Vim expects a POSIX-compliant shell
  12. " Change the mapleader from \ to ,
  13. let mapleader=","
  14. let maplocalleader="\\"
  15. " Editing behaviour {{{
  16. filetype indent on " load indent.vim needed for flake8 and other plugins
  17. set showmode " always show what mode we're currently editing in
  18. set nowrap " don't wrap lines
  19. set tabstop=4 " a tab is four spaces
  20. set softtabstop=4 " when hitting <BS>, pretend like a tab is removed, even if spaces
  21. set expandtab " expand tabs by default (overloadable per file type later)
  22. set shiftwidth=4 " number of spaces to use for autoindenting
  23. set shiftround " use multiple of shiftwidth when indenting with '<' and '>'
  24. set backspace=indent,eol,start " allow backspacing over everything in insert mode
  25. set autoindent " always set autoindenting on
  26. set copyindent " copy the previous indentation on autoindenting
  27. set number " always show line numbers
  28. set showmatch " set show matching parenthesis
  29. set ignorecase " ignore case when searching
  30. set smartcase " ignore case if search pattern is all lowercase,
  31. " case-sensitive otherwise
  32. set smarttab " insert tabs on the start of a line according to
  33. " shiftwidth, not tabstop
  34. set scrolloff=4 " keep 4 lines off the edges of the screen when scrolling
  35. set virtualedit=all " allow the cursor to go in to "invalid" places
  36. set hlsearch " highlight search terms
  37. set incsearch " show search matches as you type
  38. set gdefault " search/replace "globally" (on a line) by default
  39. set listchars=trail:·,precedes:«,extends:»,eol:↲,tab:▸\
  40. " set listchars=trail:\uB7,precedes:«,extends:»,eol:↲,tab:\uBB\uBB
  41. set nolist " don't show invisible characters by default,
  42. " but it is enabled for some file types (see later)
  43. set pastetoggle=<F2> " when in insert mode, press <F2> to go to
  44. " paste mode, where you can paste mass data
  45. " that won't be autoindented
  46. set mouse=a " enable using the mouse if terminal emulator
  47. " supports it (xterm does)
  48. set fileformats="unix,dos,mac"
  49. set formatoptions+=1 " When wrapping paragraphs, don't end lines
  50. " with 1-letter words (looks stupid)
  51. set nrformats= " make <C-a> and <C-x> play well with
  52. " zero-padded numbers (i.e. don't consider
  53. " them octal or hex)
  54. set shortmess+=I " hide the launch screen
  55. set clipboard=unnamed " normal OS clipboard interaction
  56. set autoread " automatically reload files changed outside of Vim
  57. " Toggle show/hide invisible chars
  58. nnoremap <leader>i :set list!<cr>
  59. " Toggle line numbers
  60. nnoremap <leader>N :setlocal number!<cr>
  61. " Thanks to Steve Losh for this liberating tip
  62. " See http://stevelosh.com/blog/2010/09/coming-home-to-vim
  63. nnoremap / /\v
  64. vnoremap / /\v
  65. " Speed up scrolling of the viewport slightly
  66. nnoremap <C-e> 2<C-e>
  67. nnoremap <C-y> 2<C-y>
  68. " }}}
  69. " Folding rules {{{
  70. set foldenable " enable folding
  71. set foldcolumn=2 " add a fold column
  72. set foldmethod=marker " detect triple-{ style fold markers
  73. set foldlevelstart=99 " start out with everything unfolded
  74. set foldopen=block,hor,insert,jump,mark,percent,quickfix,search,tag,undo
  75. " which commands trigger auto-unfold
  76. function! MyFoldText()
  77. let line = getline(v:foldstart)
  78. let nucolwidth = &fdc + &number * &numberwidth
  79. let windowwidth = winwidth(0) - nucolwidth - 3
  80. let foldedlinecount = v:foldend - v:foldstart
  81. " expand tabs into spaces
  82. let onetab = strpart(' ', 0, &tabstop)
  83. let line = substitute(line, '\t', onetab, 'g')
  84. let line = strpart(line, 0, windowwidth - 2 -len(foldedlinecount))
  85. let fillcharcount = windowwidth - len(line) - len(foldedlinecount) - 4
  86. return line . ' …' . repeat(" ",fillcharcount) . foldedlinecount . ' '
  87. endfunction
  88. set foldtext=MyFoldText()
  89. " Mappings to easily toggle fold levels
  90. nnoremap z0 :set foldlevel=0<cr>
  91. nnoremap z1 :set foldlevel=1<cr>
  92. nnoremap z2 :set foldlevel=2<cr>
  93. nnoremap z3 :set foldlevel=3<cr>
  94. nnoremap z4 :set foldlevel=4<cr>
  95. nnoremap z5 :set foldlevel=5<cr>
  96. " }}}
  97. " Editor layout {{{
  98. set termencoding=utf-8
  99. set encoding=utf-8
  100. set lazyredraw " don't update the display while executing macros
  101. set laststatus=2 " tell VIM to always put a status line in, even
  102. " if there is only one window
  103. set cmdheight=2 " use a status bar that is 2 rows high
  104. " }}}
  105. " Vim behaviour {{{
  106. set hidden " hide buffers instead of closing them this
  107. " means that the current buffer can be put
  108. " to background without being written; and
  109. " that marks and undo history are preserved
  110. set switchbuf=useopen " reveal already opened files from the
  111. " quickfix window instead of opening new
  112. " buffers
  113. set history=1000 " remember more commands and search history
  114. set undolevels=1000 " use many muchos levels of undo
  115. if v:version >= 730
  116. set undofile " keep a persistent backup file
  117. set undodir=~/.vim/.undo,~/tmp,/tmp
  118. endif
  119. set nobackup " do not keep backup files, it's 70's style cluttering
  120. set noswapfile " do not write annoying intermediate swap files,
  121. " who did ever restore from swap files anyway?
  122. set directory=~/.vim/.tmp,~/tmp,/tmp
  123. " store swap files in one of these directories
  124. " (in case swapfile is ever turned on)
  125. set viminfo='20,\"80 " read/write a .viminfo file, don't store more
  126. " than 80 lines of registers
  127. set wildmenu " make tab completion for files/buffers act like bash
  128. set wildmode=list:full " show a list when pressing tab and complete
  129. " first full match
  130. set wildignore=*.swp,*.bak,*.pyc,*.class
  131. set title " change the terminal's title
  132. set visualbell " don't beep
  133. set noerrorbells " don't beep
  134. set showcmd " show (partial) command in the last line of the screen
  135. " this also shows visual selection info
  136. set nomodeline " disable mode lines (security measure)
  137. set ttyfast " always use a fast terminal
  138. set cursorline " underline the current line, for quick orientation
  139. " }}}
  140. " Toggle the quickfix window {{{
  141. " From Steve Losh, http://learnvimscriptthehardway.stevelosh.com/chapters/38.html
  142. nnoremap <C-q> :call <SID>QuickfixToggle()<cr>
  143. let g:quickfix_is_open = 0
  144. function! s:QuickfixToggle()
  145. if g:quickfix_is_open
  146. cclose
  147. let g:quickfix_is_open = 0
  148. execute g:quickfix_return_to_window . "wincmd w"
  149. else
  150. let g:quickfix_return_to_window = winnr()
  151. copen
  152. let g:quickfix_is_open = 1
  153. endif
  154. endfunction
  155. " }}}
  156. " Toggle the foldcolumn {{{
  157. nnoremap <leader>f :call FoldColumnToggle()<cr>
  158. let g:last_fold_column_width = 4 " Pick a sane default for the foldcolumn
  159. function! FoldColumnToggle()
  160. if &foldcolumn
  161. let g:last_fold_column_width = &foldcolumn
  162. setlocal foldcolumn=0
  163. else
  164. let &l:foldcolumn = g:last_fold_column_width
  165. endif
  166. endfunction
  167. " }}}
  168. " Highlighting {{{
  169. if &t_Co > 2 || has("gui_running")
  170. syntax on " switch syntax highlighting on, when the terminal has colors
  171. endif
  172. " }}}
  173. " Shortcut mappings {{{
  174. " Since I never use the ; key anyway, this is a real optimization for almost
  175. " all Vim commands, as I don't have to press the Shift key to form chords to
  176. " enter ex mode.
  177. nnoremap ; :
  178. nnoremap <leader>; ;
  179. " Avoid accidental hits of <F1> while aiming for <Esc>
  180. noremap! <F1> <Esc>
  181. nnoremap <leader>Q :q<CR> " Quickly close the current window
  182. nnoremap <leader>q :bd<CR> " Quickly close the current buffer
  183. " Use Q for formatting the current paragraph (or visual selection)
  184. vnoremap Q gq
  185. nnoremap Q gqap
  186. " set breakindent on " keep paragraph indentation when re-wrapping text
  187. " Sort paragraphs
  188. vnoremap <leader>s !sort -f<CR>gv
  189. nnoremap <leader>s vip!sort -f<CR><Esc>
  190. " make p in Visual mode replace the selected text with the yank register
  191. vnoremap p <Esc>:let current_reg = @"<CR>gvdi<C-R>=current_reg<CR><Esc>
  192. " Shortcut to make
  193. nnoremap mk :make<CR>
  194. " Swap implementations of ` and ' jump to markers
  195. " By default, ' jumps to the marked line, ` jumps to the marked line and
  196. " column, so swap them
  197. nnoremap ' `
  198. nnoremap ` '
  199. " Use the damn hjkl keys
  200. " noremap <up> <nop>
  201. " noremap <down> <nop>
  202. " noremap <left> <nop>
  203. " noremap <right> <nop>
  204. " Remap j and k to act as expected when used on long, wrapped, lines
  205. nnoremap j gj
  206. nnoremap k gk
  207. " Easy window navigation
  208. noremap <C-h> <C-w>h
  209. noremap <C-j> <C-w>j
  210. noremap <C-k> <C-w>k
  211. noremap <C-l> <C-w>l
  212. " nnoremap <leader>w <C-w>v<C-w>l
  213. " Complete whole filenames/lines with a quicker shortcut key in insert mode
  214. inoremap <C-f> <C-x><C-f>
  215. inoremap <C-l> <C-x><C-l>
  216. " Use ,d (or ,dd or ,dj or 20,dd) to delete a line without adding it to the
  217. " yanked stack (also, in visual mode)
  218. nnoremap <silent> <leader>d "_d
  219. vnoremap <silent> <leader>d "_d
  220. " vnoremap <silent> x "_x TODODODOOo
  221. " Quick yanking to the end of the line
  222. nnoremap Y y$
  223. " YankRing stuff
  224. let g:yankring_history_dir = '$HOME/.vim/.tmp'
  225. nnoremap <leader>r :YRShow<CR>
  226. " Edit the vimrc file
  227. nnoremap <silent> <leader>ev :e $MYVIMRC<CR>
  228. nnoremap <silent> <leader>sv :so $MYVIMRC<CR>
  229. " Clears the search register
  230. nnoremap <silent> <leader>/ :nohlsearch<CR>
  231. " Pull word under cursor into LHS of a substitute (for quick search and
  232. " replace)
  233. nnoremap <leader>z :%s#\<<C-r>=expand("<cword>")<CR>\>#
  234. " Keep search matches in the middle of the window and pulse the line when moving
  235. " to them.
  236. nnoremap n n:call PulseCursorLine()<cr>
  237. nnoremap N N:call PulseCursorLine()<cr>
  238. " Quickly get out of insert mode without your fingers having to leave the
  239. " home row (either use 'jj' or 'jk')
  240. inoremap jj <Esc>
  241. " Quick alignment of text
  242. nnoremap <leader>al :left<CR>
  243. nnoremap <leader>ar :right<CR>
  244. nnoremap <leader>ac :center<CR>
  245. " Sudo to write
  246. cnoremap w!! w !sudo tee % >/dev/null
  247. " Ctrl+W to redraw
  248. nnoremap <C-w> :redraw!<cr>
  249. " Jump to matching pairs easily, with Tab
  250. nnoremap <Tab> %
  251. vnoremap <Tab> %
  252. " Folding
  253. nnoremap <Space> za
  254. vnoremap <Space> za
  255. " Strip all trailing whitespace from a file, using ,W
  256. nnoremap <leader>W :%s/\s\+$//<CR>:let @/=''<CR>
  257. " Use The Silver Searcher over grep, iff possible
  258. if executable('ag')
  259. " Use ag over grep
  260. set grepprg=ag\ --nogroup\ --nocolor
  261. " Use ag in CtrlP for listing files. Lightning fast and respects .gitignore
  262. let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""'
  263. " ag is fast enough that CtrlP doesn't need to cache
  264. let g:ctrlp_use_caching = 0
  265. endif
  266. " grep/Ack/Ag for the word under cursor
  267. " vnoremap <leader>a y:grep! "\b<c-r>"\b"<cr>:cw<cr>
  268. " nnoremap <leader>a :grep! "\b<c-r><c-w>\b"
  269. vnoremap <leader>a y:Ag <c-r><cr>:cw<cr>
  270. nnoremap <leader>a :Ag <c-r><c-w>
  271. nnoremap K *N:grep! "\b<c-r><c-w>\b"<cr>:cw<cr>
  272. " Allow quick additions to the spelling dict
  273. nnoremap <leader>g :spellgood <c-r><c-w>
  274. " Define "Ag" command
  275. command -nargs=+ -complete=file -bar Ag silent! grep! <args> | cwindow | redraw!
  276. " bind \ (backward slash) to grep shortcut
  277. nnoremap \ :Ag<SPACE>
  278. " Creating folds for tags in HTML
  279. "nnoremap <leader>ft Vatzf
  280. " Reselect text that was just pasted with ,v
  281. nnoremap <leader>v V`]
  282. " }}}
  283. " NERDTree settings {{{
  284. nnoremap <leader>n :NERDTreeFocus<CR>
  285. nnoremap <leader>m :NERDTreeClose<CR>:NERDTreeFind<CR>
  286. nnoremap <leader>N :NERDTreeClose<CR>
  287. " Store the bookmarks file
  288. let NERDTreeBookmarksFile=expand("$HOME/.vim/NERDTreeBookmarks")
  289. " Show the bookmarks table on startup
  290. let NERDTreeShowBookmarks=1
  291. " Show hidden files, too
  292. let NERDTreeShowFiles=1
  293. let NERDTreeShowHidden=1
  294. " Quit on opening files from the tree
  295. let NERDTreeQuitOnOpen=1
  296. " Highlight the selected entry in the tree
  297. let NERDTreeHighlightCursorline=1
  298. " Use a single click to fold/unfold directories and a double click to open
  299. " files
  300. let NERDTreeMouseMode=2
  301. " Don't display these kinds of files
  302. let NERDTreeIgnore=[ '\.pyc$', '\.pyo$', '\.py\$class$', '\.obj$',
  303. \ '\.o$', '\.so$', '\.egg$', '^\.git$', '__pycache__', '\.DS_Store' ]
  304. " }}}
  305. " vim-flake8 default configuration
  306. let g:flake8_show_in_gutter=1
  307. " vim-airline enable
  308. let g:airline_powerline_fonts = 1
  309. if !exists('g:airline_symbols')
  310. let g:airline_symbols = {}
  311. endif
  312. " unicode symbols
  313. let g:airline_left_sep = '»'
  314. let g:airline_left_sep = '▶'
  315. let g:airline_right_sep = '«'
  316. let g:airline_right_sep = '◀'
  317. let g:airline_symbols.linenr = '␊'
  318. let g:airline_symbols.linenr = '␤'
  319. let g:airline_symbols.linenr = '¶'
  320. let g:airline_symbols.branch = '⎇'
  321. let g:airline_symbols.paste = 'ρ'
  322. let g:airline_symbols.paste = 'Þ'
  323. let g:airline_symbols.paste = '∥'
  324. let g:airline_symbols.whitespace = 'Ξ'
  325. " airline symbols
  326. let g:airline_left_sep = ''
  327. let g:airline_left_alt_sep = ''
  328. let g:airline_right_sep = ''
  329. let g:airline_right_alt_sep = ''
  330. let g:airline_symbols.branch = ''
  331. let g:airline_symbols.readonly = ''
  332. let g:airline_symbols.linenr = ''
  333. " Conflict markers {{{
  334. " highlight conflict markers
  335. match ErrorMsg '^\(<\|=\|>\)\{7\}\([^=].\+\)\?$'
  336. " shortcut to jump to next conflict marker
  337. nnoremap <silent> <leader>c /^\(<\\|=\\|>\)\{7\}\([^=].\+\)\?$<CR>
  338. " }}}
  339. " Filetype specific handling {{{
  340. " only do this part when compiled with support for autocommands
  341. if has("autocmd")
  342. augroup invisible_chars "{{{
  343. au!
  344. " Show invisible characters in all of these files
  345. autocmd filetype vim setlocal list
  346. autocmd filetype python,rst setlocal list
  347. autocmd filetype ruby setlocal list
  348. autocmd filetype javascript,css setlocal list
  349. augroup end "}}}
  350. augroup vim_files "{{{
  351. au!
  352. " Bind <F1> to show the keyword under cursor
  353. " general help can still be entered manually, with :h
  354. autocmd filetype vim noremap <buffer> <F1> <Esc>:help <C-r><C-w><CR>
  355. autocmd filetype vim noremap! <buffer> <F1> <Esc>:help <C-r><C-w><CR>
  356. augroup end "}}}
  357. augroup html_files "{{{
  358. au!
  359. " This function detects, based on HTML content, whether this is a
  360. " Django template, or a plain HTML file, and sets filetype accordingly
  361. fun! s:DetectHTMLVariant()
  362. let n = 1
  363. while n < 50 && n < line("$")
  364. " check for django
  365. if getline(n) =~ '{%\s*\(extends\|load\|block\|if\|for\|include\|trans\)\>'
  366. set ft=htmldjango.html
  367. return
  368. endif
  369. let n = n + 1
  370. endwhile
  371. " go with html
  372. set ft=html
  373. endfun
  374. " Auto-tidy selection
  375. vnoremap <leader>x :!tidy -q -i --show-errors 0 --show-body-only 1 --wrap 0<cr><cr>
  376. autocmd BufNewFile,BufRead *.html,*.htm,*.j2 call s:DetectHTMLVariant()
  377. " Auto-closing of HTML/XML tags
  378. let g:closetag_default_xml=1
  379. autocmd filetype html,htmldjango let b:closetag_html_style=1
  380. autocmd filetype html,xhtml,xml source ~/.vim/scripts/closetag.vim
  381. augroup end " }}}
  382. augroup python_files "{{{
  383. au!
  384. " This function detects, based on Python content, whether this is a
  385. " Django file, which may enabling snippet completion for it
  386. fun! s:DetectPythonVariant()
  387. let n = 1
  388. while n < 50 && n < line("$")
  389. " check for django
  390. if getline(n) =~ 'import\s\+\<django\>' || getline(n) =~ 'from\s\+\<django\>\s\+import'
  391. set ft=python.django
  392. "set syntax=python
  393. return
  394. endif
  395. let n = n + 1
  396. endwhile
  397. " go with html
  398. set ft=python
  399. endfun
  400. autocmd BufNewFile,BufRead *.py call s:DetectPythonVariant()
  401. " PEP8 compliance (set 1 tab = 4 chars explicitly, even if set
  402. " earlier, as it is important)
  403. autocmd filetype python setlocal textwidth=78
  404. autocmd filetype python match ErrorMsg '\%>120v.\+'
  405. " But disable autowrapping as it is super annoying
  406. autocmd filetype python setlocal formatoptions-=t
  407. " Folding for Python (uses syntax/python.vim for fold definitions)
  408. "autocmd filetype python,rst setlocal nofoldenable
  409. "autocmd filetype python setlocal foldmethod=expr
  410. " Python runners
  411. autocmd filetype python noremap <buffer> <F5> :w<CR>:!python %<CR>
  412. autocmd filetype python inoremap <buffer> <F5> <Esc>:w<CR>:!python %<CR>
  413. autocmd filetype python noremap <buffer> <S-F5> :w<CR>:!ipython %<CR>
  414. autocmd filetype python inoremap <buffer> <S-F5> <Esc>:w<CR>:!ipython %<CR>
  415. " Automatic insertion of breakpoints
  416. autocmd filetype python nnoremap <buffer> <leader>bp :normal oimport pdb; pdb.set_trace() # TODO: BREAKPOINT # noqa<Esc>
  417. " Toggling True/False
  418. autocmd filetype python nnoremap <silent> <C-t> mmviw:s/True\\|False/\={'True':'False','False':'True'}[submatch(0)]/<CR>`m:nohlsearch<CR>
  419. " Run a quick static syntax check every time we save a Python file
  420. autocmd BufWritePost *.py call Flake8()
  421. " Defer to isort for sorting Python imports (instead of using Unix sort)
  422. autocmd filetype python nnoremap <leader>s mX:%!isort -<cr>`X:redraw!<cr>
  423. augroup end " }}}
  424. augroup js_files "{{{
  425. " Defer to import-sort for sorting JavaScript imports (instead of using Unix sort)
  426. autocmd filetype javascript nnoremap <leader>s :write<cr>mX:!import-sort --overwrite %<cr>:edit!<cr>`X
  427. augroup end " }}}
  428. augroup clojure_files "{{{
  429. au!
  430. " Set up <leader>r to run the entire file with vim-fireplace
  431. autocmd filetype clojure nnoremap <leader>r :%Eval<cr>
  432. autocmd filetype clojure RainbowParenthesesActivate
  433. autocmd filetype clojure RainbowParenthesesLoadRound
  434. autocmd filetype clojure RainbowParenthesesLoadSquare
  435. autocmd filetype clojure RainbowParenthesesLoadBraces
  436. augroup end " }}}
  437. augroup supervisord_files "{{{
  438. au!
  439. autocmd BufNewFile,BufRead supervisord.conf set ft=dosini
  440. augroup end " }}}
  441. augroup markdown_files "{{{
  442. au!
  443. autocmd filetype markdown noremap <buffer> <leader>p :w<CR>:!open -a 'Marked 2' %<CR><CR>
  444. augroup end " }}}
  445. augroup ruby_files "{{{
  446. au!
  447. augroup end " }}}
  448. augroup rst_files "{{{
  449. au!
  450. " Auto-wrap text around 74 chars
  451. autocmd filetype rst setlocal textwidth=74
  452. autocmd filetype rst setlocal formatoptions+=nqt
  453. autocmd filetype rst match ErrorMsg '\%>74v.\+'
  454. augroup end " }}}
  455. augroup css_files "{{{
  456. au!
  457. autocmd filetype css,less setlocal foldmethod=marker foldmarker={,}
  458. augroup end "}}}
  459. augroup javascript_files "{{{
  460. au!
  461. autocmd filetype javascript setlocal expandtab
  462. autocmd filetype javascript setlocal listchars=trail:·,extends:#,nbsp:·
  463. autocmd filetype javascript setlocal foldmethod=marker foldmarker={,}
  464. " Toggling True/False
  465. autocmd filetype javascript nnoremap <silent> <C-t> mmviw:s/true\\|false/\={'true':'false','false':'true'}[submatch(0)]/<CR>`m:nohlsearch<CR>
  466. " Enable insertion of "debugger" statement in JS files
  467. autocmd filetype javascript nnoremap <leader>b Odebugger;<esc>
  468. " Use prettier to format JS files
  469. autocmd FileType javascript set formatprg=bin/prettier-stdin
  470. autocmd BufWritePre *.js,*.jsx Neoformat
  471. augroup end "}}}
  472. augroup textile_files "{{{
  473. au!
  474. autocmd filetype textile set tw=78 wrap
  475. " Render YAML front matter inside Textile documents as comments
  476. autocmd filetype textile syntax region frontmatter start=/\%^---$/ end=/^---$/
  477. autocmd filetype textile highlight link frontmatter Comment
  478. augroup end "}}}
  479. augroup git_files "{{{
  480. au!
  481. " Don't remember the last cursor position when editing commit
  482. " messages, always start on line 1
  483. autocmd filetype gitcommit call setpos('.', [0, 1, 1, 0])
  484. augroup end "}}}
  485. endif
  486. " }}}
  487. " Skeleton processing {{{
  488. if has("autocmd")
  489. "if !exists('*LoadTemplate')
  490. "function LoadTemplate(file)
  491. "" Add skeleton fillings for Python (normal and unittest) files
  492. "if a:file =~ 'test_.*\.py$'
  493. "execute "0r ~/.vim/skeleton/test_template.py"
  494. "elseif a:file =~ '.*\.py$'
  495. "execute "0r ~/.vim/skeleton/template.py"
  496. "endif
  497. "endfunction
  498. "endif
  499. "autocmd BufNewFile * call LoadTemplate(@%)
  500. endif " has("autocmd")
  501. " }}}
  502. " Restore cursor position upon reopening files {{{
  503. autocmd BufReadPost *
  504. \ if &filetype != "gitcommit" && line("'\"") > 0 && line("'\"") <= line("$") |
  505. \ exe "normal! g`\"" |
  506. \ endif
  507. " }}}
  508. " Common abbreviations / misspellings {{{
  509. "source ~/.vim/autocorrect.vim
  510. " }}}
  511. " Extra vi-compatibility {{{
  512. " set extra vi-compatible options
  513. set cpoptions+=$ " when changing a line, don't redisplay, but put a '$' at
  514. " the end during the change
  515. set formatoptions-=o " don't start new lines w/ comment leader on pressing 'o'
  516. au filetype vim set formatoptions-=o
  517. " somehow, during vim filetype detection, this gets set
  518. " for vim files, so explicitly unset it again
  519. " }}}
  520. " Extra user or machine specific settings {{{
  521. "source ~/.vim/user.vim
  522. " }}}
  523. "set guifont=Anonymous\ for\ Powerline:h12 linespace=2
  524. "set guifont=Droid\ Sans\ Mono:h14 linespace=0
  525. "set guifont=Mensch\ for\ Powerline:h14 linespace=0
  526. "set guifont=saxMono:h14 linespace=3
  527. "set guifont=Ubuntu\ Mono:h18 linespace=3
  528. "set guifont=Source\ Code\ Pro\ Light:h10 linespace=0
  529. "if has("gui_running")
  530. " Remove toolbar, left scrollbar and right scrollbar
  531. " set guioptions-=T
  532. " set guioptions-=l
  533. " set guioptions-=L
  534. " set guioptions-=r
  535. " set guioptions-=R
  536. " set guifont=Source\ Code\ Pro\ Light:h13 linespace=0
  537. "else
  538. " set bg=dark
  539. "endif
  540. colorscheme molokai
  541. "colorscheme mustang
  542. "colorscheme mustang_silent
  543. "colorscheme wombat256
  544. "colorscheme jellybeans
  545. "colorscheme onedark
  546. " Pulse ------------------------------------------------------------------- {{{
  547. function! PulseCursorLine()
  548. let current_window = winnr()
  549. windo set nocursorline
  550. execute current_window . 'wincmd w'
  551. setlocal cursorline
  552. redir => old_hi
  553. silent execute 'hi CursorLine'
  554. redir END
  555. let old_hi = split(old_hi, '\n')[0]
  556. let old_hi = substitute(old_hi, 'xxx', '', '')
  557. hi CursorLine guibg=#3a3a3a
  558. redraw
  559. sleep 20m
  560. hi CursorLine guibg=#4a4a4a
  561. redraw
  562. sleep 30m
  563. hi CursorLine guibg=#3a3a3a
  564. redraw
  565. sleep 30m
  566. hi CursorLine guibg=#2a2a2a
  567. redraw
  568. sleep 20m
  569. execute 'hi ' . old_hi
  570. windo set cursorline
  571. execute current_window . 'wincmd w'
  572. endfunction
  573. " }}}
  574. " Powerline configuration ------------------------------------------------- {{{
  575. let g:Powerline_symbols = 'compatible'
  576. "let g:Powerline_symbols = 'fancy'
  577. " }}}
  578. " Python mode configuration ----------------------------------------------- {{{
  579. " Don't run pylint on every save
  580. let g:pymode = 1
  581. let g:pymode_breakpoint = 0
  582. let g:pymode_breakpoint_bind = '<leader>b'
  583. let g:pymode_doc = 0
  584. let g:pymode_doc_bind = 'K'
  585. let g:pymode_folding = 0
  586. let g:pymode_indent = 0
  587. let g:pymode_lint = 0
  588. let g:pymode_lint_checkers = ['pyflakes', 'pep8', 'mccabe']
  589. let g:pymode_lint_cwindow = 1
  590. let g:pymode_lint_ignore = ''
  591. let g:pymode_lint_message = 1
  592. let g:pymode_lint_on_fly = 0
  593. let g:pymode_lint_on_write = 0
  594. let g:pymode_lint_select = ''
  595. let g:pymode_lint_signs = 1
  596. let g:pymode_motion = 0
  597. let g:pymode_options = 0
  598. let g:pymode_paths = []
  599. let g:pymode_quickfix_maxheight = 6
  600. let g:pymode_quickfix_minheight = 3
  601. let g:pymode_rope = 1
  602. let g:pymode_rope_completion = 0
  603. let g:pymode_rope_regenerate_on_write = 0
  604. let g:pymode_run = 0
  605. let g:pymode_run_bind = '<leader>r'
  606. let g:pymode_trim_whitespaces = 0
  607. " }}}
  608. " Ignore common directories
  609. let g:ctrlp_custom_ignore = {
  610. \ 'dir': 'node_modules\|bower_components',
  611. \ }
  612. " Invoke CtrlP, but CommandT style
  613. nnoremap <leader>t :CtrlP<cr>
  614. nnoremap <leader>. :CtrlPTag<cr>
  615. nnoremap <leader>b :CtrlPBuffer<cr>
  616. " Learn Vim Script the Hard Way Exercises
  617. noremap - ddp
  618. noremap _ ddkP
  619. " C-U in insert/normal mode, to uppercase the word under cursor
  620. inoremap <c-u> <esc>viwUea
  621. nnoremap <c-u> viwUe
  622. " Quote words under cursor
  623. nnoremap <leader>" viW<esc>a"<esc>gvo<esc>i"<esc>gvo<esc>3l
  624. nnoremap <leader>' viW<esc>a'<esc>gvo<esc>i'<esc>gvo<esc>3l
  625. " Quote current selection
  626. " TODO: This only works for selections that are created "forwardly"
  627. vnoremap <leader>" <esc>a"<esc>gvo<esc>i"<esc>gvo<esc>ll
  628. vnoremap <leader>' <esc>a'<esc>gvo<esc>i'<esc>gvo<esc>ll
  629. " Use shift-H and shift-L for move to beginning/end
  630. nnoremap H 0
  631. nnoremap L $
  632. " Define operator-pending mappings to quickly apply commands to function names
  633. " and/or parameter lists in the current line
  634. onoremap inf :<c-u>normal! 0f(hviw<cr>
  635. onoremap anf :<c-u>normal! 0f(hvaw<cr>
  636. onoremap in( :<c-u>normal! 0f(vi(<cr>
  637. onoremap an( :<c-u>normal! 0f(va(<cr>
  638. " "Next" tag
  639. onoremap int :<c-u>normal! 0f<vit<cr>
  640. onoremap ant :<c-u>normal! 0f<vat<cr>
  641. " Function argument selection (change "around argument", change "inside argument")
  642. onoremap ia :<c-u>execute "normal! ?[,(]\rwv/[),]\rh"<cr>
  643. vnoremap ia :<c-u>execute "normal! ?[,(]\rwv/[),]\rh"<cr>
  644. " Split previously opened file ('#') in a split window
  645. nnoremap <leader>sh :execute "leftabove vsplit" bufname('#')<cr>
  646. nnoremap <leader>sl :execute "rightbelow vsplit" bufname('#')<cr>
  647. " Grep searches
  648. "nnoremap <leader>g :silent execute "grep! -R " . shellescape('<cword>') . " ."<cr>:copen 12<cr>
  649. "nnoremap <leader>G :silent execute "grep! -R " . shellescape('<cWORD>') . " ."<cr>:copen 12<cr>
  650. " Rope config
  651. nnoremap <leader>A :RopeAutoImport<cr>
  652. " Switch from block-cursor to vertical-line-cursor when going into/out of
  653. " insert mode
  654. let &t_SI = "\<Esc>]50;CursorShape=1\x7"
  655. let &t_EI = "\<Esc>]50;CursorShape=0\x7"
  656. " Configure vim-expand-region, for easy selection precision
  657. vmap v <Plug>(expand_region_expand)
  658. vmap <C-v> <Plug>(expand_region_shrink)
  659. " Configure ArgWrap
  660. let g:argwrap_tail_comma = 1
  661. nnoremap <leader>w :ArgWrap<cr>
  662. " Default settings. (NOTE: Remove comments in dictionary before sourcing)
  663. let g:expand_region_text_objects = {
  664. \ 'iw' :0,
  665. \ 'i"' :0,
  666. \ 'i''' :0,
  667. \ 'a"' :0,
  668. \ 'a''' :0,
  669. \ 'i)' :1,
  670. \ 'i}' :1,
  671. \ 'i]' :1,
  672. \ 'a)' :1,
  673. \ 'a}' :1,
  674. \ 'a]' :1,
  675. \ }
  676. " HTML specific region expansions
  677. " call expand_region#custom_text_objects('html', {
  678. " \ 'it': 1,
  679. " \ 'at': 1,
  680. " \ })