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 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. " __ __ _ __ _ _
  2. " \ \ / / | |/ _| ( ) (_)
  3. " \ \ /\ / /__ | | |_ ___|/ ___ __ ___ _ __ ___ _ __ ___
  4. " \ \/ \/ / _ \| | _/ _ \ / __| \ \ / / | '_ ` _ \| '__/ __|
  5. " \ /\ / (_) | | || __/ \__ \ \ V /| | | | | | | | | (__
  6. " \/ \/ \___/|_|_| \___| |___/ (_)_/ |_|_| |_| |_|_| \___|
  7. " Vim Plug {{{
  8. call plug#begin('~/.vim/plugged')
  9. " Visual
  10. Plug 'chriskempson/base16-vim'
  11. Plug 'vim-airline/vim-airline'
  12. Plug 'vim-airline/vim-airline-themes'
  13. " Fuzzy Finding
  14. Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
  15. Plug 'junegunn/fzf.vim'
  16. " Utils
  17. Plug 'tpope/vim-surround'
  18. Plug 'tpope/vim-fugitive'
  19. Plug 'tpope/vim-repeat'
  20. Plug 'tpope/vim-rsi'
  21. Plug 'tpope/vim-scriptease'
  22. Plug 'tpope/vim-afterimage'
  23. Plug 'haya14busa/incsearch.vim'
  24. Plug 'vim-scripts/matchit.zip'
  25. Plug 'junegunn/vim-easy-align'
  26. " Completion
  27. Plug 'ervandew/supertab'
  28. Plug 'Rip-Rip/clang_complete'
  29. Plug 'davidhalter/jedi-vim'
  30. " Misc
  31. Plug 'WolfeCub/vim-markdown-format', { 'for': ['md', 'markdown'] }
  32. call plug#end()
  33. " }}}
  34. " Basic Configuration {{{
  35. set nocompatible " be iMproved, required
  36. set tabstop=4 " Show existing tab with 4 spaces width
  37. set shiftwidth=4 " When indenting with '>', use 4 spaces width
  38. set expandtab " Basic tab options
  39. set hlsearch " Highlights search options
  40. set laststatus=2 " Displays statusline by default
  41. set backspace=2 " Allows for free backspacing
  42. set incsearch " Incremental search
  43. set ignorecase " Case insensitive matching
  44. set smartcase " Smartcase matching
  45. set showmatch " Show matching brackets when text indicator is over them
  46. set splitbelow " Open new splits below
  47. set splitright " Open new splits right
  48. set shortmess=atI " No intro message
  49. set title " Show the filename in the window titlebar
  50. set scrolloff=3 " Start scrolling three lines before the horizontal window border
  51. set visualbell " Disable screen flash bells
  52. set t_vb= " Disable audio bells
  53. set nostartofline " Don’t reset cursor to start of line when moving around.
  54. set foldenable " Turn on folds
  55. set fdm=indent " Fold on syntax
  56. set foldlevel=999 " Make it really high, so they're not displayed by default
  57. set hidden " Allow buffers with pending changes to be sent to background
  58. set timeoutlen=500 ttimeoutlen=0
  59. " Completion options
  60. set wildmode=longest:list,full
  61. set wildmenu "enable ctrl-n and ctrl-p to scroll thru matches
  62. set wildignore=*.o,*.obj,*~ "stuff to ignore when tab completing
  63. set wildignore+=*vim/backups*
  64. set wildignore+=*sass-cache*
  65. set wildignore+=*DS_Store*
  66. set wildignore+=vendor/rails/**
  67. set wildignore+=vendor/cache/**
  68. set wildignore+=*.gem
  69. set wildignore+=log/**
  70. set wildignore+=tmp/**
  71. set wildignore+=*.png,*.jpg,*.gif
  72. " }}}
  73. " Visual Configuration {{{
  74. set relativenumber
  75. set number
  76. set background=dark
  77. let base16colorspace=256 " Access colors present in 256 colorspace
  78. colorscheme base16-default-dark
  79. syntax enable
  80. set t_Co=256
  81. filetype on
  82. set showmatch
  83. set cursorline
  84. hi CursorLine cterm=bold ctermbg=NONE
  85. " }}}
  86. " Custom Keybinds {{{
  87. nnoremap <Space> <nop>
  88. let g:mapleader = "\<Space>"
  89. let g:maplocalleader = "\\"
  90. " Make j and k behave like they should for wrapped lines
  91. nnoremap j gj
  92. nnoremap k gk
  93. " Quick access to vimrc file
  94. nnoremap <leader>init :e ~/.vimrc<cr>
  95. " Fast saving
  96. nnoremap <leader>w :<C-u>update<cr>
  97. " Spellcheck
  98. noremap <leader>ss :setlocal spell!<cr>
  99. " Toggle folds
  100. nnoremap <silent> <Tab> :call Foldtoggle()<cr>
  101. " Source current file
  102. nnoremap <leader>S :source %<cr>
  103. " Source visual selection
  104. vnoremap <leader>S y:execute @@<cr>
  105. " Buffer navigation keybinds
  106. nnoremap <leader>b :b#<cr>
  107. nnoremap <leader>k :bd<cr>
  108. nnoremap <leader>m :Buffers<cr>
  109. " Tab navigation
  110. nnoremap <right> :tabnext<cr>
  111. nnoremap <left> :tabprevious<cr>
  112. " Don't lose visual selection with < >
  113. xnoremap < <gv
  114. xnoremap > >gv
  115. " Better redraw. Clears search and fixes syntax
  116. nnoremap <c-l> :nohlsearch<cr>:diffupdate<cr>:syntax sync fromstart<cr><c-l>
  117. " Quickly edit macros
  118. nnoremap <leader>@ :<c-u><c-r><c-r>='let @'. v:register .' = '. string(getreg(v:register))<cr><c-f><left>
  119. " FZF ag search
  120. nnoremap <leader>f :Ag<cr>
  121. " FZF search tags file
  122. nnoremap <leader>t :Tags<cr>
  123. nnoremap <leader>T :call fzf#vim#tags(expand('<cword>'))<cr>
  124. nnoremap <localleader><localleader> :b#<cr>
  125. " }}}
  126. " Custom Configuration {{{
  127. " Use :W to sudo write file
  128. command! W w !sudo tee % > /dev/null
  129. " Command to remove trailing whitespace
  130. function! TrimWhitespace()
  131. exec "%s/\\s\\+$//e"
  132. exec "normal! \<C-o>"
  133. endfunction
  134. command! -nargs=0 TrimWhitespace :call TrimWhitespace()
  135. " Adds the :Shell command to execute a command via the shell and place the result in a buffer
  136. function! s:ExecuteInShell(command)
  137. let command = join(map(split(a:command), 'expand(v:val)'))
  138. let winnr = bufwinnr('^' . command . '$')
  139. silent! execute winnr < 0 ? 'botright new ' . fnameescape(command) : winnr . 'wincmd w'
  140. setlocal buftype=nowrite bufhidden=wipe nobuflisted noswapfile nowrap number
  141. echo 'Execute ' . command . '...'
  142. silent! execute 'silent %!'. command
  143. silent! execute 'resize ' . line('$')
  144. silent! redraw
  145. silent! execute 'au BufUnload <buffer> execute bufwinnr(' . bufnr('#') . ') . ''wincmd w'''
  146. silent! execute 'nnoremap <silent> <buffer> <LocalLeader>r :call <SID>ExecuteInShell(''' . command . ''')<CR>'
  147. echo 'Shell command ' . command . ' executed.'
  148. endfunction
  149. command! -complete=shellcmd -nargs=+ Shell call s:ExecuteInShell(<q-args>)
  150. " Hides the error message when toggling folds
  151. function! Foldtoggle()
  152. try
  153. normal! za
  154. catch /E490/
  155. endtry
  156. endfunction
  157. " }}}
  158. " Plugin Configs {{{
  159. let g:airline_powerline_fonts = 1 " Sets the powerline font to work properly
  160. let g:airline#extensions#tabline#enabled = 1
  161. " FZF Settings
  162. " Insert mode completion
  163. imap <C-x><C-k> <Plug>(fzf-complete-word)
  164. imap <C-x><C-f> <Plug>(fzf-complete-path)
  165. imap <C-x><C-j> <Plug>(fzf-complete-file-ag)
  166. imap <C-x><C-l> <Plug>(fzf-complete-line)
  167. " [Tags] Command to generate tags file
  168. let g:fzf_tags_command = 'ctags -R'
  169. " incsearch
  170. map / <Plug>(incsearch-forward)
  171. map ? <Plug>(incsearch-backward)
  172. map g/ <Plug>(incsearch-stay)
  173. " Easy Align
  174. " Start interactive EasyAlign in visual mode (e.g. vipga)
  175. xmap ga <Plug>(EasyAlign)
  176. " Start interactive EasyAlign for a motion/text object (e.g. gaip)
  177. nmap ga <Plug>(EasyAlign)
  178. " Supertab
  179. let g:SuperTabDefaultCompletionType = "<C-X><C-O>"
  180. " If you prefer the Omni-Completion tip window to close when a selection is
  181. " made, these lines close it on movement in insert mode or when leaving
  182. " insert mode
  183. autocmd CursorMovedI * if pumvisible() == 0|pclose|endif
  184. autocmd InsertLeave * if pumvisible() == 0|pclose|endif
  185. " Set clang path for completion
  186. let g:clang_library_path='/usr/lib64/libclang.so.3.9'
  187. " Keybinds for Markdown Format
  188. nnoremap <leader>h1 :MakeHeader 1<cr>
  189. nnoremap <leader>h2 :MakeHeader 2<cr>
  190. nnoremap <leader>h3 :MakeHeader 3<cr>
  191. nnoremap <leader>h4 :MakeHeader 4<cr>
  192. nnoremap <leader>h5 :MakeHeader 5<cr>
  193. nnoremap <leader>h6 :MakeHeader 6<cr>
  194. vnoremap <leader>ll :<C-u>MakeList<cr>
  195. vnoremap <leader>nl :<C-u>MakeNumberedList<cr>
  196. vnoremap <leader>cb :<C-u>FencedCodeBlock<cr>
  197. vnoremap <leader>bq :<C-u>BlockQuote<cr>
  198. nnoremap <leader>li :MakeLink n<cr>
  199. vnoremap <leader>li :<C-u>MakeLink v<cr>
  200. " }}}
  201. " Temp & Testing {{{
  202. function! GetSyntaxID()
  203. return synID(line('.'), col('.'), 1)
  204. endfunction
  205. function! GetSyntaxParentID()
  206. return synIDtrans(GetSyntaxID())
  207. endfunction
  208. function! GetSyntax()
  209. echo synIDattr(GetSyntaxID(), 'name')
  210. exec "hi ".synIDattr(GetSyntaxParentID(), 'name')
  211. endfunction
  212. " }}}
  213. " Modeline {{{
  214. " vim: set fdm=marker foldlevel=0:
  215. "" }}}