/vim_runtime/vimrcs/extended.vim

https://gitlab.com/lokiexinferis/vim-configs · Vim Script · 168 lines · 78 code · 33 blank · 57 comment · 6 complexity · c79bf19f842a63e2f87dcc501aa94df1 MD5 · raw file

  1. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  2. " Important:
  3. " This requries that you install https://github.com/amix/vimrc !
  4. "
  5. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  6. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  7. " => GUI related
  8. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  9. " Set font according to system
  10. if has("mac") || has("macunix")
  11. set gfn=IBM\ Plex\ Mono:h14,Hack:h14,Source\ Code\ Pro:h15,Menlo:h15
  12. elseif has("win16") || has("win32")
  13. set gfn=IBM\ Plex\ Mono:h14,Source\ Code\ Pro:h12,Bitstream\ Vera\ Sans\ Mono:h11
  14. elseif has("gui_gtk2")
  15. set gfn=IBM\ Plex\ Mono:h14,:Hack\ 14,Source\ Code\ Pro\ 12,Bitstream\ Vera\ Sans\ Mono\ 11
  16. elseif has("linux")
  17. set gfn=IBM\ Plex\ Mono:h14,:Hack\ 14,Source\ Code\ Pro\ 12,Bitstream\ Vera\ Sans\ Mono\ 11
  18. elseif has("unix")
  19. set gfn=Monospace\ 11
  20. endif
  21. " Disable scrollbars (real hackers don't use scrollbars for navigation!)
  22. set guioptions-=r
  23. set guioptions-=R
  24. set guioptions-=l
  25. set guioptions-=L
  26. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  27. " => Fast editing and reloading of vimrc configs
  28. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  29. map <leader>e :e! ~/.vim_runtime/my_configs.vim<cr>
  30. autocmd! bufwritepost ~/.vim_runtime/my_configs.vim source ~/.vim_runtime/my_configs.vim
  31. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  32. " => Turn persistent undo on
  33. " means that you can undo even when you close a buffer/VIM
  34. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  35. try
  36. set undodir=~/.vim_runtime/temp_dirs/undodir
  37. set undofile
  38. catch
  39. endtry
  40. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  41. " => Command mode related
  42. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  43. " Smart mappings on the command line
  44. cno $h e ~/
  45. cno $d e ~/Desktop/
  46. cno $j e ./
  47. cno $c e <C-\>eCurrentFileDir("e")<cr>
  48. " $q is super useful when browsing on the command line
  49. " it deletes everything until the last slash
  50. cno $q <C-\>eDeleteTillSlash()<cr>
  51. " Bash like keys for the command line
  52. cnoremap <C-A> <Home>
  53. cnoremap <C-E> <End>
  54. cnoremap <C-K> <C-U>
  55. cnoremap <C-P> <Up>
  56. cnoremap <C-N> <Down>
  57. " Map ½ to something useful
  58. map ½ $
  59. cmap ½ $
  60. imap ½ $
  61. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  62. " => Parenthesis/bracket
  63. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  64. vnoremap $1 <esc>`>a)<esc>`<i(<esc>
  65. vnoremap $2 <esc>`>a]<esc>`<i[<esc>
  66. vnoremap $3 <esc>`>a}<esc>`<i{<esc>
  67. vnoremap $$ <esc>`>a"<esc>`<i"<esc>
  68. vnoremap $q <esc>`>a'<esc>`<i'<esc>
  69. vnoremap $e <esc>`>a"<esc>`<i"<esc>
  70. " Map auto complete of (, ", ', [
  71. inoremap $1 ()<esc>i
  72. inoremap $2 []<esc>i
  73. inoremap $3 {}<esc>i
  74. inoremap $4 {<esc>o}<esc>O
  75. inoremap $q ''<esc>i
  76. inoremap $e ""<esc>i
  77. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  78. " => General abbreviations
  79. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  80. iab xdate <c-r>=strftime("%Y-%m-%d %H:%M:%S")<cr>
  81. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  82. " => Omni complete functions
  83. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  84. autocmd FileType css set omnifunc=csscomplete#CompleteCSS
  85. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  86. " => Ack searching and cope displaying
  87. " requires ack.vim - it's much better than vimgrep/grep
  88. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  89. " Use the the_silver_searcher if possible (much faster than Ack)
  90. if executable('ag')
  91. let g:ackprg = 'ag --vimgrep --smart-case'
  92. endif
  93. " When you press gv you Ack after the selected text
  94. vnoremap <silent> gv :call VisualSelection('gv', '')<CR>
  95. " Open Ack and put the cursor in the right position
  96. map <leader>ack :Ack
  97. " When you press <leader>r you can search and replace the selected text
  98. vnoremap <silent> <leader>r :call VisualSelection('replace', '')<CR>
  99. " Do :help cope if you are unsure what cope is. It's super useful!
  100. "
  101. " When you search with Ack, display your results in cope by doing:
  102. " <leader>cc
  103. "
  104. " To go to the next search result do:
  105. " <leader>n
  106. "
  107. " To go to the previous search results do:
  108. " <leader>p
  109. "
  110. map <leader>cc :botright cope<cr>
  111. map <leader>co ggVGy:tabnew<cr>:set syntax=qf<cr>pgg
  112. map <leader>n :cn<cr>
  113. map <leader>p :cp<cr>
  114. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  115. " => Helper functions
  116. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  117. func! DeleteTillSlash()
  118. let g:cmd = getcmdline()
  119. if has("win16") || has("win32")
  120. let g:cmd_edited = substitute(g:cmd, "\\(.*\[\\\\]\\).*", "\\1", "")
  121. else
  122. let g:cmd_edited = substitute(g:cmd, "\\(.*\[/\]\\).*", "\\1", "")
  123. endif
  124. if g:cmd == g:cmd_edited
  125. if has("win16") || has("win32")
  126. let g:cmd_edited = substitute(g:cmd, "\\(.*\[\\\\\]\\).*\[\\\\\]", "\\1", "")
  127. else
  128. let g:cmd_edited = substitute(g:cmd, "\\(.*\[/\]\\).*/", "\\1", "")
  129. endif
  130. endif
  131. return g:cmd_edited
  132. endfunc
  133. func! CurrentFileDir(cmd)
  134. return a:cmd . " " . expand("%:p:h") . "/"
  135. endfunc