Advertisement
Guest User

vimrc

a guest
Sep 6th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 12.91 KB | None | 0 0
  1. set nocompatible              " be iMproved, required
  2. filetype off                  " required
  3.  
  4. " set the runtime path to include Vundle and initialize
  5. set rtp+=~/.vim/bundle/Vundle.vim
  6. call vundle#begin()
  7.  
  8. " let Vundle manage Vundle, required
  9. Plugin 'VundleVim/Vundle.vim'
  10. Plugin 'artur-shaik/vim-javacomplete2'
  11. Plugin 'skywind3000/asyncrun.vim'
  12. Plugin 'kien/ctrlp.vim'
  13. Plugin 'scrooloose/nerdcommenter'
  14. Plugin 'AndrewRadev/splitjoin.vim'
  15. Plugin 'ConradIrwin/vim-bracketed-paste'
  16. Plugin 'cespare/vim-toml'
  17. Plugin 'corylanou/vim-present', {'for' : 'present'}
  18. Plugin 'ekalinin/Dockerfile.vim', {'for' : 'Dockerfile'}
  19. Plugin 'elzr/vim-json', {'for' : 'json'}
  20. Plugin 'fatih/vim-go'
  21. Plugin 'fatih/vim-hclfmt'
  22. Plugin 'fatih/vim-nginx' , {'for' : 'nginx'}
  23. Plugin 'godlygeek/tabular'
  24. Plugin 'hashivim/vim-hashicorp-tools'
  25. Plugin 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --bin' }
  26. Plugin 'junegunn/fzf.vim'
  27. Plugin 'mileszs/ack.vim'
  28. Plugin 'plasticboy/vim-markdown'
  29. Plugin 'scrooloose/nerdtree'
  30. Plugin 't9md/vim-choosewin'
  31. Plugin 'roxma/vim-tmux-clipboard'
  32. Plugin 'tmux-plugins/vim-tmux', {'for': 'tmux'}
  33. Plugin 'tmux-plugins/vim-tmux-focus-events'
  34. Plugin 'tpope/vim-commentary'
  35. Plugin 'tpope/vim-eunuch'
  36. Plugin 'tpope/vim-fugitive'
  37. Plugin 'tpope/vim-repeat'
  38. Plugin 'tpope/vim-scriptease'
  39. Plugin 'ervandew/supertab'
  40.  
  41. " All of your Plugins must be added before the following line
  42. call vundle#end()            " required
  43. filetype plugin indent on    " required
  44. "=====================================================
  45. "===================== SETTINGS ======================
  46. set encoding=utf-8              " Set default encoding to UTF-8
  47. set autoread                    " Automatically reread changed files without asking me anything
  48. set autoindent
  49. set smartindent
  50. set shiftwidth=4        " Sets indent width to be consistent with netbeans:
  51. set backspace=indent,eol,start  " Makes backspace key more powerful.
  52. set incsearch                   " Shows the match while typing
  53. set hlsearch                    " Highlight found searches
  54. set clipboard=unnamed       " Changes default clipboard to system
  55. "set mouse=a                     "Enable mouse mode
  56.  
  57. " Disables automatic comment insertion for newlines
  58. autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o
  59.  
  60. set noerrorbells             " No beeps
  61. set number                   " Show line numbers
  62. set showcmd                  " Show me what I'm typing
  63. set noswapfile               " Don't use swapfile
  64. set nobackup                 " Don't create annoying backup files
  65. set splitright               " Split vertical windows right to the current windows
  66. set splitbelow               " Split horizontal windows below to the current windows
  67. set autowrite                " Automatically save before :next, :make etc.
  68. set hidden
  69. set fileformats=unix,dos,mac " Prefer Unix over Windows over OS 9 formats
  70. set noshowmatch              " Do not show matching brackets by flickering
  71. set noshowmode               " We show the mode with airline or lightline
  72. set ignorecase               " Search case insensitive...
  73. set smartcase                " ... but not it begins with upper case
  74. set completeopt=menu,menuone
  75. set nocursorcolumn           " speed up syntax highlighting
  76. set nocursorline
  77. set updatetime=300
  78. set pumheight=10             " Completion window max size
  79. set conceallevel=2           " Concealed text is completely hidden
  80.  
  81. set shortmess+=c   " Shut off completion messages
  82. set belloff+=ctrlg " If Vim beeps during completion
  83.  
  84.  
  85. " increase max memory to show syntax highlighting for large files
  86. set maxmempattern=20000
  87.  
  88. " ~/.viminfo needs to be writable and readable. Set oldfiles to 1000 last
  89. " recently opened files, :FzfHistory uses it
  90. set viminfo='1000
  91.  
  92. if has('persistent_undo')
  93.  set undofile
  94.  set undodir=~/.cache/vim
  95. endif
  96.  
  97. " color
  98. colorscheme monokai
  99. syntax enable
  100. set background=dark
  101.  
  102. "=====================================================
  103. "===================== STATUSLINE ====================
  104. " Always show the status line
  105. set laststatus=2
  106.  
  107. let s:modes = {
  108.      \ 'n': 'NORMAL',
  109.      \ 'i': 'INSERT',
  110.      \ 'R': 'REPLACE',
  111.      \ 'v': 'VISUAL',
  112.      \ 'V': 'V-LINE',
  113.      \ "\<C-v>": 'V-BLOCK',
  114.      \ 'c': 'COMMAND',
  115.      \ 's': 'SELECT',
  116.      \ 'S': 'S-LINE',
  117.      \ "\<C-s>": 'S-BLOCK',
  118.      \ 't': 'TERMINAL'
  119.      \}
  120.  
  121. let s:prev_mode = ""
  122. function! StatusLineMode()
  123.  let cur_mode = get(s:modes, mode(), '')
  124.  
  125.  " do not update higlight if the mode is the same
  126.  if cur_mode == s:prev_mode
  127.    return cur_mode
  128.  endif
  129.  
  130.  if cur_mode == "NORMAL"
  131.    exe 'hi! StatusLine ctermfg=236'
  132.    exe 'hi! myModeColor cterm=bold ctermbg=148 ctermfg=22'
  133.  elseif cur_mode == "INSERT"
  134.    exe 'hi! myModeColor cterm=bold ctermbg=23 ctermfg=231'
  135.  elseif cur_mode == "VISUAL" || cur_mode == "V-LINE" || cur_mode == "V_BLOCK"
  136.    exe 'hi! StatusLine ctermfg=236'
  137.    exe 'hi! myModeColor cterm=bold ctermbg=208 ctermfg=88'
  138.  endif
  139.  
  140.  let s:prev_mode = cur_mode
  141.  return cur_mode
  142. endfunction
  143.  
  144. function! StatusLineFiletype()
  145.  return winwidth(0) > 70 ? (strlen(&filetype) ? &filetype : 'no ft') : ''
  146. endfunction
  147.  
  148. function! StatusLinePercent()
  149.  return (100 * line('.') / line('$')) . '%'
  150. endfunction
  151.  
  152. function! StatusLineLeftInfo()
  153. let branch = fugitive#head()
  154. let filename = '' != expand('%:t') ? expand('%:t') : '[No Name]'
  155. if branch !=# ''
  156.   return printf("%s | %s", branch, filename)
  157. endif
  158. return filename
  159. endfunction
  160.  
  161. exe 'hi! myInfoColor ctermbg=240 ctermfg=252'
  162.  
  163. " start building our statusline
  164. set statusline=
  165.  
  166. " mode with custom colors
  167. set statusline+=%#myModeColor#
  168. set statusline+=%{StatusLineMode()}
  169. set statusline+=%*
  170.  
  171. " left information bar (after mode)
  172. set statusline+=%#myInfoColor#
  173. set statusline+=\ %{StatusLineLeftInfo()}
  174. set statusline+=\ %*
  175.  
  176. " go command status (requires vim-go)
  177. set statusline+=%#goStatuslineColor#
  178. set statusline+=%{go#statusline#Show()}
  179. set statusline+=%*
  180.  
  181. " right section seperator
  182. set statusline+=%=
  183.  
  184. " filetype, percentage, line number and column number
  185. set statusline+=%#myInfoColor#
  186. set statusline+=\ %{StatusLineFiletype()}\ %{StatusLinePercent()}\ %l:%v
  187. set statusline+=\ %*
  188.  
  189. "=====================================================
  190. "===================== MAPPINGS ======================
  191.  
  192. " This comes first, because we have mappings that depend on leader
  193. " With a map leader it's possible to do extra key combinations
  194. " i.e: <leader>w saves the current file
  195. let mapleader = ","
  196.  
  197. " Some useful quickfix shortcuts for quickfix
  198. map <C-n> :cn<CR>
  199. map <C-m> :cp<CR>
  200. nnoremap <leader>a :cclose<CR>
  201.  
  202. " Fast saving
  203. nnoremap <leader>w :w!<cr>
  204. nnoremap <silent> <leader>q :q!<CR>
  205.  
  206. " Center the screen
  207. nnoremap <space> zz
  208.  
  209. " Remove search highlight
  210. nnoremap <leader><space> :nohlsearch<CR>
  211. function! s:clear_highlight()
  212.   let @/ = ""
  213.   call go#guru#ClearSameIds()
  214. endfunction
  215.  
  216.  
  217. nnoremap <silent> <leader><space> :<C-u>call <SID>clear_highlight()<CR>
  218.  
  219. " Source the current Vim file
  220. nnoremap <leader>pr :Runtime<CR>
  221.  
  222. " Close all but the current one
  223. nnoremap <leader>o :only<CR>
  224.  
  225. " Better split switching
  226. map <C-j> <C-W>j
  227. map <C-k> <C-W>k
  228. map <C-h> <C-W>h
  229. map <C-l> <C-W>l
  230.  
  231. " Print full path
  232. map <C-p> :echo expand("%:p")<cr>
  233.  
  234. " Visual linewise up and down by default (and use gj gk to go quicker)
  235. noremap <Up> gk
  236. noremap <Down> gj
  237. noremap j gj
  238. noremap k gk
  239.  
  240. " Exit on j
  241. imap jj <Esc>
  242.  
  243. " Source (reload configuration)
  244. nnoremap <silent> <F5> :source $MNVIMRC<CR>
  245.  
  246. nnoremap <F6> :setlocal spell! spell?<CR>
  247.  
  248. " Search mappings: These will make it so that going to the next one in a
  249. " search will center on the line it's found in.
  250. nnoremap n nzzzv
  251. nnoremap N Nzzzv
  252.  
  253. " Same when moving up and down
  254. noremap <C-d> <C-d>zz
  255. noremap <C-u> <C-u>zz
  256.  
  257. " Remap H and L (top, bottom of screen to left and right end of line)
  258. nnoremap H ^
  259. nnoremap L $
  260. vnoremap H ^
  261. vnoremap L g_
  262.  
  263. " Act like D and C
  264. nnoremap Y y$
  265.  
  266. " Do not show stupid q: window
  267. map q: :q
  268.  
  269. " Don't move on * I'd use a function for this but Vim clobbers the last search
  270. " when you're in a function so fuck it, practicality beats purity.
  271. nnoremap <silent> * :let stay_star_view = winsaveview()<cr>*:call winrestview(stay_star_view)<cr>
  272.  
  273. " mimic the behavior of /%Vfoobar which searches within the previously
  274. " selected visual selection
  275. " while in search mode, pressing / will do this
  276. vnoremap / <Esc>/\%><C-R>=line("'<")-1<CR>l\%<<C-R>=line("'>")+1<CR>l
  277. vnoremap ? <Esc>?\%><C-R>=line("'<")-1<CR>l\%<<C-R>=line("'>")+1<CR>l
  278.  
  279. " Time out on key codes but not mappings.
  280. " Basically this makes terminal Vim work sanely.
  281. if !has('gui_running')
  282.   set notimeout
  283.   set ttimeout
  284.   set ttimeoutlen=10
  285.   augroup FastEscape
  286.     autocmd!
  287.     au InsertEnter * set timeoutlen=0
  288.     au InsertLeave * set timeoutlen=1000
  289.   augroup END
  290. endif
  291.  
  292. " Visual Mode */# from Scrooloose {{{
  293. function! s:VSetSearch()
  294.   let temp = @@
  295.   norm! gvy
  296.   let @/ = '\V' . substitute(escape(@@, '\'), '\n', '\\n', 'g')
  297.  let @@ = temp
  298. endfunction
  299.  
  300. vnoremap * :<C-u>call <SID>VSetSearch()<CR>//<CR><c-o>
  301. vnoremap # :<C-u>call <SID>VSetSearch()<CR>??<CR><c-o>
  302.  
  303. " create a go doc comment based on the word under the cursor
  304. function! s:create_go_doc_comment()
  305.  norm "zyiw
  306.  execute ":put! z"
  307.  execute ":norm I// \<Esc>$"
  308. endfunction
  309. nnoremap <leader>ui :<C-u>call <SID>create_go_doc_comment()<CR>
  310.  
  311.  
  312. "===================== PLUGINS ======================
  313. " plugins expect bash - not fish, zsh, etc
  314. set shell=bash
  315.  
  316. " pathogen will load the other modules
  317. execute pathogen#infect()
  318.  
  319. " use goimports for formatting
  320. let g:go_fmt_command = "goimports"
  321.  
  322. " turn highlighting on
  323. let g:go_highlight_functions = 1
  324. let g:go_highlight_methods = 1
  325. let g:go_highlight_structs = 1
  326. let g:go_highlight_operators = 1
  327. let g:go_highlight_build_constraints = 1
  328.  
  329. let g:syntastic_go_checkers = ['go', 'golint', 'errcheck']
  330. let g:go_modifytags_transform = 'camelcase'
  331. let g:go_fold_enable = []
  332.  
  333. nmap <C-g> :GoDecls<cr>
  334. imap <C-g> <esc>:<C-u>GoDecls<cr>
  335.  
  336. " Open go doc in vertical window, horizontal, or tab
  337. au Filetype go nnoremap <leader>v :vsp <CR>:exe "GoDef" <CR>
  338. au Filetype go nnoremap <leader>s :sp <CR>:exe "GoDef"<CR>
  339. au Filetype go nnoremap <leader>t :tab split <CR>:exe "GoDef"<CR>
  340.  
  341. " run :GoBuild or :GoTestCompile based on the go file
  342. function! s:build_go_files()
  343.  let l:file = expand('%')
  344.  if l:file =~# '^\f\+_test\.go$'
  345.    call go#test#Test(0, 1)
  346.  elseif l:file =~# '^\f\+\.go$'
  347.    call go#cmd#Build(0)
  348.  endif
  349. endfunction
  350.  
  351. augroup go
  352.     autocmd!
  353.  
  354.  
  355.     autocmd FileType go nmap <silent> <leader>b :<C-u>call <SID>build_go_files()<CR>
  356.     autocmd FileType go nmap <silent> <leader>t  <Plug>(go-test)
  357.     autocmd FileType go nmap <silent> <leader>r  <Plug>(go-run)
  358.     autocmd FileType go nmap <silent> <leader>e  <Plug>(go-install)
  359.     " TEST FOR python TODO
  360.     " autocmd FileType py nmap <silent> <leader>r <!python %>
  361.  
  362. " we want to tell the syntastic module when to run
  363. " we want to see code highlighting and checks when  we open a file
  364. " but we don't care so much that it reruns when we close the file
  365. let g:syntastic_check_on_open = 1
  366. let g:syntastic_check_on_wq = 0
  367.  
  368. " we also want to get rid of accidental trailing whitespace on save
  369. autocmd BufWritePre * :%s/\s\+$//e
  370.  
  371. " tell vim to allow you to copy between files, remember your cursor
  372. " position and other little nice things like that
  373. set viminfo='100,\"2500,:200,%,n~/.viminfo
  374.  
  375. " ==================== Fugitive ====================
  376. vnoremap <leader>gb :Gblame<CR>
  377. nnoremap <leader>gb :Gblame<CR>
  378.  
  379.  
  380. " ==================== NerdTree ====================
  381. " For toggling
  382. noremap <Leader>n :NERDTreeToggle<cr>
  383. noremap <Leader>f :NERDTreeFind<cr>
  384.  
  385. let NERDTreeShowHidden=1
  386.  
  387. " ==================== ag ====================
  388. let g:ackprg = 'ag --vimgrep --smart-case'
  389.  
  390. " ==================== NerdCommenter ====================
  391. " Add spaces after comment delimiters by default
  392. let g:NERDSpaceDelims = 1
  393.  
  394. " Quick Run
  395. " Quick run via <F5>
  396. nnoremap <Leader>r :call <SID>compile_and_run()<CR>
  397.  
  398. function! s:compile_and_run()
  399.    exec 'w'
  400.    if &filetype == 'c'
  401.        exec "AsyncRun! gcc % -o %<; time ./%<"
  402.    elseif &filetype == 'cpp'
  403.       exec "AsyncRun! g++ -std=c++11 % -o %<; time ./%<"
  404.    elseif &filetype == 'java'
  405.       exec "AsyncRun! javac %; time java %<"
  406.    elseif &filetype == 'sh'
  407.       exec "AsyncRun! time bash %"
  408.    elseif &filetype == 'python'
  409.       exec "AsyncRun! time python %"
  410.    endif
  411. endfunction
  412.  
  413. " Deprecated:
  414. " augroup SPACEVIM_ASYNCRUN
  415. "     autocmd!
  416. "    " Automatically open the quickfix window
  417. "     autocmd User AsyncRunStart call asyncrun#quickfix_toggle(15, 1)
  418. " augroup END
  419. "
  420. " asyncrun now has an option for opening quickfix automatically
  421. let g:asyncrun_open = 15
  422.  
  423. " TRY OR DELETE!!
  424. :" Only do this part when compiled with support for autocommands.
  425. if has("autocmd")
  426. autocmd Filetype java setlocal omnifunc=javacomplete#Complete
  427. endif
  428.  
  429. setlocal omnifunc=javacomplete#Complete
  430. helptags $HOME/.vim/doc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement