vimrc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. unlet! skip_defaults_vim
  2. runtime defaults.vim
  3. " To make 3rd party includes
  4. set foldmethod=marker
  5. " Enable syntax and plugins
  6. syntax enable
  7. filetype indent plugin on
  8. nnoremap <LEADER>gid :read !date +\%Y-\%m-\%d<CR>kJ
  9. " Plugins {{{
  10. call plug#begin()
  11. Plug 'OmniSharp/omnisharp-vim' " After :PlugInstall do :OmnisharpInstall
  12. Plug 'dense-analysis/ale'
  13. call plug#end()
  14. " }}}
  15. " Personal {{{
  16. " Looks {{{
  17. function! ConfigPresent()
  18. " Settings for presentation mode
  19. set nonumber norelativenumber
  20. endfunction
  21. function! ConfigNoPresent()
  22. " Settings for non-presentation mode
  23. set number relativenumber
  24. endfunction
  25. nnoremap <Leader>gp :call ConfigPresent()<CR>
  26. nnoremap <Leader>gP :call ConfigNoPresent()<CR>
  27. " Window title reflects document title
  28. set title
  29. " Ye olde faithful
  30. set textwidth=80
  31. " HUD {{{
  32. set hlsearch incsearch
  33. call ConfigNoPresent()
  34. set ruler
  35. set showcmd
  36. " }}}
  37. " Spaces instead of TABs :( {{{
  38. set expandtab " Use spaces instead of tab characters
  39. set shiftround
  40. set shiftwidth=4 " Number of spaces to use for each step of (auto)indent
  41. set softtabstop=4 " Number of spaces that a Tab key press is equivalent to
  42. set softtabstop=-1 " When 'sts' is negative, the value of 'shiftwidth' is used.
  43. set tabstop=6 " Make TAB char more obvious
  44. set tabstop=6 " Number of spaces that a tab character represents
  45. " }}}
  46. " }}}
  47. " Feels {{{
  48. set iskeyword-=_ " Don't skip over _
  49. " Search subdirectories
  50. " Provides tab-complete for all file-related tasks
  51. set path+=**
  52. " Display all matching files when we tab complete
  53. " instead of cycling through completions
  54. set wildmenu
  55. " UTF-8 everywhere
  56. set encoding=utf-8
  57. scriptencoding utf-8
  58. " Copy Pasta {{{
  59. " Registers
  60. "
  61. function! RegisterSwapDefaultWith()
  62. " Swap the default register with the contents of another
  63. let l = nr2char(getchar())
  64. execute 'let @x=@' . l . '| let @' . l . '=@" | let @"=@x'
  65. endfunction
  66. nnoremap <Leader>c :call RegisterSwapDefaultWith()<CR>
  67. nnoremap <Leader>C :call RegisterSwapDefaultWith()<CR>+
  68. "
  69. " (visual) <LEADER>ca := swap contents of default register (") with register a
  70. " (visual) <LEADER>C := swap contents of default register with clipboard (+)
  71. " }}}
  72. " Case {{{
  73. " Uppercase/Lowercase
  74. "
  75. " (visual) gu := lowercase selection
  76. " (normal) guu := lowercase line
  77. " (visual) gU := uppercase selection
  78. " (normal) gUU := uppercase line
  79. " Title Case
  80. "
  81. vnoremap gt :s/\%V\v<(.)(\w*)/\u\1\L\2/g<CR>:noh<CR>
  82. nnoremap gtt V:s/\v<(.)(\w*)/\u\1\L\2/g<CR>:noh<CR>
  83. "
  84. " (visual) gt := titlecase selection
  85. " (normal) gtt := titlecase line
  86. " }}}
  87. " Quote {{{
  88. function! SelectionSurroundWith()
  89. " Surround selected text with a single char
  90. let open = nr2char(getchar())
  91. let pairs = {'(': ')', '[': ']', '{': '}', '<': '>'}
  92. let close = get(pairs, open, open)
  93. execute "normal! gvc" . open . "\<C-r>\"" . close . "\<Esc>"
  94. endfunction
  95. vnoremap gi :<C-u>call SelectionSurroundWith()<CR>
  96. "
  97. " (visual) gi" := surround selection with quotes (")
  98. " (visual) gi{ := surround selection with braces ({})
  99. " }}}
  100. " Autoformatting (to be tested) {{{
  101. "set formatoptions+=c
  102. "set formatoptions+=n
  103. "set formatoptions+=q
  104. "set formatoptions+=r
  105. " }}}
  106. " }}}
  107. " C#/.NET specific settings {{{
  108. " Enable OmniSharp for C# files
  109. autocmd FileType cs setlocal omnifunc=OmniSharp#Complete
  110. " Optional: Key mappings {{{
  111. augroup omnisharp_commands
  112. autocmd!
  113. " Show type information automatically when the cursor stops moving.
  114. " Note that the type is echoed to the Vim command line, and will overwrite
  115. " any other messages in this space including e.g. ALE linting messages.
  116. autocmd CursorHold *.cs OmniSharpTypeLookup
  117. " The following commands are contextual, based on the cursor position.
  118. autocmd FileType cs nmap <silent> <buffer> gd <Plug>(omnisharp_go_to_definition)
  119. autocmd FileType cs nmap <silent> <buffer> <Leader>U <Plug>(omnisharp_find_usages)
  120. autocmd FileType cs nmap <silent> <buffer> <Leader>osfi <Plug>(omnisharp_find_implementations)
  121. autocmd FileType cs nmap <silent> <buffer> <Leader>ospd <Plug>(omnisharp_preview_definition)
  122. autocmd FileType cs nmap <silent> <buffer> <Leader>ospi <Plug>(omnisharp_preview_implementations)
  123. " autocmd FileType cs nmap <silent> <buffer> <Leader>ost <Plug>(omnisharp_type_lookup)
  124. autocmd FileType cs nmap <silent> <buffer> K <Plug>(omnisharp_documentation)
  125. " autocmd FileType cs nmap <silent> <buffer> <Leader>osfs <Plug>(omnisharp_find_symbol)
  126. autocmd FileType cs nmap <silent> <buffer> <Leader>F <Plug>(omnisharp_fix_usings)
  127. " autocmd FileType cs nmap <silent> <buffer> <C-\> <Plug>(omnisharp_signature_help)
  128. " autocmd FileType cs imap <silent> <buffer> <C-\> <Plug>(omnisharp_signature_help)
  129. "
  130. " " Navigate up and down by method/property/field
  131. " autocmd FileType cs nmap <silent> <buffer> [[ <Plug>(omnisharp_navigate_up)
  132. " autocmd FileType cs nmap <silent> <buffer> ]] <Plug>(omnisharp_navigate_down)
  133. " " Find all code errors/warnings for the current solution and populate the quickfix window
  134. " autocmd FileType cs nmap <silent> <buffer> <Leader>osgcc <Plug>(omnisharp_global_code_check)
  135. " " Contextual code actions (uses fzf, vim-clap, CtrlP or unite.vim selector when available)
  136. " autocmd FileType cs nmap <silent> <buffer> <Leader>osca <Plug>(omnisharp_code_actions)
  137. " autocmd FileType cs xmap <silent> <buffer> <Leader>osca <Plug>(omnisharp_code_actions)
  138. " " Repeat the last code action performed (does not use a selector)
  139. " autocmd FileType cs nmap <silent> <buffer> <Leader>os. <Plug>(omnisharp_code_action_repeat)
  140. " autocmd FileType cs xmap <silent> <buffer> <Leader>os. <Plug>(omnisharp_code_action_repeat)
  141. "
  142. " autocmd FileType cs nmap <silent> <buffer> <Leader>os= <Plug>(omnisharp_code_format)
  143. "
  144. autocmd FileType cs nmap <silent> <buffer> <Leader>R <Plug>(omnisharp_rename)
  145. "
  146. " autocmd FileType cs nmap <silent> <buffer> <Leader>osre <Plug>(omnisharp_restart_server)
  147. " autocmd FileType cs nmap <silent> <buffer> <Leader>osst <Plug>(omnisharp_start_server)
  148. " autocmd FileType cs nmap <silent> <buffer> <Leader>ossp <Plug>(omnisharp_stop_server)
  149. autocmd FileType cs nmap <silent> <buffer> <Leader>T <Plug>(omnisharp_run_tests_in_file)
  150. autocmd FileType cs nmap <silent> <buffer> <Leader>t <Plug>(omnisharp_run_test)
  151. augroup END
  152. " }}}
  153. " Settings: {{{
  154. set completeopt=menuone,noinsert,noselect,popuphidden
  155. set completepopup=highlight:Pmenu,border:off
  156. set backspace=indent,eol,start
  157. set hidden
  158. set nofixendofline
  159. set nostartofline
  160. set splitbelow
  161. set splitright
  162. set laststatus=2
  163. set showmode
  164. set signcolumn=yes
  165. set mouse=a
  166. set updatetime=1000
  167. " }}}
  168. " }}}
  169. " }}}
  170. " 3rd Party {{{
  171. " Max Cantor {{{
  172. "
  173. " Copied from https://github.com/changemewtf/no_plugins/blob/master/no_plugins.vim
  174. "
  175. " HOW TO DO 90% OF WHAT PLUGINS DO (WITH JUST VIM)
  176. " Max Cantor
  177. " NYC Vim Meetup -- August 3, 2016
  178. " FEATURES TO COVER:
  179. " - Fuzzy File Search
  180. " - Tag jumping
  181. " - Autocomplete
  182. " - File Browsing
  183. " - Snippets
  184. " - Build Integration (if we have time)
  185. " GOALS OF THIS TALK:
  186. " - Increase Vim understanding
  187. " - Offer powerful options
  188. " NOT GOALS OF THIS TALK:
  189. " - Hate on plugins
  190. " - Get people to stop using plugins
  191. " {{{ BASIC SETUP
  192. " BASIC SETUP:
  193. " enter the current millenium
  194. set nocompatible
  195. " enable syntax and plugins (for netrw)
  196. syntax enable
  197. filetype plugin on
  198. " }}}
  199. " FINDING FILES: {{{
  200. " Search down into subfolders
  201. " Provides tab-completion for all file-related tasks
  202. set path+=**
  203. " Display all matching files when we tab complete
  204. set wildmenu
  205. " NOW WE CAN:
  206. " - Hit tab to :find by partial match
  207. " - Use * to make it fuzzy
  208. " THINGS TO CONSIDER:
  209. " - :b lets you autocomplete any open buffer
  210. " }}}
  211. " TAG JUMPING: {{{
  212. " Create the `tags` file (may need to install ctags first)
  213. command! MakeTags !ctags -R .
  214. " NOW WE CAN:
  215. " - Use ^] to jump to tag under cursor
  216. " - Use g^] for ambiguous tags
  217. " - Use ^t to jump back up the tag stack
  218. " THINGS TO CONSIDER:
  219. " - This doesn't help if you want a visual list of tags
  220. " }}}
  221. " AUTOCOMPLETE: {{{
  222. " The good stuff is documented in |ins-completion|
  223. " HIGHLIGHTS:
  224. " - ^x^n for JUST this file
  225. " - ^x^f for filenames (works with our path trick!)
  226. " - ^x^] for tags only
  227. " - ^n for anything specified by the 'complete' option
  228. " NOW WE CAN:
  229. " - Use ^n and ^p to go back and forth in the suggestion list
  230. " }}}
  231. " FILE BROWSING: {{{
  232. " Tweaks for browsing
  233. let g:netrw_banner=0 " disable annoying banner
  234. let g:netrw_browse_split=4 " open in prior window
  235. let g:netrw_altv=1 " open splits to the right
  236. let g:netrw_liststyle=3 " tree view
  237. let g:netrw_list_hide=netrw_gitignore#Hide()
  238. let g:netrw_list_hide.=',\(^\|\s\s\)\zs\.\S\+'
  239. " NOW WE CAN:
  240. " - :edit a folder to open a file browser
  241. " - <CR>/v/t to open in an h-split/v-split/tab
  242. " - check |netrw-browse-maps| for more mappings
  243. " }}}
  244. " SNIPPETS: {{{
  245. " Read an empty HTML template and move cursor to title
  246. nnoremap ,html :-1read $HOME/.vim/.skeleton.html<CR>3jwf>a
  247. " NOW WE CAN:
  248. " - Take over the world!
  249. " (with much fewer keystrokes)
  250. " }}}
  251. " BUILD INTEGRATION: {{{
  252. " Steal Mr. Bradley's formatter & add it to our spec_helper
  253. " http://philipbradley.net/rspec-into-vim-with-quickfix
  254. " Configure the `make` command to run RSpec
  255. set makeprg=bundle\ exec\ rspec\ -f\ QuickfixFormatter
  256. " NOW WE CAN:
  257. " - Run :make to run RSpec
  258. " - :cl to list errors
  259. " - :cc# to jump to error by number
  260. " - :cn and :cp to navigate forward and back
  261. " }}}
  262. " THANK YOU!
  263. " Download this file at:
  264. " github.com/mcantor/no_plugins
  265. " Follow me for kitten pictures:
  266. " twitter.com/mcantor
  267. " Contact me at `max at maxcantor dot net` for:
  268. " - Consulting (Dev and PM)
  269. " - Tutoring
  270. " - Classroom Teaching
  271. " - Internal Training
  272. " - Encouragement
  273. " }}}
  274. " ALE {{{
  275. let g:ale_linters = {
  276. \ 'cs': ['OmniSharp']
  277. \}
  278. let g:ale_fixers = { 'cs': [ 'dotnet-format' ] }
  279. let g:ale_set_quickfix = 0
  280. let g:ale_set_loclist = 1
  281. " }}}
  282. " OmniSharp: {{{
  283. let g:OmniSharp_popup_position = 'peek'
  284. if has('nvim')
  285. let g:OmniSharp_popup_options = {
  286. \ 'winblend': 30,
  287. \ 'winhl': 'Normal:Normal,FloatBorder:ModeMsg',
  288. \ 'border': 'rounded'
  289. \}
  290. else
  291. let g:OmniSharp_popup_options = {
  292. \ 'highlight': 'Normal',
  293. \ 'padding': [1],
  294. \ 'border': [1],
  295. \ 'borderchars': ['─', '│', '─', '│', '╭', '╮', '╯', '╰'],
  296. \ 'borderhighlight': ['Special']
  297. \}
  298. endif
  299. let g:OmniSharp_popup_mappings = {
  300. \ 'sigNext': '<C-n>',
  301. \ 'sigPrev': '<C-p>',
  302. \ 'pageDown': ['<C-f>', '<PageDown>'],
  303. \ 'pageUp': ['<C-b>', '<PageUp>']
  304. \}
  305. let g:OmniSharp_highlight_groups = {
  306. \ 'ExcludedCode': 'NonText'
  307. \}
  308. " }}}
  309. " }}}
  310. " Restore some things Max Cantor changed
  311. unlet g:netrw_banner
  312. " Restore some other defaults that got disabled
  313. set showcmd
  314. " Clear search highlight after sourcing
  315. silent! call feedkeys(":nohlsearch\<CR>")
  316. " Fix CTRL-] suppressed on Alacritty for Windows
  317. nnoremap <LEADER><TAB> <C-]>
  318. " Make navigation a bit easier on Colemak
  319. set langmap=jk,kj