Thedro's Dotfiles https://www.thedroneely.com
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.

364 lines
13KB

  1. " Clear all mappings.
  2. mapclear
  3. " Add match tag pairs package.
  4. packadd! matchit
  5. " Do not load defaults if ~/.vimrc is missing.
  6. let skip_defaults_vim=1
  7. " Source plugins.
  8. so ~/.vim/plugins.vim
  9. "------------General Settings------------"
  10. let mapleader = "\<space>" " Set default map leader.
  11. syntax enable " Enable syntax highlighting.
  12. set ruler " Show the cursor position all the time.
  13. set nowrap " Do not wrap lines.
  14. set nonumber " Set line numbers.
  15. set hlsearch " Enable search.
  16. set incsearch " Set incremental search.
  17. set showmatch " Briefly show matching tags.
  18. set nocompatible " Use Vim defaults.
  19. set splitbelow " Open horizontal splits below.
  20. set splitright " Open vertical splits to the right.
  21. set cursorline " Set cursor line highlight.
  22. set notimeout " Wait indefinitely for complete key combinations.
  23. set ttimeout " Prevent pressing <Esc> twice.
  24. set showcmd " Show key presses in status line.
  25. set path+=** " Search subfolders.
  26. set wildmenu " Show tab completions menu.
  27. set display=lastline " @@@ indicates remaining line is not displayed.
  28. set hidden " Set hidden buffers.
  29. set nobackup " No write backups.
  30. set noswapfile " Disable swap files.
  31. set nowritebackup " No overwrite backups.
  32. set autoread " Auto read file on external change.
  33. set autowrite " Write if modified.
  34. set autowriteall " Write if modified on buffer change.
  35. set autoindent " Copy indent from current line to new line.
  36. set ignorecase " Ignore case on search.
  37. set smartcase " Search by case smartly.
  38. set lazyredraw " Do not redraw screen when using macros.
  39. set undofile " Enable undofile.
  40. set viminfo+=n~/.vim/viminfo " Set viminfo file path.
  41. set undodir=~/.vim/undodir " Set undofile directory.
  42. set mouse=a " Enable mouse.
  43. set shortmess+=I " Disable startup message.
  44. set showtabline=0 " Disable tab bar.
  45. set updatetime=1500 " Set duration for cursor hold event.
  46. set fillchars= " Set split window margin fill to none.
  47. set laststatus=0 " Disable status bar.
  48. set linespace=3 " Set line spaces.
  49. set guiheadroom=0 " Disable headroom on window maximize.
  50. set history=50 " Keep 50 lines of command line history.
  51. set clipboard=unnamed " Use clipboard as default register.
  52. set backspace=indent,eol,start " Enable backspacing.
  53. set formatoptions-=t " Do not auto wrap text when typing.
  54. set complete=.,w,b,u " Set our desired autocompletion match pattern.
  55. set encoding=utf-8 " Set UTF-8 encoding.
  56. set scrolloff=3 " Set vertical scroll headroom.
  57. set sidescroll=3 " Set horizontal column scroll.
  58. set sidescrolloff=10 " Set horizontal scroll headroom.
  59. " Convert tab to spaces.
  60. set tabstop=2 softtabstop=0 shiftwidth=2 smarttab expandtab
  61. " Highlight HTML and SQL in PHP.
  62. let php_sql_query = 1
  63. let php_htmlInStrings = 1
  64. " Highlight JavaScript
  65. let g:javascript_plugin_jsdoc = 1
  66. "----------------Visuals----------------"
  67. " Set color scheme.
  68. colorscheme fluid
  69. " Remove scrollbars in gui.
  70. set guioptions-=l
  71. set guioptions-=L
  72. set guioptions-=r
  73. set guioptions-=R
  74. " Remove menubar, toolbar, and tabs in gui.
  75. set guioptions-=m
  76. set guioptions-=T
  77. set guioptions-=e
  78. " Set fold column
  79. set foldcolumn=2
  80. "---------------Functions---------------"
  81. " PHP Fixer
  82. function! PHPFix()
  83. :silent !notify-send "$(phpcbf % 2>&1)"
  84. :redraw!
  85. endfunction
  86. " HTML Beautify
  87. function! HTMLBeautify()
  88. :silent !notify-send "$(prettier --write --parser html % 2>&1)"
  89. :redraw!
  90. endfunction
  91. " CSS Beautify
  92. function! CSSBeautify()
  93. :silent !notify-send "$(prettier --write --parser css %)"
  94. endfunction
  95. " ESLint Fix
  96. function! ESLintFix()
  97. :silent !notify-send -t 10000 "$(eslint -c $HOME/.config/eslintrc.yml --fix %)" >/dev/null 2>&1
  98. endfunction
  99. " Ansible Check
  100. function! AnsibleCheck()
  101. :silent !notify-send -t 10000 "$(ansible-playbook --syntax-check % 2>&1)" &
  102. endfunction
  103. " Shell Check
  104. function! ShellCheck()
  105. :silent !notify-send -t 10000 "$(shellcheck -x --exclude=SC1090,SC1091 % && echo 'Shellcheck OK: %')" >/dev/null 2>&1 &
  106. endfunction
  107. " Nix Check
  108. function! NixCheck()
  109. :silent !notify-send -t 10000 "$(nix-linter % 2>&1 && echo 'Nix Lint OK: %' && nixfmt %)" >/dev/null 2>&1
  110. :redraw!
  111. endfunction
  112. " Elixir Format
  113. function! ElixirFormat()
  114. :silent !notify-send -t 10000 "$(mix format % 2>&1 && echo 'Elixir Format OK: %')" >/dev/null 2>&1
  115. :redraw!
  116. endfunction
  117. "---------------Shortcuts---------------"
  118. " Edit shortcuts
  119. nmap <leader>ev :tabedit ~/.vimrc<cr>
  120. nmap <leader>ep :tabedit ~/.vim/plugins.vim<cr>
  121. nmap <leader>eh :tabedit ~/.vim/post-save-hook<cr>
  122. " Git, tags, and help commands
  123. nmap <leader>fgf :GFiles<cr>
  124. nmap <leader>fgs :GFiles?<cr>
  125. nmap <leader>fgc :Commits<cr>
  126. nmap <leader>ftb :BTags<cr>
  127. nmap <leader>flh :Helptags<cr>
  128. nmap <leader>flc :Commands<cr>
  129. " Show key mappings
  130. nmap <leader>mm :Maps<cr>
  131. nmap <leader>ma :Marks<cr>
  132. " Search documentation under cursor
  133. nmap <leader>dm :exe ':term ++close fzf-man ' . expand('<cword>')<cr>
  134. nmap <leader>di :exe ':term ++close fzf-doc ' . expand('<cword>')<cr>
  135. nmap <leader>dt :exe ':term dict -h localhost -d dict-moby-thesaurus-latest ' . expand('<cword>')<cr>
  136. " View function documentation
  137. nmap <leader>dp :call fzf#run({'options': ['--preview', 'echo doc {} \| psysh \| fold -s -w 80'], 'source': "psysh-doc", 'sink': ':term psysh-doc', 'down': '50%'})<cr>
  138. " Jump to line
  139. nmap <leader>jl :norm yaW<cr> \| :Jump<cr>
  140. " Load and save sessions
  141. nmap <leader>sl :source ~/.vim/sessions/session.vim \| :source ~/.vimrc<cr>
  142. nmap <leader>ss :silent! exe "!~/.vim/hooks/pre-session-save && notify-send 'Vim session saved.'" \| :mksession! ~/.vim/sessions/session.vim \| :redraw!<cr>
  143. " Toggle Spell Check
  144. nmap <leader>sp :set spell!<cr>
  145. " Sort lines by length
  146. vnoremap <leader>sn !perl -e 'print sort { length($a) <=> length($b) } <>'<cr>
  147. " Switch between tabs and spaces
  148. nmap <leader>ses :set tabstop=2 softtabstop=0 shiftwidth=2 smarttab expandtab \| :%retab!<cr>
  149. nmap <leader>set :set tabstop=2 softtabstop=0 shiftwidth=2 smarttab noexpandtab \| :%retab!<cr>
  150. " Close buffer and window
  151. nmap <leader>q :bd<cr>
  152. nmap <leader>w <C-w>c<cr>
  153. " Linting shortcuts
  154. nmap <leader>lph :call HTMLBeautify()<cr>
  155. nmap <leader>lpc :call CSSBeautify()<cr>
  156. " Re-indent entire file
  157. nmap <leader>re gg=G<C-o><C-o>
  158. " Reset all settings and source configuration.
  159. nmap <leader>ra :set all& \| :source ~/.vimrc \| :e<cr>
  160. " Remove duplicate lines
  161. vnoremap <leader>rd !awk '\!visited[$0]++'<cr>
  162. " Toggle color column
  163. nmap <leader>cv :exe "set colorcolumn=" . (&colorcolumn == "" ? "80" : "")<cr>
  164. " Toggle cursor column
  165. nmap <leader>cx :set cursorcolumn!<cr>
  166. " Justify columns
  167. vnoremap <leader>ct !column -t -o' '<cr>
  168. " File open mappings
  169. nmap <Tab> :Buffers<cr>
  170. nmap <leader>ov :Lines<cr>
  171. nmap <leader>ob :BLines<cr>
  172. nmap <leader>op :History<cr>
  173. nmap <leader>oc :History:<cr>
  174. nmap <leader>ol :Locate<space>
  175. nmap <leader>ot :exe '! urxvt -cd ' . expand('%:p:h') . ' &'<cr><cr>
  176. nmap <leader>of :call fzf#run({'options': [], 'source': "cat $FZF_FILE_MARKS", 'sink': 'e', 'down': '20%'})<cr>:pwd<cr>
  177. nmap <leader>od :call fzf#run({'options': ['--preview', 'ls {}'], 'source': "cut -d' ' -f3 $FZF_DIRECTORY_MARKS", 'sink': 'cd', 'down': '20%'})<cr>:pwd<cr>
  178. nmap <leader>oo :call fzf#run({'options': ['--preview', 'highlight -O ansi --force {}'], 'source': 'rg --files --hidden \|\| find . -type f -printf "%P\n"', 'sink': 'e', 'down': '20%'})<cr>
  179. " Mappings for nnn
  180. nmap <leader>nm :NnnPicker<cr>
  181. nmap <leader>nn :NnnPicker '%:p:h'<cr>
  182. " Exit incremental search
  183. nmap <Esc><Esc> :nohl<cr>
  184. " Disable Ex Mode
  185. nnoremap Q <Nop>
  186. " Split window mappings
  187. nmap <Bslash> :vsplit<cr>
  188. nmap <C-Bslash> :split<cr>
  189. nmap <C-j> :resize +5<cr>
  190. nmap <C-k> :resize -5<cr>
  191. nmap <C-h> :vertical resize +5<cr>
  192. nmap <C-l> :vertical resize -5<cr>
  193. " Inverse Tabs
  194. inoremap <S-Tab> <C-d>
  195. " Retain visual selection when tabbing
  196. vnoremap < <gv
  197. vnoremap > >gv
  198. " Prevent cursor from jumping in visual select context https://ddrscott.github.io/blog/2016/yank-without-jank/
  199. vnoremap <expr>y "my\"" . v:register . "y`y"
  200. "---------------Plugin Settings---------------"
  201. " netrw settings
  202. let g:netrw_banner=0
  203. " nnn settings
  204. let g:nnn#command = 'nnn -H' " Override default command
  205. let g:nnn#set_default_mappings = 0 " Disable default mappings
  206. let g:nnn#layout = 'new' " Opens the nnn window in a split
  207. let g:nnn#layout = { 'left': '~20%' } " Left 20% of the window
  208. "-------------------Scripts-------------------"
  209. " https://vi.stackexchange.com/questions/14300/vim-how-to-send-entire-line-to-a-buffer-of-type-terminal
  210. function s:repl(start, end, language)
  211. let g:terminal_buffer = get(g:, 'terminal_buffer', -1)
  212. if g:terminal_buffer == -1 || !bufexists(g:terminal_buffer)
  213. terminal ++rows=10
  214. let g:terminal_buffer = bufnr('')
  215. call term_sendkeys(g:terminal_buffer, a:language . "; exit" . "\<cr>")
  216. wincmd p
  217. elseif bufwinnr(g:terminal_buffer) == -1
  218. exe 'sbuffer ' . g:terminal_buffer
  219. wincmd p
  220. endif
  221. call term_sendkeys(g:terminal_buffer, join(getline(a:start, a:end), "\<cr>") . "\<cr>")
  222. endfunction
  223. " jump to line and column in the format 123:13
  224. function s:cursor(selection)
  225. wincmd p
  226. let g:cursor_request = split(a:selection, ":")
  227. call cursor(g:cursor_request[0], g:cursor_request[1])
  228. endfunction
  229. command! -nargs=? -range Jump call s:cursor(@*)
  230. command! -nargs=? -range REPL call s:repl(<line1>, <line2>, <f-args>)
  231. "----------------Autorun----------------"
  232. augroup AutoCommands
  233. " Clear auto commands.
  234. autocmd!
  235. " Reload vimrc on vimrc file save.
  236. autocmd BufWritePost .vimrc source % | silent !notify-send 'Sourcing vimrc...'
  237. " Reload plugins.vim on file save.
  238. autocmd BufWritePost plugins.vim source % | silent !notify-send 'Sourcing plugins...'
  239. " Linting extension post write commands.
  240. autocmd BufWritePost *.php :call PHPFix()
  241. autocmd BufWritePost *.js :call ESLintFix()
  242. autocmd BufWritePost *.yml :call AnsibleCheck()
  243. autocmd BufWritePost *.txt,*.md :only | :term ++rows=10 vale-wrapper %
  244. " Linting file type post write commands.
  245. autocmd FileType bash,sh autocmd! BufWritePost <buffer> :call ShellCheck()
  246. autocmd FileType nix autocmd! BufWritePost <buffer> silent call NixCheck()
  247. autocmd FileType elixir autocmd! BufWritePost <buffer> :call ElixirFormat()
  248. autocmd FileType awk autocmd! BufWritePost <buffer> silent !notify-send "$(awk -g -f % 2>&1 && awk -o- -f % | sponge % && echo 'awk OK:' %)"
  249. autocmd FileType rust autocmd! BufWritePost <buffer> silent !notify-send "$(rustfmt % 2>&1 && echo 'rustfmt OK:' %)"
  250. " File type function under cursor lookups.
  251. autocmd FileType elixir noremap <buffer> <leader>df :exe ':term ++rows=10 sh -c "echo ''h(' . expand('<cexpr>') . ')'' \| iex"'<cr>
  252. autocmd FileType nix noremap <buffer> <leader>df :exe ':term ++rows=10 nixos-option ' . expand('<cexpr>')<cr>
  253. " REPL commands.
  254. autocmd FileType go noremap <buffer> <leader>cc :REPL gore<cr>
  255. autocmd FileType lua noremap <buffer> <leader>cc :REPL lua<cr>
  256. autocmd FileType php noremap <buffer> <leader>cc :REPL psysh<cr>
  257. autocmd FileType elixir noremap <buffer> <leader>cc :REPL iex<cr>
  258. autocmd FileType sh noremap <buffer> <leader>cc :REPL dash -x<cr>
  259. autocmd FileType rust noremap <buffer> <leader>cc :REPL evcxr<cr>
  260. autocmd FileType nix noremap <buffer> <leader>cc :REPL nix repl<cr>
  261. autocmd FileType bash noremap <buffer> <leader>cc :REPL bash -x<cr>
  262. autocmd FileType python noremap <buffer> <leader>cc :REPL python<cr>
  263. autocmd FileType perl noremap <buffer> <leader>cc :REPL perl -de0<cr>
  264. autocmd FileType javascript noremap <buffer> <leader>cc :REPL node<cr>
  265. autocmd FileType awk noremap <buffer> <leader>cc :term ++rows=10 ++close awk -f %<cr>
  266. " General auto commands.
  267. autocmd BufWritePost *.tex :term ++close ++rows=10 latex-compile %
  268. autocmd BufWritePost rc.lua silent !notify-send "$(awesome -k 2>&1)"
  269. autocmd BufWritePost quotes,*.fortune silent !notify-send "$(strfile %)"
  270. autocmd BufWritePost $HOME/.config/chromexup/config.ini silent !notify-send "$(chromexup 2>&1)"
  271. autocmd BufWritePost *.desktop silent !notify-send "$(desktop-file-validate % 2>&1 && echo 'OK: %')"
  272. autocmd BufWritePost Xresources silent !xrdb ~/.config/X11/Xresources && notify-send 'Reloading Xresources...'
  273. " Automatically remove trailing white space on save.
  274. autocmd InsertLeave,BufWritePre * %s/\s\+$//e
  275. " Automatically save file on insert and idle.
  276. autocmd InsertLeave,CursorHold * silent! write
  277. \| silent! exe "!~/.vim/hooks/post-save > /dev/null 2>&1 &"
  278. \| :echo @% '[filetype=' . &filetype . ']'
  279. augroup END
  280. set cmdheight=999 " Set command height temporarily to avoid prompt.
  281. set cmdheight=1 " Set command height back to the default.