.vimrc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. " Permit use of the mouse.
  2. set mouse=a
  3. set fileformat=unix
  4. set fileformats=unix
  5. set sidescroll=1
  6. " All teh opsec
  7. set cryptmethod=blowfish2
  8. set nomodeline
  9. " Automatically deal with valid filetypes.
  10. filetype on
  11. filetype plugin on
  12. filetype indent on
  13. "Set indentation behaviour."
  14. set autoindent
  15. set expandtab
  16. set smarttab
  17. set tabstop=4
  18. set softtabstop=4
  19. set shiftwidth=4
  20. set shiftround
  21. " Override that tab behavior for certain directories
  22. autocmd BufRead,BufNewFile ~/src/gnu/datamash/* setlocal ts=2 sw=2 sts=2
  23. " ins-completion and popup menu
  24. set completeopt=menuone,popup,noinsert
  25. " When navigating word-wise, don't treat underscores as internal characters.
  26. set iskeyword-=_
  27. " However, restore _ when autocompleting
  28. " https://www.reddit.com/r/vim/comments/22431a/i_ctrln_the_motion_w_and_iskeyword/
  29. autocmd! InsertLeave <buffer> :set iskeyword-=_
  30. autocmd! InsertEnter <buffer> :set iskeyword+=_
  31. " Don't put two spaces between sentences!
  32. set nojoinspaces
  33. " Disable adding eol at eof
  34. set nofixeol
  35. set equalprg=jq\ .
  36. "Reduce the interference created by running shell commands.
  37. " Ref h: press-enter, h: shortmess
  38. set shortmess=aoOtTW
  39. " Ensure backspace works as intended regardless of what is default
  40. " Ref: http://vim.wikia.com/wiki/Backspace_and_delete_problems
  41. set backspace=indent,eol,start
  42. "Set the print header. See help: statusline for explanation of symbols."
  43. set printheader=%F%=%-%Page\ %N
  44. "Statusline
  45. set statusline=%<0x%B\ %=\ %l,%c%V\ %P
  46. set laststatus=2
  47. "Set up folding.
  48. " Ref https://vi.stackexchange.com/a/8671
  49. set foldmethod=indent
  50. function AutoFold()
  51. if line('$') > 30
  52. set foldlevel=0
  53. elseif line('$') > 20
  54. set foldlevel=1
  55. elseif line('$') > 10
  56. set foldlevel=2
  57. else
  58. set foldlevel=3
  59. endif
  60. endfunction
  61. autocmd! BufReadPost * call AutoFold()
  62. " Suppress W16 warnings.
  63. set autoread
  64. " Preserve undo history when switching buffers.
  65. set hidden
  66. " Control what information gets preserved between sessions
  67. set viminfo='128,<64,s32,h
  68. set viminfofile=~/.vim/info
  69. " Restore last known cursor position:
  70. function! RestoreCursor()
  71. if line("'\"") <= line("$")
  72. normal! g`"
  73. return 1
  74. endif
  75. endfunction
  76. augroup resCur
  77. autocmd!
  78. autocmd BufWinEnter * call RestoreCursor()
  79. augroup END
  80. " Don't continue commenting on new lines.
  81. " Ref: http://vim.wikia.com/wiki/Disable_automatic_comment_insertion
  82. augroup vimrc
  83. autocmd!
  84. autocmd FileType * setlocal formatoptions-=r formatoptions-=o
  85. augroup END
  86. " If file is readonly disable modifications
  87. " Ref: http://vim.wikia.com/wiki/Make_buffer_modifiable_state_match_file_readonly_state
  88. function UpdateModifiable()
  89. if !exists("b:setmodifiable")
  90. let b:setmodifiable = 0
  91. endif
  92. if &readonly
  93. if &modifiable
  94. setlocal nomodifiable
  95. let b:setmodifiable = 1
  96. endif
  97. else
  98. if b:setmodifiable
  99. setlocal modifiable
  100. endif
  101. endif
  102. endfunction
  103. autocmd BufReadPost * call UpdateModifiable()
  104. " Prefill registers
  105. let @d = strftime("%F")
  106. let @s = '¯\_(ツ)_/¯'
  107. set clipboard-=autoselect
  108. if $DISPLAY == "" || !has('x11')
  109. set mouse="r"
  110. endif
  111. " If the parent directory did not exist, it would be necessary to invent it
  112. " Ref: https://vi.stackexchange.com/a/679
  113. function MkdirFunction(dir)
  114. if empty(a:dir) || isdirectory(a:dir)
  115. return
  116. else
  117. call mkdir(a:dir)
  118. endif
  119. endfunction
  120. augroup MkdirGroup
  121. autocmd!
  122. autocmd BufWritePre * call MkdirFunction(expand("<afile>:p:h"))
  123. augroup END
  124. " Silence E173
  125. " https://vi.stackexchange.com/a/31461/18583
  126. autocmd QuitPre * qa
  127. set updatetime=500
  128. runtime helpers/theme.vim
  129. runtime helpers/airline_config.vim
  130. runtime helpers/gitgutter_config.vim
  131. runtime helpers/ale_config.vim
  132. runtime helpers/Mappings.vim
  133. runtime helpers/Operators.vim
  134. runtime helpers/cmdwin_config.vim
  135. if exists('+packages')
  136. packload
  137. silent! helptags ALL
  138. endif