From 07d294425a98ee5d1e22d03e2b24ae2c76e487c0 Mon Sep 17 00:00:00 2001 From: TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> Date: Sat, 23 Aug 2025 12:42:37 +0900 Subject: updates --- mac/.config/vim/init.vim | 438 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 438 insertions(+) create mode 100644 mac/.config/vim/init.vim (limited to 'mac/.config/vim/init.vim') diff --git a/mac/.config/vim/init.vim b/mac/.config/vim/init.vim new file mode 100644 index 0000000..c39c130 --- /dev/null +++ b/mac/.config/vim/init.vim @@ -0,0 +1,438 @@ + +" AUTOCMD ---------------------------------------------------------------- {{{ + +" Close with q +autocmd FileType checkhealth,help,lspinfo,neotest-output,neotest-output-panel,neotest-summary,netrw,notify,qf,query,spectre_panel,startuptime,terminal,tsplayground noremap q :bd + +" Disables automatic commenting on newline: +autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o + +" Nerd tree +autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif + +" Runs a script that cleans out tex build files whenever I close out of a .tex file. +autocmd VimLeave *.tex !texclear % + +" Text files +let g:vimwiki_ext2syntax = {'.Rmd': 'markdown', '.rmd': 'markdown','.md': 'markdown', '.markdown': 'markdown', '.mdown': 'markdown'} +let g:vimwiki_list = [{'path': '~/.local/share/nvim/vimwiki', 'syntax': 'markdown', 'ext': '.md'}] +autocmd BufRead,BufNewFile /tmp/calcurse*,~/.calcurse/notes/* set filetype=markdown +autocmd BufRead,BufNewFile *.ms,*.me,*.mom,*.man set filetype=groff +autocmd BufRead,BufNewFile *.tex set filetype=tex + +" Enable Goyo by default for mutt writing +autocmd BufRead,BufNewFile /tmp/neomutt* :Goyo 80 | call feedkeys("jk") +autocmd BufRead,BufNewFile /tmp/neomutt* map ZZ :Goyo!\|x! +autocmd BufRead,BufNewFile /tmp/neomutt* map ZQ :Goyo!\|q! + +" Automatically deletes all trailing whitespace and newlines at end of file on save. & reset cursor position +autocmd BufWritePre * let currPos = getpos(".") +autocmd BufWritePre * %s/\s\+$//e +autocmd BufWritePre * %s/\n\+\%$//e +autocmd BufWritePre *.[ch] %s/\%$/\r/e " add trailing newline for ANSI C standard +autocmd BufWritePre *neomutt* %s/^--$/-- /e " dash-dash-space signature delimiter in emails +autocmd BufWritePre * cal cursor(currPos[1], currPos[2]) + +" When shortcut files are updated, renew bash and ranger configs with new material: +autocmd BufWritePost bm-files,bm-dirs !shortcuts + +" Run xrdb whenever Xdefaults or Xresources are updated. +autocmd BufRead,BufNewFile Xresources,Xdefaults,xresources,xdefaults set filetype=xdefaults +autocmd BufWritePost Xresources,Xdefaults,xresources,xdefaults !xrdb % + +" Recompile dwmblocks on config edit. +autocmd BufWritePost ~/.local/src/dwmblocks/config.h !cd ~/.local/src/dwmblocks/; sudo make install && { killall -q dwmblocks;setsid -f dwmblocks } + +" Which key description +autocmd! User vim-which-key call which_key#register('', 'g:which_key_map') +let g:which_key_map = {} + +" }}} + + +" BACKUP ----------------------------------------------------------------- {{{ + +if version >= 703 + set undodir=~/.config/vim/undodir + set undofile + set undoreload=10000 +endif + +" }}} + + +" PLUGINS INIT ----------------------------------------------------------- {{{ + +let config_path = empty($XDG_CONFIG_HOME) ? expand("$HOME/.config") : expand("$XDG_CONFIG_HOME") +if filereadable(config_path . "/vim/plugins.vim") + silent! call mkdir(config_path . "/vim/plugged", "p") + execute "source " . config_path . "/vim/plugins.vim" +endif + +" goyo +let g:is_goyo_active = v:false +function! GoyoEnter() + if executable('tmux') && strlen($TMUX) + silent !tmux set status off + silent !tmux list-panes -F '\#F' | grep -q Z || tmux resize-pane -Z + endif + + let g:default_colorscheme = exists('g:colors_name') ? g:colors_name : 'desert' + set background=light + set linebreak + set wrap + set textwidth=0 + set wrapmargin=0 + + Goyo 80x85% + colorscheme seoul256 + let g:is_goyo_active = v:true +endfunction + +function! GoyoLeave() + if executable('tmux') && strlen($TMUX) + silent !tmux set status on + silent !tmux list-panes -F '\#F' | grep -q Z && tmux resize-pane -Z + endif + + Goyo! + execute 'colorscheme ' . g:default_colorscheme + let g:is_goyo_active = v:false +endfunction + +function! ToggleGoyo() + if g:is_goyo_active + call GoyoLeave() + else + call GoyoEnter() + endif +endfunction + +" }}} + + +" PLUGIN MAPPINGS & SETTINGS -------------------------------------------------------- {{{ + +" Open quickfix/location list +let g:which_key_map.o = { + \ 'name' : '+Open' , + \ 'q' : 'Quickfix-list' , + \ 'l' : 'Location-list' , + \ } + +" Check health +nnoremap ch :CheckHealth +let g:which_key_map.c = { 'name' : 'Check' } +let g:which_key_map.c.h = 'Check-health' + +" Bookmarks +let g:bookmark_no_default_key_mappings = 1 +let g:bookmark_save_per_working_dir = 1 +let g:bookmark_auto_save = 1 +nmap mm BookmarkToggle +nmap mi BookmarkAnnotate +nmap ma BookmarkShowAll +nmap m] BookmarkNext +nmap m[ BookmarkPrev +nmap mc BookmarkClear +nmap mx BookmarkClearAll +nmap mk BookmarkMoveUp +nmap mj BookmarkMoveDown +nmap mg BookmarkMoveToLine + +" Fugitive +nnoremap gs :Git +let g:which_key_map.g = { 'name' : 'Git/Goyo' } +let g:which_key_map.g.s = 'Git' + +" Goyo plugin makes text more readable when writing prose: +nnoremap gy :call ToggleGoyo() +let g:which_key_map.g.y = 'Toggle-goyo' + +" Nerd tree +map n :NERDTreeToggle +let g:which_key_map.n = 'Toggle-nerd-tree' + +" Undotree +nnoremap u :UndotreeToggle +let g:which_key_map.u = 'Toggle-undo-tree' + +" vimwiki +map vw :VimwikiIndex +let g:which_key_map.v = { 'name' : '+Vim-wiki' } +let g:which_key_map.v.w = 'Vim-wiki-index' + +" vim-plug +nnoremap pc :PlugClean +nnoremap pi :PlugInstall +nnoremap pu :PlugUpdate +let g:which_key_map.p = { 'name' : '+Plug' } +let g:which_key_map.p.c = 'Plug-clean' +let g:which_key_map.p.i = 'Plug-install' +let g:which_key_map.p.u = 'Plug-update' + +" whichkey +nnoremap :WhichKey '' +nnoremap :WhichKey '\' + +" lsp +if executable('pylsp') + " pip install python-lsp-server + au User lsp_setup call lsp#register_server({ + \ 'name': 'pylsp', + \ 'cmd': {server_info->['pylsp']}, + \ 'allowlist': ['python'], + \ }) +endif + +function! s:on_lsp_buffer_enabled() abort + setlocal omnifunc=lsp#complete + setlocal signcolumn=yes + if exists('+tagfunc') | setlocal tagfunc=lsp#tagfunc | endif + nmap gd (lsp-definition) + nmap gs (lsp-document-symbol-search) + nmap gS (lsp-workspace-symbol-search) + nmap gr (lsp-references) + nmap gi (lsp-implementation) + nmap gt (lsp-type-definition) + nmap lr (lsp-rename) + nmap [t (lsp-previous-diagnostic) + nmap ]t (lsp-next-diagnostic) + nmap K (lsp-hover) + " nnoremap lsp#scroll(+4) + " nnoremap lsp#scroll(-4) + + let g:lsp_format_sync_timeout = 1000 + autocmd! BufWritePre *.rs,*.go,*.py call execute('LspDocumentFormatSync') + + " refer to doc to add more commands +endfunction + +let g:which_key_map.g = { + \ 'name' : '+Goto' , + \ 'd' : 'Definition' , + \ 's' : 'Symbol' , + \ 'S' : 'Workspace-symbol' , + \ 'r' : 'References' , + \ 'i' : 'Implementation' , + \ 't' : 'Type-definition' , + \ } + +let g:which_key_map['['] = { 'name' : '+Previous' } +let g:which_key_map[']'] = { 'name' : '+Next' } +let g:which_key_map['[t'] = 'Diagnostic' +let g:which_key_map[']t'] = 'Diagnostic' +let g:which_key_map.K = 'Keyword' + +augroup lsp_install + au! + " call s:on_lsp_buffer_enabled only for languages that has the server registered. + autocmd User lsp_buffer_enabled call s:on_lsp_buffer_enabled() +augroup END + +let g:lsp_fold_enabled = 0 +let g:lsp_log_verbose = 1 +let g:lsp_log_file = expand('~/.cache/vim/vim-lsp.log') +let g:asyncomplete_log_file = expand('~/.cache/vim/asyncomplete.log') +let g:lsp_settings_filetype_python = ['pyright-langserver', 'ruff', 'ruff-lsp'] + +nnoremap li :LspInstallServer + +" vim-airline +if !exists('g:airline_symbols') + let g:airline_symbols = {} +endif +let g:airline_symbols.colnr = ' C:' +let g:airline_symbols.linenr = ' L:' +let g:airline_symbols.maxlinenr = ' ' +let g:airline#extensions#whitespace#symbol = '!' + +" colorscheme +if isdirectory(expand("~/.config/vim/plugged/catppuccin")) + let g:airline_theme = 'catppuccin_mocha' + colorscheme catppuccin_mocha +endif + +" fzf +let g:fzf_vim = {} +let $FZF_DEFAULT_OPTS = "--layout=default --preview-window 'right:60%' --preview 'bat --style=numbers --line-range :300 {}' + \ --bind ctrl-y:preview-up, + \ ctrl-e:preview-down, + \ ctrl-b:preview-page-up, + \ ctrl-f:preview-page-down, + \ ctrl-u:preview-half-page-up, + \ ctrl-d:preview-half-page-down, + \ shift-up:preview-top, + \ shift-down:preview-bottom, + \ alt-up:half-page-up, + \ alt-down:half-page-down + \ " + +" tmux +if exists('$TMUX') + let g:fzf_layout = { 'tmux': '90%,70%' } + let g:tmux_navigator_no_wrap = 1 +else + let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6, 'relative': v:true } } +endif +let g:fzf_vim.preview_window = ['right,50%,<70(up,40%)', 'ctrl-/'] +let g:fzf_vim.commits_log_options = '--graph --color=always --format="%C(auto)%h%d %s %C(black)%C(bold)%cr"' +let g:fzf_vim.tags_command = 'ctags -R' + +function! s:build_quickfix_list(lines) + call setqflist(map(copy(a:lines), '{ "filename": v:val, "lnum": 1 }')) + copen + cc +endfunction + +let g:fzf_action = { + \ 'ctrl-q' : function('s:build_quickfix_list'), + \ 'ctrl-t' : 'tab split' , + \ 'ctrl-x' : 'split' , + \ 'ctrl-v' : 'vsplit' , + \ } + +nnoremap cl :Colors +nnoremap fb :Files ~/.local/bin +nnoremap fc :Files ~/.config +nnoremap fd :Files ~/.dotfiles +nnoremap ff :Files . +nnoremap fF :Files ~ +nnoremap fg :GFiles +nnoremap fG :GFiles? +nnoremap fs :Files ~/.local/src/suckless +nnoremap fv :Files ~/.config/vim +nnoremap sb :Buffers +nnoremap sc :Changes +nnoremap sC :Commands +nnoremap sg :Rg +nnoremap sG :RG +nnoremap shc :History: +nnoremap shh :History +nnoremap shp :Helptags +nnoremap shs :History/ +nnoremap sj :Jumps +nnoremap sk :Maps +nnoremap sl :Locate +nnoremap sm :Marks +nnoremap sn :Snippets +nnoremap st :Filetypes +nnoremap gc :Commits +nnoremap gC :BCommits + +let g:which_key_map.c = 'Color-schemes' +let g:which_key_map.f = { + \ 'name' : '+Find' , + \ 'b' : 'Scripts' , + \ 'c' : 'Config' , + \ 'd' : 'Dotfiles' , + \ 'f' : 'Files' , + \ 'F' : 'Root-files' , + \ 'g' : 'Git-files' , + \ 'G' : 'Git-status' , + \ 's' : 'Suckless' , + \ 'v' : 'Vim-config' , + \ } + +let g:which_key_map.g = { + \ 'name' : '+Git' , + \ 'c' : 'Commits' , + \ 'C' : 'Buffer-commits' , + \ } + +let g:which_key_map.s = { + \ 'name' : '+Search' , + \ 'b' : 'Buffers' , + \ 'c' : 'Changes' , + \ 'C' : 'Commands' , + \ 'g' : 'Rip-grep' , + \ 'G' : 'Rip-Grep' , + \ 'h' : { + \ 'name' : '+History' , + \ 'c' : 'Command-history' , + \ 'h' : 'History' , + \ 'p' : 'Help-tags' , + \ 's' : 'Search-history' , + \ }, + \ 'j' : 'Jumps' , + \ 'k' : 'Key-maps' , + \ 'l' : 'Locate' , + \ 'm' : 'Marks' , + \ 'n' : 'Snippets' , + \ 't' : 'File-types' , + \ } + + +" snippets +let g:SuperTabDefaultCompletionType = '' +let g:SuperTabCrMapping = 0 +let g:UltiSnipsExpandTrigger = '' +let g:UltiSnipsJumpForwardTrigger = '' +let g:UltiSnipsJumpBackwardTrigger = '' +let g:UltiSnipsEditSplit = 'vertical' +let g:UltiSnipsAutoTrigger = 1 +let g:asyncomplete_auto_completeopt = 0 +let g:asyncomplete_auto_popup = 1 + +set completeopt=menuone,noinsert,noselect,preview +autocmd! CompleteDone * if pumvisible() == 0 | pclose | endif + +if has('python3') + call asyncomplete#register_source(asyncomplete#sources#ultisnips#get_source_options({ + \ 'name': 'ultisnips', + \ 'allowlist': ['*'], + \ 'completor': function('asyncomplete#sources#ultisnips#completor'), + \ })) +endif + +inoremap pumvisible() ? "\" : "\" +inoremap pumvisible() ? "\" : "\" +inoremap pumvisible() ? asyncomplete#close_popup() : "\" + +" whichkey +set timeoutlen=500 + +let g:which_key_map.a = 'Select-all-the-text' +let g:which_key_map.b = { 'name' : '+Buffer' } +let g:which_key_map.b.n = 'New/open-buffer' +let g:which_key_map.c = { 'name' : '+Format' } +let g:which_key_map.c.f = 'Format-buffer' +let g:which_key_map.e = 'Explorer' +let g:which_key_map.h = { 'name' : '+Hex' } +let g:which_key_map.h.x = 'Toggle-hex/reverse-conversion' +let g:which_key_map.l = { 'name' : '+Lex/Lsp' } +let g:which_key_map.l.e = 'Open-lex' +let g:which_key_map.l.i = 'Lsp-install-server' +let g:which_key_map.l.r = 'Rename' +let g:which_key_map.o = { 'name' : '+Open' } +let g:which_key_map.o.g = 'Orthography' +let g:which_key_map.Q = 'Force-quit-all' +let g:which_key_map.r = { 'name' : '+Replace' } +let g:which_key_map.r.w = 'Replace word' +let g:which_key_map.s = { 'name' : '+Surround' } +let g:which_key_map.s.o = 'Source-file' +let g:which_key_map.s.w = 'Surround-word' +let g:which_key_map.t = 'Go-to-tab' +let g:which_key_map["'"] = 'Register' +let g:which_key_map['w'] = { + \ 'name' : '+windows' , + \ 'd' : ['c' , 'Delete-window'] , + \ 'h' : ['h' , 'Window-left'] , + \ 'H' : ['5<' , 'Expand-window-left'] , + \ 'j' : ['j' , 'Window-below'] , + \ 'J' : [':resize +5' , 'Expand-window-below'] , + \ 'k' : ['k' , 'Window-up'] , + \ 'K' : [':resize -5' , 'Expand-window-up'] , + \ 'l' : ['l' , 'Window-right'] , + \ 'L' : ['5>' , 'Expand-window-right'] , + \ 's' : ['s' , 'Split-window-below'] , + \ 'v' : ['v' , 'Split-window-below'] , + \ 'w' : ['w' , 'Other-window'] , + \ '2' : ['v' , 'Layout-double-columns'] , + \ '-' : ['s' , 'Split-window-below'] , + \ '|' : ['v' , 'Split-window-right'] , + \ '=' : ['=' , 'Balance-window'] , + \ '?' : ['Windows' , 'Fzf-window'] , + \ } + +" }}} -- cgit v1.2.3