My 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.

364 lines
11 KiB

  1. call plug#begin('~/.vim/plugged')
  2. Plug 'joshdick/onedark.vim' " Colors
  3. Plug 'itchyny/lightline.vim' " Lightline statusbar
  4. Plug 'scrooloose/nerdtree' " Nerdtree
  5. Plug 'tiagofumo/vim-nerdtree-syntax-highlight' " Highlighting Nerdtree
  6. Plug 'ryanoasis/vim-devicons' " Icons for Nerdtree
  7. Plug 'ap/vim-css-color' " Color previews for CSS
  8. Plug 'junegunn/limelight.vim'
  9. Plug 'junegunn/fzf.vim'
  10. Plug 'xolox/vim-misc'
  11. Plug 'xolox/vim-session'
  12. Plug 'neoclide/coc.nvim', {'branch': 'release'}
  13. Plug 'mfussenegger/nvim-dap'
  14. Plug 'rcarriga/nvim-dap-ui'
  15. Plug 'jackguo380/vim-lsp-cxx-highlight'
  16. Plug 'vim-syntastic/syntastic'
  17. Plug 'rhysd/vim-clang-format'
  18. Plug 'lambdalisue/suda.vim'
  19. call plug#end()
  20. " for transparent background
  21. function! AdaptColorscheme()
  22. highlight clear CursorLine
  23. highlight Normal ctermbg=none
  24. highlight LineNr ctermbg=none
  25. highlight Folded ctermbg=none
  26. highlight NonText ctermbg=none
  27. highlight SpecialKey ctermbg=none
  28. highlight VertSplit ctermbg=none
  29. highlight SignColumn ctermbg=none
  30. endfunction
  31. autocmd ColorScheme * call AdaptColorscheme()
  32. set cursorline
  33. " colorscheme
  34. syntax on
  35. " brackets
  36. inoremap " ""<left>
  37. inoremap ' ''<left>
  38. inoremap ( ()<left>
  39. inoremap [ []<left>
  40. inoremap { {}<left>
  41. inoremap {<CR> {<CR>}<ESC>O
  42. inoremap {;<CR> {<CR>};<ESC>O
  43. filetype plugin on
  44. let g:instant_markdown_browser = "firefox --new-window"
  45. let g:session_autosave = "no"
  46. let g:session_autoload = "no"
  47. " Make Vim more useful
  48. set nocompatible
  49. " Long lines as one line
  50. set nowrap
  51. " Ruler
  52. set ruler
  53. " Horizontal splits will automatically be below
  54. set splitbelow
  55. " Vertical splits will automatically be to the right
  56. set splitright
  57. " Indent
  58. set smartindent
  59. set autoindent
  60. " Use the OS clipboard by default (on versions compiled with `+clipboard`)
  61. set clipboard+=unnamedplus
  62. " Enhance command-line completion
  63. set wildmenu
  64. " Disables automatic commenting on newline:
  65. autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o
  66. " Allow cursor keys in insert mode
  67. " Allow backspace in insert mode
  68. set backspace=indent,eol,start
  69. " Optimize for fast terminal connections
  70. set ttyfast
  71. " Add the g flag to search/replace by default
  72. set gdefault
  73. " Use UTF-8 without BOM
  74. set encoding=utf-8
  75. " Change mapleader
  76. let mapleader=","
  77. " Don’t add empty newlines at the end of files
  78. set binary
  79. set noeol
  80. set smartcase
  81. set noswapfile
  82. set nobackup
  83. set undodir=~/.vim/undodir
  84. set undofile
  85. " 256 colors
  86. set t_Co=256
  87. " Respect modeline in files
  88. set modeline
  89. set modelines=4
  90. " Enable per-directory .vimrc files and disable unsafe commands in them
  91. set exrc
  92. set secure
  93. " Enable line numbers
  94. set number
  95. " Make tabs as wide as two spaces
  96. set tabstop=4
  97. set shiftwidth=4
  98. set smarttab
  99. set expandtab
  100. " Highlight searches
  101. set hlsearch
  102. " Ignore case of searches
  103. set ignorecase
  104. " Highlight dynamically as pattern is typed
  105. set incsearch
  106. " Always show status line
  107. set laststatus=2
  108. " Enable mouse in all modes
  109. set mouse=a
  110. " Disable error bells
  111. set noerrorbells
  112. " Don’t reset cursor to start of line when moving around.
  113. set nostartofline
  114. " Show the cursor position
  115. set ruler
  116. " Don’t show the intro message when starting Vim
  117. set shortmess=atI
  118. " Show the current mode
  119. set showmode
  120. " Show the filename in the window titlebar
  121. set title
  122. " Show the (partial) command as it’s being typed
  123. set showcmd
  124. " Use relative line numbers
  125. set hidden
  126. set nobackup
  127. set nowritebackup
  128. set updatetime=300
  129. set shortmess+=c
  130. " Give more space for displaying messages.
  131. set cmdheight=2
  132. set pumheight=5
  133. " Always show the signcolumn, otherwise it would shift the text each time
  134. " diagnostics appear/become resolved.
  135. if has("nvim-0.5.0") || has("patch-8.1.1564")
  136. " Recently vim can merge signcolumn and number column into one
  137. set signcolumn=number
  138. else
  139. set signcolumn=yes
  140. endif
  141. inoremap <silent><expr> <TAB>
  142. \ pumvisible() ? "\<C-n>" :
  143. \ <SID>check_back_space() ? "\<TAB>" :
  144. \ coc#refresh()
  145. inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
  146. function! s:check_back_space() abort
  147. let col = col('.') - 1
  148. return !col || getline('.')[col - 1] =~# '\s'
  149. endfunction
  150. " Use <c-space> to trigger completion.
  151. if has('nvim')
  152. inoremap <silent><expr> <c-return> coc#refresh()
  153. else
  154. inoremap <silent><expr> <c-@> coc#refresh()
  155. endif
  156. " Make <CR> auto-select the first completion item and notify coc.nvim to
  157. " format on enter, <cr> could be remapped by other vim plugin
  158. inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm()
  159. \: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
  160. " Use `[g` and `]g` to navigate diagnostics
  161. " Use `:CocDiagnostics` to get all diagnostics of current buffer in location list.
  162. nmap <silent> [g <Plug>(coc-diagnostic-prev)
  163. nmap <silent> ]g <Plug>(coc-diagnostic-next)
  164. " GoTo code navigation.
  165. nmap <silent> gd <Plug>(coc-definition)
  166. nmap <silent> gy <Plug>(coc-type-definition)
  167. nmap <silent> gi <Plug>(coc-implementation)
  168. nmap <silent> gr <Plug>(coc-references)
  169. " Use K to show documentation in preview window.
  170. nnoremap <silent> K :call <SID>show_documentation()<CR>
  171. function! s:show_documentation()
  172. if (index(['vim','help'], &filetype) >= 0)
  173. execute 'h '.expand('<cword>')
  174. elseif (coc#rpc#ready())
  175. call CocActionAsync('doHover')
  176. else
  177. execute '!' . &keywordprg . " " . expand('<cword>')
  178. endif
  179. endfunction
  180. " Highlight the symbol and its references when holding the cursor.
  181. autocmd CursorHold * silent call CocActionAsync('highlight')
  182. " Symbol renaming.
  183. nmap <leader>rn <Plug>(coc-rename)
  184. " Formatting selected code.
  185. xmap <leader>f <Plug>(coc-format-selected)
  186. nmap <leader>f <Plug>(coc-format-selected)
  187. augroup mygroup
  188. autocmd!
  189. " Setup formatexpr specified filetype(s).
  190. autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
  191. " Update signature help on jump placeholder.
  192. autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
  193. augroup end
  194. " Applying codeAction to the selected region.
  195. " Example: `<leader>aap` for current paragraph
  196. xmap <leader>a <Plug>(coc-codeaction-selected)
  197. nmap <leader>a <Plug>(coc-codeaction-selected)
  198. " Remap keys for applying codeAction to the current buffer.
  199. nmap <leader>ac <Plug>(coc-codeaction)
  200. " Apply AutoFix to problem on the current line.
  201. nmap <leader>qf <Plug>(coc-fix-current)
  202. " Run the Code Lens action on the current line.
  203. nmap <leader>cl <Plug>(coc-codelens-action)
  204. " Remap <C-f> and <C-b> for scroll float windows/popups.
  205. if has('nvim-0.4.0') || has('patch-8.2.0750')
  206. nnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
  207. nnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
  208. inoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<Right>"
  209. inoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0)\<cr>" : "\<Left>"
  210. vnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
  211. vnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
  212. endif
  213. " Add `:Format` command to format current buffer.
  214. command! -nargs=0 Format :call CocActionAsync('format')
  215. " Add `:Fold` command to fold current buffer.
  216. command! -nargs=? Fold :call CocAction('fold', <f-args>)
  217. " Add `:OR` command for organize imports of the current buffer.
  218. command! -nargs=0 OR :call CocActionAsync('runCommand', 'editor.action.organizeImport')
  219. let g:lightline = {
  220. \ 'colorscheme': 'onedark',
  221. \ 'active': {
  222. \ 'left': [ [ 'mode', 'paste' ],
  223. \ [ 'cocstatus', 'readonly', 'filename', 'modified' ] ]
  224. \ },
  225. \ 'component_function': {
  226. \ 'cocstatus': 'coc#status'
  227. \ },
  228. \ }
  229. " Use autocmd to force lightline update.
  230. autocmd User CocStatusChange,CocDiagnosticChange call lightline#update()
  231. " Mappings for CoCList
  232. " Show all diagnostics.
  233. nnoremap <silent><nowait> <space>a :<C-u>CocList diagnostics<cr>
  234. " Manage extensions.
  235. nnoremap <silent><nowait> <space>e :<C-u>CocList extensions<cr>
  236. " Show commands.
  237. nnoremap <silent><nowait> <space>c :<C-u>CocList commands<cr>
  238. " Find symbol of current document.
  239. nnoremap <silent><nowait> <space>o :<C-u>CocList outline<cr>
  240. " Search workspace symbols.
  241. nnoremap <silent><nowait> <space>s :<C-u>CocList -I symbols<cr>
  242. " Do default action for next item.
  243. nnoremap <silent><nowait> <space>j :<C-u>CocNext<CR>
  244. " Do default action for previous item.
  245. nnoremap <silent><nowait> <space>k :<C-u>CocPrev<CR>
  246. " Resume latest coc list.
  247. nnoremap <silent><nowait> <space>p :<C-u>CocListResume<CR>
  248. " c++ syntax highlighting
  249. let g:cpp_class_scope_highlight = 1
  250. let g:cpp_member_variable_highlight = 1
  251. let g:cpp_class_decl_highlight = 1
  252. " c++ linting
  253. let g:syntastic_cpp_checkers = ['cpplint']
  254. let g:syntastic_c_checkers = ['cpplint']
  255. let g:syntastic_cpp_cpplint_exec = 'cpplint'
  256. " The following two lines are optional. Configure it to your liking!
  257. let g:syntastic_check_on_open = 1
  258. let g:syntastic_check_on_wq = 0
  259. nnoremap <Leader>f :<C-u>ClangFormat<CR>
  260. " header guards
  261. function! s:insert_gates()
  262. let gatename = substitute(toupper(expand("%:t")), "\\.", "_", "g")
  263. execute "normal! i#ifndef " . gatename
  264. execute "normal! o#define " . gatename . " "
  265. execute "normal! Go#endif /* " . gatename . " */"
  266. normal! ko
  267. endfunction
  268. autocmd BufNewFile *.{h,hpp} call <SID>insert_gates()
  269. if exists("&relativenumber")
  270. set relativenumber
  271. au BufReadPost * set relativenumber
  272. endif " Start scrolling three lines before the horizontal window border
  273. set scrolloff=3
  274. " Toggle spellchecking
  275. function! ToggleSpellCheck()
  276. set spell!
  277. if &spell
  278. echo "Spellcheck ON"
  279. else
  280. echo "Spellcheck OFF"
  281. endif
  282. endfunction
  283. " Better tabbing
  284. vnoremap < <gv
  285. vnoremap > >gv
  286. " Better window navigation
  287. nnoremap <C-h> <C-w>h
  288. nnoremap <C-j> <C-w>j
  289. nnoremap <C-k> <C-w>k
  290. nnoremap <C-l> <C-w>l
  291. map <Leader>c :w! \| !make <CR>
  292. map <Leader>r <c-w>v <c-w>l :terminal ./run.sh <c-r>% <CR>a
  293. map <Leader>t :!st&<CR><CR>
  294. map <Leader>o :FZF<CR>
  295. map <Leader>s :call ToggleSpellCheck()<CR>
  296. map <Leader>n :NERDTreeToggle<CR>
  297. map Q gq
  298. " Insert mode completion
  299. imap <c-x><c-k> <plug>(fzf-complete-word)
  300. imap <c-x><c-f> <plug>(fzf-complete-path)
  301. imap <c-x><c-l> <plug>(fzf-complete-line)
  302. vnoremap <C-c> "+y
  303. " Write as root
  304. cnoremap w!! SudaWrite
  305. colorscheme onedark
  306. " Debugging
  307. map <Leader>db :lua require'dap'.toggle_breakpoint() <CR>
  308. map <Leader>dc :lua require'dap'.continue() <CR>
  309. map <Leader>do :lua require'dap'.step_over() <CR>
  310. map <Leader>di :lua require'dap'.step_into() <CR>
  311. map <Leader>dn :lua require("dapui").toggle() <CR>
  312. lua require("dap-conf")
  313. lua require("dapui").setup()