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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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 'WolfeCub/vim-markdown-format', { 'for': ['md', 'markdown'] }
  17. call plug#end()
  18. " }}}
  19. " Basic Configuration {{{
  20. set tabstop=4 " Show existing tab with 4 spaces width
  21. set shiftwidth=4 " When indenting with '>', use 4 spaces width
  22. set expandtab " Basic tab options
  23. set hlsearch " Highlights search options
  24. set laststatus=2 " Displays statusline by default
  25. set backspace=2 " Allows for free backspacing
  26. set incsearch " Incremental search
  27. set wildchar=<TAB> " Start wild expansion in the command line using <TAB>
  28. set wildmenu " Wild char completion menu
  29. set ignorecase " Case insensitive matching
  30. set smartcase " Smartcase matching
  31. set showmatch " Show matching brackets when text indicator is over them
  32. set splitbelow " Open new splits below
  33. set splitright " Open new splits right
  34. set shortmess=atI " No intro message
  35. set title " Show the filename in the window titlebar
  36. set scrolloff=3 " Start scrolling three lines before the horizontal window border
  37. set visualbell " Disable screen flash bells
  38. set t_vb= " Disable audio bells
  39. set nostartofline " Don’t reset cursor to start of line when moving around.
  40. set foldenable " Turn on folds
  41. set fdm=indent " Fold on syntax
  42. set foldlevel=999 " Make it really high, so they're not displayed by default
  43. set hidden " Allow buffers with pending changes to be sent to background
  44. set timeoutlen=500 ttimeoutlen=0
  45. if has('macunix')
  46. set clipboard=exclude:.* " Improve startup time by ignoring x server clipboard
  47. end
  48. " }}}
  49. " Visual Configuration {{{
  50. set relativenumber
  51. set number
  52. set lcs=trail:█
  53. set list
  54. set background=dark
  55. colorscheme jellybeans
  56. syntax enable
  57. set t_Co=256
  58. filetype on
  59. set showmatch
  60. if $TERM_PROGRAM =~ "iTerm" && has('nvim') == 0
  61. let &t_SI = "\<Esc>]50;CursorShape=1\x7" " Vertical bar in insert mode
  62. let &t_EI = "\<Esc>]50;CursorShape=0\x7" " Block in normal mode
  63. endif
  64. " }}}
  65. " Custom Keybinds {{{
  66. nnoremap <Space> <nop>
  67. let g:mapleader = "\<Space>"
  68. nnoremap <leader>vimrc :vs ~/.vimrc<cr><C-w>r
  69. " Make j and k behave like they should for wrapped lines
  70. nnoremap j gj
  71. nnoremap k gk
  72. " Fast saving
  73. nnoremap <leader>w :<C-u>update<cr>
  74. " Spellcheck
  75. noremap <leader>ss :setlocal spell!<cr>
  76. " Ctrl+A goes to the beginning of the command line
  77. cnoremap <C-A> <Home>
  78. " Ctrl+E goes to the end of the command line
  79. cnoremap <C-E> <End>
  80. " Toggle folds
  81. nnoremap <silent> <Tab> :call Foldtoggle()<cr>
  82. " Source current file
  83. nnoremap <leader>so :source %<cr>
  84. " Source current line
  85. nnoremap <leader>S ^vg_y:execute @@<cr>
  86. " Source visual selection
  87. vnoremap <leader>S y:execute @@<cr>
  88. " Remove search highlights
  89. nnoremap <leader>n :set hlsearch! hlsearch?<cr>
  90. " Buffer navigation keybinds
  91. nnoremap <leader>bb :b#<cr>
  92. nnoremap <leader>bn :bn<cr>
  93. nnoremap <leader>bp :bp<cr>
  94. nnoremap <leader>bd :bd<cr>
  95. nnoremap <leader>bl :CtrlPBuffer<cr>
  96. " }}}
  97. " Custom Configuration {{{
  98. " Use :W to sudo write file
  99. command! W w !sudo tee % > /dev/null
  100. " Command to remove trailing whitespace
  101. function! TrimWhitespace()
  102. exec "%s/\\s\\+$//e"
  103. exec "normal! \<C-o>"
  104. endfunction
  105. command! -nargs=0 TrimWhitespace :call TrimWhitespace()
  106. " Adds the :Shell command to execute a command via the shell and place the result in a buffer
  107. function! s:ExecuteInShell(command)
  108. let command = join(map(split(a:command), 'expand(v:val)'))
  109. let winnr = bufwinnr('^' . command . '$')
  110. silent! execute winnr < 0 ? 'botright new ' . fnameescape(command) : winnr . 'wincmd w'
  111. setlocal buftype=nowrite bufhidden=wipe nobuflisted noswapfile nowrap number
  112. echo 'Execute ' . command . '...'
  113. silent! execute 'silent %!'. command
  114. silent! execute 'resize ' . line('$')
  115. silent! redraw
  116. silent! execute 'au BufUnload <buffer> execute bufwinnr(' . bufnr('#') . ') . ''wincmd w'''
  117. silent! execute 'nnoremap <silent> <buffer> <LocalLeader>r :call <SID>ExecuteInShell(''' . command . ''')<CR>'
  118. echo 'Shell command ' . command . ' executed.'
  119. endfunction
  120. command! -complete=shellcmd -nargs=+ Shell call s:ExecuteInShell(<q-args>)
  121. " Hides the error message when toggling folds
  122. function! Foldtoggle()
  123. try
  124. normal! za
  125. catch /E490/
  126. endtry
  127. endfunction
  128. " }}}
  129. " Plugin Configs {{{
  130. " Keybinds for Markdown Format
  131. nnoremap <leader>h1 :MakeHeader 1<cr>
  132. nnoremap <leader>h2 :MakeHeader 2<cr>
  133. nnoremap <leader>h3 :MakeHeader 3<cr>
  134. nnoremap <leader>h4 :MakeHeader 4<cr>
  135. nnoremap <leader>h5 :MakeHeader 5<cr>
  136. nnoremap <leader>h6 :MakeHeader 6<cr>
  137. vnoremap <leader>ll :<C-u>MakeList<cr>
  138. vnoremap <leader>nl :<C-u>MakeNumberedList<cr>
  139. vnoremap <leader>cb :<C-u>FencedCodeBlock<cr>
  140. vnoremap <leader>bq :<C-u>BlockQuote<cr>
  141. nnoremap <leader>li :MakeLink n<cr>
  142. vnoremap <leader>li :<C-u>MakeLink v<cr>
  143. let g:airline_powerline_fonts = 1 " Sets the powerline font to work properly
  144. let g:airline#extensions#tabline#enabled = 1
  145. " Change default ctrlp binding
  146. let g:ctrlp_map = '<C-p>'
  147. let g:ctrlp_clear_cache_on_exit = 1
  148. " Ignores
  149. set wildignore+=*/tmp/*,*.so,*.swp,*.zip
  150. let g:ctrlp_custom_ignore = {
  151. \ 'dir': '\v[\/]\.(git|hg|svn)$',
  152. \ 'file': '\v\.(exe|so|dll)$',
  153. \ 'link': 'some_bad_symbolic_links',
  154. \ }
  155. " }}}
  156. " Temp & Testing {{{
  157. function! GetSyntaxID()
  158. return synID(line('.'), col('.'), 1)
  159. endfunction
  160. function! GetSyntaxParentID()
  161. return synIDtrans(GetSyntaxID())
  162. endfunction
  163. function! GetSyntax()
  164. echo synIDattr(GetSyntaxID(), 'name')
  165. exec "hi ".synIDattr(GetSyntaxParentID(), 'name')
  166. endfunction
  167. " }}}
  168. " Neovim Only {{{
  169. if has('nvim') == 1
  170. "Enable full color support
  171. let $NVIM_TUI_ENABLE_TRUE_COLOR=1
  172. " Change cursor shape based on current mode
  173. let $NVIM_TUI_ENABLE_CURSOR_SHAPE=1
  174. " Maps Esc to actually exit insert mode for terminal
  175. tnoremap <Esc> <C-\><C-n>
  176. endif
  177. " }}}
  178. " Modeline {{{
  179. " vim: set fdm=marker foldlevel=0:
  180. "" }}}