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.

240 lines
6.9 KiB

4 years ago
  1. " My awesome vimrc
  2. let mapleader =","
  3. if ! filereadable(expand('~/.config/nvim/autoload/plug.vim'))
  4. echo "Downloading junegunn/vim-plug to manage plugins..."
  5. silent !mkdir -p ~/.config/nvim/autoload/
  6. silent !curl "https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim" > ~/.config/nvim/autoload/plug.vim
  7. autocmd VimEnter * PlugInstall
  8. endif
  9. function! Cond(cond, ...)
  10. let opts = get(a:000, 0, {})
  11. return a:cond ? opts : extend(opts, { 'on': [], 'for': [] })
  12. endfunction
  13. call plug#begin('~/.config/nvim/plugged')
  14. if !exists('g:vscode')
  15. Plug 'neoclide/coc.nvim', Cond(!exists('g:vscode'))
  16. Plug 'nvim-lua/popup.nvim', Cond(!exists('g:vscode'))
  17. Plug 'nvim-lua/plenary.nvim', Cond(!exists('g:vscode'))
  18. Plug 'nvim-telescope/telescope.nvim', Cond(!exists('g:vscode'))
  19. Plug 'nvim-telescope/telescope-fzy-native.nvim', Cond(!exists('g:vscode'))
  20. Plug 'Rican7/php-doc-modded'
  21. Plug 'udalov/kotlin-vim'
  22. Plug 'f-person/git-blame.nvim'
  23. Plug 'vimwiki/vimwiki', Cond(!exists('g:vscode'))
  24. Plug 'ap/vim-css-color', Cond(!exists('g:vscode'))
  25. endif
  26. Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
  27. Plug 'darrikonn/vim-gofmt', { 'do': ':GoUpdateBinaries' }
  28. call plug#end()
  29. " Some basics:
  30. set clipboard+=unnamedplus
  31. set nohlsearch
  32. set incsearch
  33. set ignorecase
  34. autocmd BufWritePre * :%s/\s\+$//e
  35. if !exists('g:vscode')
  36. set go=a
  37. set mouse=a
  38. set smartcase
  39. set linebreak
  40. set noswapfile
  41. set nobackup
  42. set undodir=~/.config/nvim/undodir
  43. set undofile
  44. nnoremap c "_c
  45. set nocompatible
  46. filetype plugin on
  47. syntax on
  48. set encoding=utf-8
  49. set number relativenumber
  50. nnoremap <leader>vs :vsplit<Enter>
  51. nnoremap <leader>hs :split<Enter>
  52. " Tab 2 spaces
  53. filetype plugin indent on
  54. set tabstop=4 softtabstop=4 expandtab shiftwidth=4 smarttab
  55. let g:tabStop=4
  56. function! ToggleTabWidth()
  57. if g:tabStop == 2
  58. set tabstop=4 softtabstop=4 expandtab shiftwidth=4 smarttab
  59. let g:tabStop=4
  60. else
  61. set tabstop=2 softtabstop=2 expandtab shiftwidth=2 smarttab
  62. let g:tabStop=2
  63. endif
  64. endfunction
  65. nnoremap <leader>t :call ToggleTabWidth()<CR>
  66. " Disables automatic commenting on newline:
  67. autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o
  68. " Remember last cursor position
  69. autocmd BufReadPost * if @% !~# '\.git[\/\\]COMMIT_EDITMSG$' && line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
  70. " Copy entire document
  71. noremap <leader>y <Esc>ggyG<C-o>
  72. map <leader>y <Esc>ggyG<C-o>
  73. " Set gohtml template files to html syntax
  74. autocmd BufNewFile,BufRead *.gohtml set syntax=html
  75. " Automatically save the current session whenever vim is closed
  76. autocmd VimLeave * mksession! ~/.config/nvim/session/shutdown_session.vim
  77. " <F7> restores that 'shutdown session'
  78. noremap <F7> :source ~/.config/nvim/session/shutdown_session.vim<CR>
  79. " If you really want to, this next line should restore the shutdown session
  80. " automatically, whenever you start vim. (Commented out for now, in case
  81. " somebody just copy/pastes this whole block)
  82. "
  83. " autocmd VimEnter source ~/.vim/shutdown_session.vim<CR>
  84. " manually save a session with <F5>
  85. noremap <F5> :mksession! ~/.config/nvim/session/manual_session.vim<cr>
  86. " recall the manually saved session with <F6>
  87. noremap <F6> :source ~/.config/nvim/session/manual_session.vim<cr>
  88. " NETRW
  89. let g:netrw_liststyle = 3
  90. let g:netrw_banner = 0
  91. let g:netrw_browse_split = 4
  92. let g:netrw_winsize = 20
  93. let g:netrw_altv = 1
  94. let g:NetrwIsOpen=0
  95. function! ToggleNetrw()
  96. if g:NetrwIsOpen
  97. let i = bufnr("$")
  98. while (i >= 1)
  99. if (getbufvar(i, "&filetype") == "netrw")
  100. silent exe "bwipeout " . i
  101. endif
  102. let i-=1
  103. endwhile
  104. let g:NetrwIsOpen=0
  105. else
  106. let g:NetrwIsOpen=1
  107. silent Lexplore
  108. endif
  109. endfunction
  110. " Add your own mapping. For example:
  111. noremap <silent> <C-p> :call ToggleNetrw()<CR>
  112. " coc
  113. highlight CocErrorSign ctermfg=Black ctermbg=Magenta
  114. inoremap <silent><expr> <TAB>
  115. \ pumvisible() ? "\<C-n>" :
  116. \ <SID>check_back_space() ? "\<TAB>" :
  117. \ coc#refresh()
  118. inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
  119. function! s:check_back_space() abort
  120. let col = col('.') - 1
  121. return !col || getline('.')[col - 1] =~# '\s'
  122. endfunction
  123. nmap <leader>gd <Plug>(coc-definition)
  124. nmap <leader>gr <Plug>(coc-references)
  125. nmap <leader>rr <Plug>(coc-rename)
  126. nnoremap <leader>prw :CocSearch <C-R>=expand("<cword>")<CR><CR>
  127. inoremap <expr> <C-j> pumvisible() ? "\<Down>" : "\<C-j>"
  128. inoremap <expr> <C-k> pumvisible() ? "\<Up>" : "\<C-k>"
  129. try
  130. nmap <silent> <leader>ej :call CocAction('diagnosticNext')<cr>
  131. nmap <silent> <leader>ek :call CocAction('diagnosticPrevious')<cr>
  132. endtry
  133. " Telescope remaps
  134. lua require("telescope")
  135. nnoremap <C-g> :lua require('telescope.builtin').grep_string({ search = vim.fn.input("Grep For > ")})<CR>
  136. nnoremap <C-p> :lua require('telescope.builtin').git_files()<CR>
  137. nnoremap <C-q> :lua require('telescope.builtin').find_files()<CR>
  138. nnoremap <leader>fb <cmd>lua require('telescope.builtin').buffers()<cr>
  139. " PHP Doc
  140. nnoremap <leader>h :call UpdatePhpDocIfExists()<CR>
  141. function! UpdatePhpDocIfExists()
  142. normal! k
  143. if getline('.') =~ '/'
  144. normal! V%d
  145. else
  146. normal! j
  147. endif
  148. call PhpDocSingle()
  149. normal! k^%k$
  150. if getline('.') =~ ';'
  151. exe "normal! $svoid"
  152. endif
  153. endfunction
  154. nnoremap <C-D> :call UpdatePhpDocIfExists()<CR>
  155. " VimWiki
  156. let pentest_wiki = {}
  157. let pentest_wiki.path = '~/Documents/PentestWiki/'
  158. let pentest_wiki.path_html = '~/Documents/PentestWikiHtml/'
  159. let pentest_wiki.syntax = 'markdown'
  160. let pentest_wiki.ext = '.md'
  161. let pentest_wiki.custom_wiki2html = '~/.local/bin/vimwiki_convert.py'
  162. let g:vimwiki_list = [pentest_wiki]
  163. let g:vimwiki_ext2syntax = {'.md': 'markdown', '.markdown': 'markdown', '.mdown': 'markdown'}
  164. au filetype vimwiki silent! iunmap <buffer> <Tab>
  165. " Spell-check
  166. map <leader>o :setlocal spell! spelllang=en_au<CR>
  167. " Shortcutting split navigation, saving a keypress:
  168. nnoremap <C-h> <C-w>h
  169. nnoremap <C-j> <C-w>j
  170. nnoremap <C-k> <C-w>k
  171. nnoremap <C-l> <C-w>l
  172. " Replace all is aliased to S.
  173. nnoremap <c-s> :%s//g<Left><Left>
  174. " Navigating with guides
  175. inoremap <leader><leader> <Esc>/<++><Enter>"_c4l
  176. vnoremap <leader><leader> <Esc>/<++><Enter>"_c4l
  177. map <leader><leader> <Esc>/<++><Enter>"_c4l
  178. augroup twig_ft
  179. au!
  180. autocmd BufNewFile,BufRead *.docker set syntax=dockerfile
  181. augroup END
  182. endif