My personal dotfiles
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

.vimrc 9.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. " __ __ _ __ _ _
  2. " \ \ / / | |/ _| ( ) (_)
  3. " \ \ /\ / /__ | | |_ ___|/ ___ __ ___ _ __ ___ _ __ ___
  4. " \ \/ \/ / _ \| | _/ _ \ / __| \ \ / / | '_ ` _ \| '__/ __|
  5. " \ /\ / (_) | | || __/ \__ \ \ V /| | | | | | | | | (__
  6. " \/ \/ \___/|_|_| \___| |___/ (_)_/ |_|_| |_| |_|_| \___|
  7. if has('nvim') == 0
  8. set nocompatible " be iMproved, required
  9. endif
  10. " Vim Plug {{{
  11. call plug#begin('~/.vim/plugged')
  12. Plug 'vim-airline/vim-airline'
  13. Plug 'vim-airline/vim-airline-themes'
  14. Plug 'ctrlpvim/ctrlp.vim'
  15. Plug 'tpope/vim-surround'
  16. Plug 'jiangmiao/auto-pairs'
  17. Plug 'terryma/vim-expand-region'
  18. Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
  19. Plug 'tpope/vim-markdown', { 'for': ['md', 'markdown'] }
  20. Plug 'WolfeCub/vim-markdown-format', { 'for': ['md', 'markdown'] }
  21. Plug 'Shougo/neocomplete.vim'
  22. Plug 'dhruvasagar/vim-table-mode', { 'on': 'TableModeToggle' }
  23. if has('nvim') == 1
  24. Plug 'benekastah/neomake'
  25. else
  26. Plug 'scrooloose/syntastic'
  27. endif
  28. call plug#end()
  29. " }}}
  30. " Basic Configuration {{{
  31. set tabstop=4 " Show existing tab with 4 spaces width
  32. set shiftwidth=4 " When indenting with '>', use 4 spaces width
  33. set expandtab " Basic tab options
  34. set hlsearch " Highlights search options
  35. set laststatus=2 " Displays statusline by default
  36. set backspace=2 " Allows for free backspacing
  37. set incsearch " Incremental search
  38. set wildchar=<TAB> " Start wild expansion in the command line using <TAB>
  39. set wildmenu " Wild char completion menu
  40. set ignorecase " Case insensitive matching
  41. set smartcase " Smartcase matching
  42. set showmatch " Show matching brackets when text indicator is over them
  43. set splitbelow " Open new splits below
  44. set splitright " Open new splits right
  45. set shortmess=atI " No intro message
  46. set title " Show the filename in the window titlebar
  47. set scrolloff=3 " Start scrolling three lines before the horizontal window border
  48. set visualbell " Disable screen flash bells
  49. set t_vb= " Disable audio bells
  50. set nostartofline " Don’t reset cursor to start of line when moving around.
  51. set foldenable " Turn on folds
  52. set fdm=indent " Fold on syntax
  53. set foldlevel=999 " Make it really high, so they're not displayed by default
  54. set hidden " Allow buffers with pending changes to be sent to background
  55. set timeoutlen=500 ttimeoutlen=0
  56. if has('macunix')
  57. set clipboard=exclude:.* " Improve startup time by ignoring x server clipboard
  58. end
  59. " }}}
  60. " Visual Configuration {{{
  61. set relativenumber
  62. set number
  63. set lcs=trail:█
  64. set list
  65. set background=dark
  66. colorscheme jellybeans
  67. syntax enable
  68. set t_Co=256
  69. filetype on
  70. set showmatch
  71. if $TERM_PROGRAM =~ "iTerm" && has('nvim') == 0
  72. let &t_SI = "\<Esc>]50;CursorShape=1\x7" " Vertical bar in insert mode
  73. let &t_EI = "\<Esc>]50;CursorShape=0\x7" " Block in normal mode
  74. endif
  75. " }}}
  76. " Custom Keybinds {{{
  77. nnoremap <Space> <nop>
  78. let g:mapleader = "\<Space>"
  79. nnoremap <leader>vimrc :vs ~/.vimrc<cr><C-w>r
  80. " Make j and k behave like they should for wrapped lines
  81. nnoremap j gj
  82. nnoremap k gk
  83. " Fast saving
  84. nnoremap <leader>w :<C-u>update<cr>
  85. " Spellcheck
  86. noremap <leader>ss :setlocal spell!<cr>
  87. " Ctrl+A goes to the beginning of the command line
  88. cnoremap <C-A> <Home>
  89. " Ctrl+E goes to the end of the command line
  90. cnoremap <C-E> <End>
  91. " Toggle folds
  92. nnoremap <silent> <Tab> :call Foldtoggle()<cr>
  93. " Source current file
  94. nnoremap <leader>so :source %<cr>
  95. " Source current line
  96. nnoremap <leader>S ^vg_y:execute @@<cr>
  97. " Source visual selection
  98. vnoremap <leader>S y:execute @@<cr>
  99. " Remove search highlights
  100. nnoremap <leader>n :set hlsearch! hlsearch?<cr>
  101. " Buffer navigation keybinds
  102. nnoremap <leader>bb :b#<cr>
  103. nnoremap <leader>bn :bn<cr>
  104. nnoremap <leader>bp :bp<cr>
  105. nnoremap <leader>bd :bd<cr>
  106. nnoremap <leader>bl :CtrlPBuffer<cr>
  107. " }}}
  108. " Custom Configuration {{{
  109. " Use :W to sudo write file
  110. command! W w !sudo tee % > /dev/null
  111. " Command to remove trailing whitespace
  112. function! TrimWhitespace()
  113. exec "%s/\\s\\+$//e"
  114. exec "normal! \<C-o>"
  115. endfunction
  116. command! -nargs=0 TrimWhitespace :call TrimWhitespace()
  117. " Adds the :Shell command to execute a command via the shell and place the result in a buffer
  118. function! s:ExecuteInShell(command)
  119. let command = join(map(split(a:command), 'expand(v:val)'))
  120. let winnr = bufwinnr('^' . command . '$')
  121. silent! execute winnr < 0 ? 'botright new ' . fnameescape(command) : winnr . 'wincmd w'
  122. setlocal buftype=nowrite bufhidden=wipe nobuflisted noswapfile nowrap number
  123. echo 'Execute ' . command . '...'
  124. silent! execute 'silent %!'. command
  125. silent! execute 'resize ' . line('$')
  126. silent! redraw
  127. silent! execute 'au BufUnload <buffer> execute bufwinnr(' . bufnr('#') . ') . ''wincmd w'''
  128. silent! execute 'nnoremap <silent> <buffer> <LocalLeader>r :call <SID>ExecuteInShell(''' . command . ''')<CR>'
  129. echo 'Shell command ' . command . ' executed.'
  130. endfunction
  131. command! -complete=shellcmd -nargs=+ Shell call s:ExecuteInShell(<q-args>)
  132. " Hides the error message when toggling folds
  133. function! Foldtoggle()
  134. try
  135. normal! za
  136. catch /E490/
  137. endtry
  138. endfunction
  139. " }}}
  140. " Plugin Configs {{{
  141. " Keybinds for Markdown Format
  142. nnoremap <leader>h1 :MakeHeader 1<cr>
  143. nnoremap <leader>h2 :MakeHeader 2<cr>
  144. nnoremap <leader>h3 :MakeHeader 3<cr>
  145. nnoremap <leader>h4 :MakeHeader 4<cr>
  146. nnoremap <leader>h5 :MakeHeader 5<cr>
  147. nnoremap <leader>h6 :MakeHeader 6<cr>
  148. vnoremap <leader>ll :<C-u>MakeList<cr>
  149. vnoremap <leader>nl :<C-u>MakeNumberedList<cr>
  150. vnoremap <leader>cb :<C-u>FencedCodeBlock<cr>
  151. vnoremap <leader>bq :<C-u>BlockQuote<cr>
  152. nnoremap <leader>li :MakeLink n<cr>
  153. vnoremap <leader>li :<C-u>MakeLink v<cr>
  154. let g:airline_powerline_fonts = 1 " Sets the powerline font to work properly
  155. let g:airline#extensions#tabline#enabled = 1
  156. " Change default ctrlp binding
  157. let g:ctrlp_map = '<C-p>'
  158. let g:ctrlp_clear_cache_on_exit = 1
  159. " Ignores
  160. set wildignore+=*/tmp/*,*.so,*.swp,*.zip
  161. let g:ctrlp_custom_ignore = {
  162. \ 'dir': '\v[\/]\.(git|hg|svn)$',
  163. \ 'file': '\v\.(exe|so|dll)$',
  164. \ 'link': 'some_bad_symbolic_links',
  165. \ }
  166. " NERDtree Options
  167. nnoremap <C-n> :NERDTreeToggle<CR>
  168. autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
  169. if has('nvim') == 0
  170. "Set up syntastic
  171. set statusline+=%#warningmsg#
  172. set statusline+=%{SyntasticStatuslineFlag()}
  173. set statusline+=%*
  174. let g:syntastic_always_populate_loc_list = 1
  175. let g:syntastic_auto_loc_list = 1
  176. let g:syntastic_check_on_open = 1
  177. let g:syntastic_check_on_wq = 0
  178. "Have syntastic use Python 3 for syntax checking
  179. let g:syntastic_python_python_exec = '/usr/local/bin/python3'
  180. endif
  181. " Neocomplete settings
  182. " Disable AutoComplPop.
  183. let g:acp_enableAtStartup = 0
  184. " Use neocomplete.
  185. let g:neocomplete#enable_at_startup = 1
  186. " Use smartcase.
  187. let g:neocomplete#enable_smart_case = 1
  188. " Set minimum syntax keyword length.
  189. let g:neocomplete#sources#syntax#min_keyword_length = 3
  190. let g:neocomplete#lock_buffer_name_pattern = '\*ku\*'
  191. " Define dictionary.
  192. let g:neocomplete#sources#dictionary#dictionaries = {
  193. \ 'default' : '',
  194. \ 'vimshell' : $HOME.'/.vimshell_hist',
  195. \ 'scheme' : $HOME.'/.gosh_completions'
  196. \ }
  197. " Define keyword.
  198. if !exists('g:neocomplete#keyword_patterns')
  199. let g:neocomplete#keyword_patterns = {}
  200. endif
  201. let g:neocomplete#keyword_patterns['default'] = '\h\w*'
  202. " Plugin key-mappings.
  203. inoremap <expr><C-g> neocomplete#undo_completion()
  204. inoremap <expr><C-l> neocomplete#complete_common_string()
  205. " Recommended key-mappings.
  206. " <CR>: close popup and save indent.
  207. inoremap <silent> <CR> <C-r>=<SID>my_cr_function()<CR>
  208. function! s:my_cr_function()
  209. return (pumvisible() ? "\<C-y>" : "" ) . "\<CR>"
  210. " For no inserting <CR> key.
  211. "return pumvisible() ? "\<C-y>" : "\<CR>"
  212. endfunction
  213. " <TAB>: completion.
  214. inoremap <expr><TAB> pumvisible() ? "\<C-n>" : "\<TAB>"
  215. " <C-h>, <BS>: close popup and delete backword char.
  216. inoremap <expr><C-h> neocomplete#smart_close_popup()."\<C-h>"
  217. inoremap <expr><BS> neocomplete#smart_close_popup()."\<C-h>"
  218. " Close popup by <Space>.
  219. "inoremap <expr><Space> pumvisible() ? "\<C-y>" : "\<Space>"
  220. " AutoComplPop like behavior.
  221. "let g:neocomplete#enable_auto_select = 1
  222. " Enable omni completion.
  223. autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS
  224. autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags
  225. autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS
  226. autocmd FileType python setlocal omnifunc=pythoncomplete#Complete
  227. autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags
  228. " Enable heavy omni completion.
  229. if !exists('g:neocomplete#sources#omni#input_patterns')
  230. let g:neocomplete#sources#omni#input_patterns = {}
  231. endif
  232. "let g:neocomplete#sources#omni#input_patterns.php = '[^. \t]->\h\w*\|\h\w*::'
  233. "let g:neocomplete#sources#omni#input_patterns.c = '[^.[:digit:] *\t]\%(\.\|->\)'
  234. "let g:neocomplete#sources#omni#input_patterns.cpp = '[^.[:digit:] *\t]\%(\.\|->\)\|\h\w*::'
  235. " For perlomni.vim setting.
  236. " https://github.com/c9s/perlomni.vim
  237. let g:neocomplete#sources#omni#input_patterns.perl = '\h\w*->\h\w*\|\h\w*::'
  238. let g:neocomplete#enable_auto_close_preview = 1
  239. " }}}
  240. " Temp & Testing {{{
  241. function! GetSyntaxID()
  242. return synID(line('.'), col('.'), 1)
  243. endfunction
  244. function! GetSyntaxParentID()
  245. return synIDtrans(GetSyntaxID())
  246. endfunction
  247. function! GetSyntax()
  248. echo synIDattr(GetSyntaxID(), 'name')
  249. exec "hi ".synIDattr(GetSyntaxParentID(), 'name')
  250. endfunction
  251. " }}}
  252. " Neovim Only {{{
  253. if has('nvim') == 1
  254. "Enable full color support
  255. let $NVIM_TUI_ENABLE_TRUE_COLOR=1
  256. " Change cursor shape based on current mode
  257. let $NVIM_TUI_ENABLE_CURSOR_SHAPE=1
  258. " Maps Esc to actually exit insert mode for terminal
  259. tnoremap <Esc> <C-\><C-n>
  260. endif
  261. " }}}
  262. " Modeline {{{
  263. " vim: set fdm=marker foldlevel=0:
  264. "" }}}