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.

175 lines
5.1 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 'vimwiki/vimwiki', Cond(!exists('g:vscode'))
  21. Plug 'ap/vim-css-color', Cond(!exists('g:vscode'))
  22. endif
  23. Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
  24. Plug 'darrikonn/vim-gofmt', { 'do': ':GoUpdateBinaries' }
  25. call plug#end()
  26. " Some basics:
  27. set clipboard+=unnamedplus
  28. set nohlsearch
  29. set incsearch
  30. set ignorecase
  31. if !exists('g:vscode')
  32. set go=a
  33. set mouse=a
  34. set smartcase
  35. set linebreak
  36. set noswapfile
  37. set nobackup
  38. set undodir=~/.config/nvim/undodir
  39. set undofile
  40. nnoremap c "_c
  41. set nocompatible
  42. filetype plugin on
  43. syntax on
  44. set encoding=utf-8
  45. set number relativenumber
  46. " Tab 2 spaces
  47. filetype plugin indent on
  48. set tabstop=4 softtabstop=4 expandtab shiftwidth=4 smarttab
  49. " Disables automatic commenting on newline:
  50. autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o
  51. " Remember last cursor position
  52. autocmd BufReadPost * if @% !~# '\.git[\/\\]COMMIT_EDITMSG$' && line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
  53. " Copy entire document
  54. noremap <leader>y <Esc>ggyG<C-o>
  55. map <leader>y <Esc>ggyG<C-o>
  56. " Set gohtml template files to html syntax
  57. autocmd BufNewFile,BufRead *.gohtml set syntax=html
  58. " NETRW
  59. let g:netrw_liststyle = 3
  60. let g:netrw_banner = 0
  61. let g:netrw_browse_split = 4
  62. let g:netrw_winsize = 20
  63. let g:netrw_altv = 1
  64. let g:NetrwIsOpen=0
  65. function! ToggleNetrw()
  66. if g:NetrwIsOpen
  67. let i = bufnr("$")
  68. while (i >= 1)
  69. if (getbufvar(i, "&filetype") == "netrw")
  70. silent exe "bwipeout " . i
  71. endif
  72. let i-=1
  73. endwhile
  74. let g:NetrwIsOpen=0
  75. else
  76. let g:NetrwIsOpen=1
  77. silent Lexplore
  78. endif
  79. endfunction
  80. " Add your own mapping. For example:
  81. noremap <silent> <C-p> :call ToggleNetrw()<CR>
  82. " coc
  83. highlight CocErrorSign ctermfg=Black ctermbg=Magenta
  84. inoremap <silent><expr> <TAB>
  85. \ pumvisible() ? "\<C-n>" :
  86. \ <SID>check_back_space() ? "\<TAB>" :
  87. \ coc#refresh()
  88. inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
  89. function! s:check_back_space() abort
  90. let col = col('.') - 1
  91. return !col || getline('.')[col - 1] =~# '\s'
  92. endfunction
  93. nmap <leader>gd <Plug>(coc-definition)
  94. nmap <leader>gr <Plug>(coc-references)
  95. nmap <leader>rr <Plug>(coc-rename)
  96. nnoremap <leader>prw :CocSearch <C-R>=expand("<cword>")<CR><CR>
  97. inoremap <expr> <C-j> pumvisible() ? "\<Down>" : "\<C-j>"
  98. inoremap <expr> <C-k> pumvisible() ? "\<Up>" : "\<C-k>"
  99. try
  100. nmap <silent> <leader>ej :call CocAction('diagnosticNext')<cr>
  101. nmap <silent> <leader>ek :call CocAction('diagnosticPrevious')<cr>
  102. endtry
  103. " Telescope remaps
  104. lua require("telescope")
  105. nnoremap <leader>gs :lua require('telescope.builtin').grep_string({ search = vim.fn.input("Grep For > ")})<CR>
  106. nnoremap <C-q> :lua require('telescope.builtin').git_files()<CR>
  107. nnoremap <C-a> :lua require('telescope.builtin').find_files()<CR>
  108. nnoremap <leader>fb <cmd>lua require('telescope.builtin').buffers()<cr>
  109. " VimWiki
  110. let pentest_wiki = {}
  111. let pentest_wiki.path = '~/Documents/PentestWiki/'
  112. let pentest_wiki.path_html = '~/Documents/PentestWikiHtml/'
  113. let pentest_wiki.syntax = 'markdown'
  114. let pentest_wiki.ext = '.md'
  115. let pentest_wiki.custom_wiki2html = '~/.local/bin/vimwiki_convert.py'
  116. let g:vimwiki_list = [pentest_wiki]
  117. let g:vimwiki_ext2syntax = {'.md': 'markdown', '.markdown': 'markdown', '.mdown': 'markdown'}
  118. au filetype vimwiki silent! iunmap <buffer> <Tab>
  119. " Spell-check
  120. map <leader>o :setlocal spell! spelllang=en_au<CR>
  121. " Shortcutting split navigation, saving a keypress:
  122. nnoremap <C-h> <C-w>h
  123. nnoremap <C-j> <C-w>j
  124. nnoremap <C-k> <C-w>k
  125. nnoremap <C-l> <C-w>l
  126. " Replace all is aliased to S.
  127. nnoremap <c-s> :%s//g<Left><Left>
  128. " Navigating with guides
  129. inoremap <leader><leader> <Esc>/<++><Enter>"_c4l
  130. vnoremap <leader><leader> <Esc>/<++><Enter>"_c4l
  131. map <leader><leader> <Esc>/<++><Enter>"_c4l
  132. endif