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.

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