init_old.vim 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. " This config file is prepared for Neovim in mind.
  2. " 1. Install neovim, git, xclip, ag, the_silver_searcher package on your
  3. " Linux system.
  4. " sudo pacman -S neovim git xclip the_silver_searcher
  5. " 2. Install vim-plug (https://github.com/junegunn/vim-plug)
  6. " to manage packages easily. On Linux:
  7. " mkdir -p ~/.local/share/nvim/site/autoload/
  8. " curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
  9. " 3. To stop a python related error for UltiSnips:
  10. " sudo pacman -S python-pip
  11. " pip3 install --upgrade pip
  12. " pip3 install --user neovim
  13. " pip3 install --user typing
  14. " 4. Save this file as init.vim:
  15. " mkdir -p ~/.config/nvim
  16. " nano ~/.config/nvim/init.vim
  17. " 5. Run nvim in terminal, ignore the errors,
  18. " then run :PlugInstall
  19. " . When it says "Finishing...Done!" :q to quit the screen. and then :UpdateRemotePlugins from inside neovim. Quit neovim, restart and use.
  20. " 6. To check keyboard Shortcuts, check the mapping commands
  21. " -------------- Start vim-plug --------------- "
  22. " Specify a directory for plugins
  23. " - For Neovim: ~/.local/share/nvim/plugged
  24. " - For Vim: ~/.vim/plugged
  25. " - Avoid using standard Vim directory names like 'plugin'
  26. call plug#begin('~/.local/share/nvim/plugged')
  27. " -- Custom Plugins -- "
  28. " Run :PlugInstall after adding a plugin
  29. Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
  30. Plug 'crusoexia/vim-monokai'
  31. Plug 'ervandew/supertab'
  32. Plug 'scrooloose/nerdcommenter'
  33. Plug 'SirVer/ultisnips'
  34. Plug 'honza/vim-snippets'
  35. " Requires system package: ack, optional: the_silver_searcher
  36. Plug 'mileszs/ack.vim'
  37. Plug 'terryma/vim-multiple-cursors'
  38. Plug 'kien/ctrlp.vim'
  39. Plug 'shinokada/dragvisuals.vim'
  40. " will need to run :UpdateRemotePlugins for this
  41. Plug 'Shougo/denite.nvim'
  42. Plug 'Chiel92/vim-autoformat'
  43. Plug 'severin-lemaignan/vim-minimap'
  44. "
  45. Plug 'tobyS/vmustache'
  46. Plug 'tobyS/pdv'
  47. " autocomplete
  48. "Plug 'roxma/LanguageServer-php-neovim', {'do': 'composer install && "composer run-script parse-stubs'}
  49. Plug 'roxma/nvim-completion-manager'
  50. "Plug 'roxma/python-support.nvim'
  51. Plug 'shawncplus/phpcomplete.vim'
  52. " Initialize plugin system
  53. call plug#end()
  54. " -------------- End vim-plug --------------- "
  55. " -------- General Configs -------- "
  56. " -- general general configs -- "
  57. syntax on
  58. filetype plugin indent on
  59. "filetype plugin on
  60. syntax on
  61. colorscheme monokai
  62. set cursorline " Highlight cursor line
  63. " highlight long lines
  64. " more helpful than "set textwidth=80"
  65. highlight ColorColumn ctermbg=magenta
  66. call matchadd('ColorColumn', '\%81v', 100)
  67. " for invisible characters
  68. set listchars=eol:$,tab:>-,trail:~,extends:>,precedes:<,space:␣
  69. "highlight SpecialKey ctermfg=8 ctermbg=8
  70. "highlight link VisibleTab Error
  71. "match VisibleTab /\t$/
  72. " -- show row and column in footer + improved statusbar -- "
  73. set ruler
  74. set statusline=%F%m%r%h%w\ [%l,%c]\ [%L,%p%%]
  75. " -- so that : commands can be typed quick! -- "
  76. nnoremap ; :
  77. " -- use mouse cursor (when needed badly) -- "
  78. set mouse=a
  79. " -- better line number -- "
  80. " on normal mode, sets current line as current line and others as
  81. " relative
  82. set number relativenumber
  83. " on insert mode, this is not needed, so restores normal line numbers
  84. augroup numbertoggle
  85. autocmd!
  86. autocmd BufEnter,FocusGained,InsertLeave * set relativenumber
  87. autocmd BufLeave,FocusLost,InsertEnter * set norelativenumber
  88. augroup END
  89. " -- Tab width -- "
  90. " for using tabs for indenting
  91. set sw=4
  92. set tabstop=4
  93. " -- Cursor style change depending on mode -- "
  94. let &t_ti.="\e[1 q"
  95. let &t_SI.="\e[5 q"
  96. let &t_EI.="\e[1 q"
  97. let &t_te.="\e[0 q"
  98. " -- highlight the status bar when in insert mode -- "
  99. if version >= 700
  100. au InsertEnter * hi StatusLine ctermfg=235 ctermbg=2
  101. au InsertLeave * hi StatusLine ctermbg=230 ctermfg=12
  102. endif
  103. " -- highlight trailing spaces in annoying red -- "
  104. highlight ExtraWhitespace ctermbg=1 guibg=red
  105. match ExtraWhitespace /\s\+$/
  106. autocmd BufWinEnter * match ExtraWhitespace /\s\+$/
  107. autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
  108. autocmd InsertLeave * match ExtraWhitespace /\s\+$/
  109. autocmd BufWinLeave * call clearmatches()
  110. " ---- General Keyboard Shortcuts ---- "
  111. inoremap <C-M-j> <ESC>ji
  112. inoremap <C-M-k> <ESC>ki
  113. " -- set leader key to comma -- "
  114. let mapleader = ","
  115. " -- Rename current file, via Gary Bernhardt -- "
  116. function! RenameFile()
  117. let old_name = expand('%')
  118. let new_name = input('New file name: ', expand('%'))
  119. if new_name != '' && new_name != old_name
  120. exec ':saveas ' . new_name
  121. exec ':silent !rm ' . old_name
  122. redraw!
  123. endif
  124. endfunction
  125. map <leader>r :call RenameFile()<cr>
  126. " -- exit insert with one hand! -- "
  127. inoremap jk <ESC>
  128. " -- window/tab related keys -- "
  129. nnoremap <C-s> :w<CR>
  130. inoremap <C-s> <Esc>:w<CR>i
  131. map <C-t> :tabnew<CR>
  132. map <C-h> :tabp<CR>
  133. map <C-l> :tabn<CR>
  134. nnoremap <C-w> :q<CR>
  135. inoremap <C-w> <Esc>:q<CR>
  136. " -- Duplicate line -- "
  137. vnoremap <C-S-D> y'>p<CR>
  138. nnoremap <C-S-D> yypk<CR>
  139. " -- Cut line -- "
  140. vnoremap <C-S-k> d
  141. nnoremap <C-S-k> dd
  142. " -- move lines up and down -- "
  143. nnoremap <C-j> :m .+1<CR>==
  144. nnoremap <C-k> :m .-2<CR>==
  145. inoremap <C-j> <Esc>:m .+1<CR>==gi
  146. inoremap <C-k> <Esc>:m .-2<CR>==gi
  147. vnoremap <C-j> :m '>+1<CR>gv=gv
  148. vnoremap <C-k> :m '<-2<CR>gv=gv
  149. " -- copy-paste systemwide (linux) -- "
  150. vmap <C-c> y:call system("xclip -i -selection clipboard", getreg("\""))<CR>:call system("xclip -i", getreg("\""))<CR>
  151. nmap <C-v> :call setreg("\"",system("xclip -o -selection clipboard"))<CR>p
  152. " https://stackoverflow.com/a/20902777
  153. " -- File format specific things -- "
  154. " - for rmarkdown (.rmd files) - "
  155. autocmd FileType rmd map <F5> :!echo<space>"require(rmarkdown);<space>render('<c-r>%')"<space>\|<space>R<space>--vanilla<enter>
  156. " -------- Plugin Related -------- "
  157. " ---- NerdTree related ---- "
  158. map <C-o> :NERDTreeToggle<CR>
  159. " ---- NerdCommenter related ---- "
  160. nmap <C-_> ,c<space>
  161. imap <C-_> <Esc>,c<space>i
  162. vmap <buffer> <C-_> ,c<space>
  163. " Add spaces after comment delimiters by default
  164. let g:NERDSpaceDelims = 1
  165. " Use compact syntax for prettified multi-line comments
  166. "let g:NERDCompactSexyComs = 1
  167. " Add your own custom formats or override the defaults
  168. let g:NERDCustomDelimiters = { 'c': { 'left': '/**','right': '*/' } }
  169. " Allow commenting and inverting empty lines (useful when commenting a region)
  170. let g:NERDCommentEmptyLines = 1
  171. " Enable trimming of trailing whitespace when uncommenting
  172. let g:NERDTrimTrailingWhitespace = 1
  173. " ---- Ctrlp related ---- "
  174. let g:ctrlp_map = '<leader>ff'
  175. nmap <C-M-f> ,ff
  176. imap <C-M-f> <Esc>,ff
  177. let g:ctrlp_max_height = 25
  178. "let g:ctrlp_working_path_mode = 0
  179. let g:ctrlp_match_window_reversed = 0
  180. " use silver searcher for ctrlp
  181. let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""'
  182. " ---- Multi Select related (like sublime) ---- "
  183. let g:multi_cursor_next_key='<C-n>'
  184. "let g:multi_cursor_prev_key='<C-z>'
  185. " ---- PDV ---- "
  186. " phpDocumentor auto comments related
  187. "let g:pdv_template_dir = $HOME ."/.vim/bundle/pdv/templates_snip"
  188. let g:pdv_template_dir = $HOME ."/.local/share/nvim/plugged/pdv/templates_snip"
  189. "nnoremap <buffer> <C-m> :call pdv#DocumentWithSnip()<CR>
  190. nnoremap <buffer> <C-m> :silent! call pdv#DocumentWithSnip()<CR>
  191. " ---- roxma/LanguageServer-php-neovim related ---- "
  192. "autocmd FileType php LanguageClientStart
  193. " pip3 requirements
  194. let g:python_support_python3_requirements = add(get(g:,'python_support_python3_requirements',[]),'neovim')
  195. " ---- ultisnip related ---- "
  196. " Trigger configuration. Do not use <tab> if you use https://github.com/Valloric/YouCompleteMe.
  197. inoremap <silent><expr><TAB> pumvisible() ? "\<C-n>" : "\<TAB>"
  198. let g:UltiSnipsExpandTrigger="<tab>"
  199. let g:UltiSnipsJumpForwardTrigger="<tab>"
  200. let g:UltiSnipsJumpBackwardTrigger="<s-tab>"
  201. let g:UltiSnipsSnippetsDir='~/.local/share/nvim/plugged/vim-snippets/UltiSnips'
  202. " If you want :UltiSnipsEdit to split your window.
  203. let g:UltiSnipsEditSplit="vertical"
  204. " -- Solution to: UltiSnips requires py >= 2.6 or any py3
  205. " yaourt -S python-pip
  206. " pip3 install --user neovim
  207. " ---- dragvisuals ---- "
  208. runtime plugin/dragvisuals.vim
  209. vmap <expr> <LEFT> DVB_Drag('left')
  210. vmap <expr> <RIGHT> DVB_Drag('right')
  211. vmap <expr> <DOWN> DVB_Drag('down')
  212. vmap <expr> <UP> DVB_Drag('up')
  213. vmap <expr> D DVB_Duplicate()
  214. " Remove any introduced trailing whitespace after moving...
  215. let g:DVB_TrimWS = 1
  216. " ---- Denite plugin related ---- "
  217. " Change mappings.
  218. call denite#custom#map(
  219. \ 'insert',
  220. \ '<C-j>',
  221. \ '<denite:move_to_next_line>',
  222. \ 'noremap'
  223. \)
  224. call denite#custom#map(
  225. \ 'insert',
  226. \ '<C-k>',
  227. \ '<denite:move_to_previous_line>',
  228. \ 'noremap'
  229. \)
  230. let g:search_term = ''
  231. set viminfo^=h
  232. function! FindText()
  233. let g:search_term = input('Search for: ', '')
  234. if g:search_term != ''
  235. "exec ':/' . g:search_term . "\<CR>"
  236. "normal ':/' . g:search_term . "\<CR>"
  237. let @/ = g:search_term
  238. "execute 'normal /' . g:search_term . "\<CR>"
  239. "let @/ = '\<' . g:search_term . '\>'
  240. "let @/='\<<C-R>=expand("<' . g:search_term . '>")<CR>\>'<CR>:set hls<CR>
  241. "let g:highlighting = 1
  242. normal n
  243. "return ":silent set hlsearch\<CR>"
  244. endif
  245. endfunction
  246. map <leader>f :call FindText()<cr>
  247. nmap <C-f> ,f
  248. imap <C-f> <Esc>,f
  249. function! FindTextNext()
  250. if g:search_term != ''
  251. "exec ':/' . g:search_term . "<CR>"
  252. normal n
  253. endif
  254. endfunction
  255. nnoremap <F3> :call FindTextNext()<CR>
  256. " Add custom menus
  257. let s:menus = {}
  258. let s:menus.my_commands = {
  259. \ 'description': 'Example commands'
  260. \ }
  261. let s:menus.my_commands.command_candidates = [
  262. \ ['Split the window', 'vnew'],
  263. \ ['Set syntax: php', 'set filetype=php'],
  264. \ ['Set syntax: html', 'set filetype=html'],
  265. \ ['Set syntax: css', 'set filetype=css'],
  266. \ ['Set syntax: js', 'set filetype=js'],
  267. \ ['Show invisibles', 'set list'],
  268. \ ['Hide invisibles', 'set nolist'],
  269. \ ['Find in this file', 'call FindText()'],
  270. \ ['Find in files', 'CtrlP'],
  271. \ ['Remove Trailing Spaces', 'RemoveTrailingSpaces'],
  272. \ ]
  273. call denite#custom#var('menu', 'menus', s:menus)
  274. "nnoremap <silent>[menu]g :Unite -silent -start-insert menu:my_commands<CR>
  275. "nnoremap <Leader>c :<C-U>Denite menu:my_commands -start-insert -ignorecase<CR>
  276. nnoremap <Leader>p :Denite menu:my_commands -ignorecase<CR>
  277. nnoremap <C-P> :Denite menu:my_commands -ignorecase<CR>
  278. " ---- Minimap related ---- "
  279. let g:minimap_update='<leader>mu'
  280. let g:minimap_toggle='<leader>mt'