init.vim 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. " ########## General ########## {{{
  2. syntax on
  3. colorscheme elflord
  4. let g:airline_theme='atomic'
  5. set encoding=utf-8
  6. set fileencoding=utf-8
  7. set wildmenu
  8. set autoindent
  9. set smartindent
  10. set incsearch
  11. set hlsearch
  12. set smarttab
  13. set ignorecase
  14. set smartcase
  15. set number relativenumber
  16. set so=7
  17. set tabstop=4 shiftwidth=4
  18. set expandtab
  19. let mapleader = ","
  20. let maplocalleader = "\\"
  21. " }}}
  22. " ########## Highlighting ########## {{{
  23. highlight ExtraWhitespace ctermbg=red guibg=red
  24. match ExtraWhitespace /\s\+$/
  25. augroup trailingwhitespace
  26. autocmd!
  27. autocmd Syntax * syn match ExtraWhitespace /\s\+$\| \+\ze\t/
  28. augroup END
  29. " Tabs
  30. set list
  31. set listchars=tab:\|\ ,
  32. " }}}
  33. " ########## Keybinds ########## {{{
  34. nnoremap <leader>ev :vsplit $MYVIMRC<cr>
  35. nnoremap <leader>sv :source $MYVIMRC<cr>
  36. nnoremap <leader>f :FZF<cr>
  37. nnoremap <leader>gs :Gstatus<cr>
  38. nnoremap <leader>gc :Gcommit<cr>
  39. nnoremap <leader>gr :Git rebase -i
  40. noremap <leader>c :w! \| !compiler <c-r>%<CR><CR>
  41. noremap <leader>p :!opout <c-r>%<CR><CR>
  42. nnoremap <leader>u :!ctags -R .<CR>
  43. nnoremap <esc> :set nohlsearch<CR>
  44. tnoremap <Esc> <C-\><C-n>
  45. " Local (scope) replace
  46. nnoremap gr gd[{V%::s/<C-R>///gc<left><left><left>
  47. " Global replace
  48. nnoremap gR gD:%s/<C-R>///gc<left><left><left>
  49. nnoremap Y y$
  50. nnoremap H ^
  51. nnoremap L $
  52. vnoremap H ^
  53. vnoremap L $
  54. inoremap jk <esc>
  55. inoremap <esc> <nop>
  56. inoremap <Left> <nop>
  57. inoremap <Right> <nop>
  58. inoremap <Up> <nop>
  59. inoremap <Down> <nop>
  60. " Dragvisuals keybinds
  61. vmap <expr> <LEFT> DVB_Drag('left')
  62. vmap <expr> <RIGHT> DVB_Drag('right')
  63. vmap <expr> <DOWN> DVB_Drag('down')
  64. vmap <expr> <UP> DVB_Drag('up')
  65. vmap <expr> D DVB_Duplicate()
  66. " Remove any introduced trailing whitespace after moving...
  67. let g:DVB_TrimWS = 1
  68. " }}}
  69. " ########## Abbreviations ########## {{{
  70. iabbrev ret return
  71. iabbrev @@ frans@tankernn.eu
  72. iabbrev ssig -- <cr>Frans Bergman<cr>frans@tankernn.eu
  73. " }}}
  74. " ########## File-specific settings ########## {{{
  75. autocmd FileType gitcommit,groff :set spell
  76. autocmd FileType vim :set foldmethod=marker
  77. autocmd BufNewFile,BufRead *.ms,*.me,*.mom,*.man set filetype=groff
  78. " }}}
  79. " ########## Plugins ########## {{{
  80. call plug#begin()
  81. Plug 'tpope/vim-fugitive'
  82. Plug 'bling/vim-airline'
  83. Plug 'vim-airline/vim-airline-themes'
  84. Plug 'mkitt/tabline.vim'
  85. Plug 'tpope/vim-surround'
  86. Plug 'tpope/vim-repeat'
  87. Plug 'raimondi/delimitmate'
  88. Plug 'fisadev/dragvisuals.vim'
  89. Plug 'dense-analysis/ale'
  90. Plug 'maralla/completor.vim'
  91. Plug 'artur-shaik/vim-javacomplete2'
  92. Plug 'junegunn/fzf'
  93. Plug 'Chiel92/vim-autoformat'
  94. Plug 'preservim/nerdtree'
  95. call plug#end()
  96. " }}}
  97. " ########## Plugin Settings ########## {{{
  98. let g:ale_linters = {'rust': ['rls', 'rustc']}
  99. nmap <leader>an <Plug>(ale_next)
  100. nmap <leader>ap <Plug>(ale_previous)
  101. let g:completor_filetype_map = {}
  102. " Enable lsp for rust by using rls
  103. let g:completor_filetype_map.rust = {'ft': 'lsp', 'cmd': 'rls-1.37.0'}
  104. augroup rust
  105. autocmd!
  106. autocmd FileType rust au BufWrite * :Autoformat
  107. autocmd FileType rust let b:delimitMate_smart_quotes='\%(\w\|[^[:punct:][:space:]]\|\%(\\\\\)*\\\)\%#\|\%#\%(\w\|[^[:space:][:punct:]]\)\|\<\%#\|\&\%#'
  108. augroup END
  109. augroup java
  110. autocmd!
  111. autocmd FileType java setlocal omnifunc=javacomplete#Complete
  112. augroup END
  113. " Use TAB to complete when typing words, else inserts TABs as usual. Uses
  114. " dictionary, source files, and completor to find matching words to complete.
  115. " Note: usual completion is on <C-n> but more trouble to press all the time.
  116. " Never type the same word twice and maybe learn a new spellings!
  117. " Use the Linux dictionary when spelling is in doubt.
  118. function! Tab_Or_Complete() abort
  119. " If completor is already open the `tab` cycles through suggested completions.
  120. if pumvisible()
  121. return "\<C-N>"
  122. " If completor is not open and we are in the middle of typing a word then
  123. " `tab` opens completor menu.
  124. elseif col('.')>1 && strpart( getline('.'), col('.')-2, 3 ) =~ '^[[:keyword:][:ident:]]'
  125. return "\<C-R>=completor#do('complete')\<CR>"
  126. else
  127. " If we aren't typing a word and we press `tab` simply do the normal `tab`
  128. " action.
  129. return "\<Tab>"
  130. endif
  131. endfunction
  132. " Use `tab` key to select completions. Default is arrow keys.
  133. inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
  134. inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
  135. " Use tab to trigger auto completion.
  136. inoremap <expr> <Tab> Tab_Or_Complete()
  137. " }}}