From 21e5d0ac8642db5ffecec255fd493a9ca4ddbeae Mon Sep 17 00:00:00 2001 From: Hektor Misplon Date: Sun, 22 Sep 2024 13:13:29 +0200 Subject: [PATCH] Separate config into '.vim/plugins/' --- .vim/plugin/cursor.vim | 14 ++++++++ .vim/plugin/jsonc.vim | 3 ++ .vim/plugin/pandoc.vim | 10 ++++++ .vim/plugin/reload.vim | 5 +++ .vim/plugin/statusline.vim | 7 ++++ .vim/plugin/zk.vim | 20 +++++++++++ .vimrc | 69 -------------------------------------- 7 files changed, 59 insertions(+), 69 deletions(-) create mode 100644 .vim/plugin/cursor.vim create mode 100644 .vim/plugin/jsonc.vim create mode 100644 .vim/plugin/pandoc.vim create mode 100644 .vim/plugin/reload.vim create mode 100644 .vim/plugin/statusline.vim create mode 100644 .vim/plugin/zk.vim diff --git a/.vim/plugin/cursor.vim b/.vim/plugin/cursor.vim new file mode 100644 index 0000000..7143a60 --- /dev/null +++ b/.vim/plugin/cursor.vim @@ -0,0 +1,14 @@ +" Taken from /usr/share/vim/vim90/defaults.vim +augroup vimStartup + au! + + " When editing a file, always jump to the last known cursor position. + " Don't do it when the position is invalid, when inside an event handler + " (happens when dropping a file on gvim) and for a commit message (it's + " likely a different one than last time). + autocmd BufReadPost * + \ if line("'\"") >= 1 && line("'\"") <= line("$") && &ft !~# 'commit' + \ | exe "normal! g`\"" + \ | endif + +augroup END diff --git a/.vim/plugin/jsonc.vim b/.vim/plugin/jsonc.vim new file mode 100644 index 0000000..35f18d1 --- /dev/null +++ b/.vim/plugin/jsonc.vim @@ -0,0 +1,3 @@ +" JSONC (see https://github.com/neoclide/jsonc.vim/pull/9") +au BufNewFile,BufRead */.vscode/*.json setlocal filetype=jsonc + diff --git a/.vim/plugin/pandoc.vim b/.vim/plugin/pandoc.vim new file mode 100644 index 0000000..f51d807 --- /dev/null +++ b/.vim/plugin/pandoc.vim @@ -0,0 +1,10 @@ +fu! Compile() + if expand('%:e') == "md" + :silent exec "!pandoc % -s -o /tmp/op.pdf &" + endif +endfu + +fu! Preview() + :call Compile() + :silent exec "!zathura /tmp/op.pdf &" +endfu diff --git a/.vim/plugin/reload.vim b/.vim/plugin/reload.vim new file mode 100644 index 0000000..eaf5d18 --- /dev/null +++ b/.vim/plugin/reload.vim @@ -0,0 +1,5 @@ +augroup Vim + au! + " Reload vim config when ~/.vimrc is changed + au BufWritePost $HOME/.vimrc so $MYVIMRC | redraw | echo "Reloaded vimrc" +augroup END diff --git a/.vim/plugin/statusline.vim b/.vim/plugin/statusline.vim new file mode 100644 index 0000000..5195284 --- /dev/null +++ b/.vim/plugin/statusline.vim @@ -0,0 +1,7 @@ +se ls=2 +se stl=\ %0*%n +se stl+=\ %m +se stl+=\ %y%0* +se stl+=\ %<%F +se stl+=\ %0*%=%5l%* +se stl+=%0*/%L%* diff --git a/.vim/plugin/zk.vim b/.vim/plugin/zk.vim new file mode 100644 index 0000000..9c01a56 --- /dev/null +++ b/.vim/plugin/zk.vim @@ -0,0 +1,20 @@ +let s:zk_preview_enabled = 0 +let s:live_server_job = -1 +au BufEnter /home/h/.zk/*.md silent exe '!echo "%" > /home/h/.zk/current-zettel.txt' +function! ToggleZKPreview() + if s:zk_preview_enabled == 1 + let s:zk_preview_enabled = 0 + call jobstop(s:live_server_job) + au! ZKPreview + else + let s:zk_preview_enabled = 1 + let s:live_server_job = jobstart('live-server --watch=/home/h/.zk/current-zettel-content.html --open=current-zettel-content.html --port=8080') + augroup ZKPreview + au BufEnter /home/h/.zk/*.md silent exe '!cat "%:r.html" > /home/h/.zk/current-zettel-content.html' + au BufWritePost /home/h/.zk/*.md silent exe '!make && cat "%:r.html" > /home/h/.zk/current-zettel-content.html' + augroup END + endif +endfunction +command! ToggleZKPreview call ToggleZKPreview() + +nn o :ToggleZKPreview :!xdg-open http://localhost:8080/%:t:r.html & diff --git a/.vimrc b/.vimrc index 91878bf..808f9df 100644 --- a/.vimrc +++ b/.vimrc @@ -231,84 +231,15 @@ au Filetype supercollider packadd scvim " }}} - -" Statusline {{{ -se ls=2 -se stl=\ %0*%n -se stl+=\ %m -se stl+=\ %y%0* -se stl+=\ %<%F -se stl+=\ %0*%=%5l%* -se stl+=%0*/%L%* -" }}} - " Quick hacks {{{ " -fu! Compile() - if expand('%:e') == "md" - :silent exec "!pandoc % -s -o /tmp/op.pdf &" - endif -endfu - -fu! Preview() - :call Compile() - :silent exec "!zathura /tmp/op.pdf &" -endfu - -" VIM config hot reload - " TODO: separate to filetype specific files " JS " Jump between `=` and `;` au FileType javascript set mps+==:; -" JSONC (see https://github.com/neoclide/jsonc.vim/pull/9") -au BufNewFile,BufRead */.vscode/*.json setlocal filetype=jsonc - -let s:zk_preview_enabled = 0 -let s:live_server_job = -1 -au BufEnter /home/h/.zk/*.md silent exe '!echo "%" > /home/h/.zk/current-zettel.txt' -function! ToggleZKPreview() - if s:zk_preview_enabled == 1 - let s:zk_preview_enabled = 0 - call jobstop(s:live_server_job) - au! ZKPreview - else - let s:zk_preview_enabled = 1 - let s:live_server_job = jobstart('live-server --watch=/home/h/.zk/current-zettel-content.html --open=current-zettel-content.html --port=8080') - augroup ZKPreview - au BufEnter /home/h/.zk/*.md silent exe '!cat "%:r.html" > /home/h/.zk/current-zettel-content.html' - au BufWritePost /home/h/.zk/*.md silent exe '!make && cat "%:r.html" > /home/h/.zk/current-zettel-content.html' - augroup END - endif -endfunction -command! ToggleZKPreview call ToggleZKPreview() - -nn o :ToggleZKPreview :!xdg-open http://localhost:8080/%:t:r.html & - highlight QuickScopeSecondary cterm=underline highlight QuickScopePrimary ctermbg=253 ctermfg=232 cterm=none highlight Pmenu ctermfg=232 - -" Taken from /usr/share/vim/vim90/defaults.vim -augroup vimStartup - au! - - " When editing a file, always jump to the last known cursor position. - " Don't do it when the position is invalid, when inside an event handler - " (happens when dropping a file on gvim) and for a commit message (it's - " likely a different one than last time). - autocmd BufReadPost * - \ if line("'\"") >= 1 && line("'\"") <= line("$") && &ft !~# 'commit' - \ | exe "normal! g`\"" - \ | endif - -augroup END - -augroup Vim - au! - " Reload vim config when ~/.vimrc is changed - au BufWritePost $HOME/.vimrc so $MYVIMRC | redraw | echo "Reloaded vimrc" -augroup END