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.

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