]> git.sev.monster Git - dotfiles.git/commitdiff
vimrc: save state with suda schemes, small changes
authorsev <git@sev.monster>
Thu, 5 Dec 2024 19:25:38 +0000 (13:25 -0600)
committersev <git@sev.monster>
Thu, 5 Dec 2024 19:25:38 +0000 (13:25 -0600)
etc/vim/.vimrc

index c782aef7052d2f82e11ceb8f0372e78b2c1cd5ab..aca1f42617131c7acdcb58f0b7b22ca0590584f5 100644 (file)
@@ -58,9 +58,9 @@ if !has('nvim')
     autocmd! vimStartup
 
     " packages
-    packadd! matchit
-    packadd! editorconfig   " this is now built to [n]vim in but optional
-    packadd! vim-commentary " nvim has built in commenting now
+    packadd! matchit        " included with [n]vim but disabled by default
+    packadd! editorconfig   " now included with [n]vim but disabled by default
+    packadd! vim-commentary " nvim has this built in now, vim still needs it
 
     " options
     set hlsearch
@@ -74,6 +74,33 @@ endif
 if ! &diff
     let g:suda_smart_edit = 1
 endif
+" re-enable backup, swap, undo for suda buffers that we can read
+" https://github.com/lambdalisue/vim-suda/issues/25
+function s:SudaSettingsSave()
+    let l:f = expand('<afile>')
+    if stridx(l:f, 'suda://') == 0
+        let g:sev_suda_file = expand('<afile>')
+        let g:sev_suda_backup = &backup
+        let g:sev_suda_swapfile = &swapfile
+        let g:sev_suda_undofile = &undofile
+    endif
+endfunction
+function s:SudaSettingsRestore()
+    if exists('g:sev_suda_file') && filereadable(g:sev_suda_file)
+        if exists('g:sev_suda_backup') && g:sev_suda_backup
+            " XXX: suda.vim uses setlocal for this, even though it's global...
+            setlocal backup
+        endif
+        if exists('g:sev_suda_swapfile') && g:sev_suda_swapfile
+            setlocal swapfile
+        endif
+        if exists('g:sev_suda_undofile') && g:sev_suda_undofile
+            setlocal undofile
+        endif
+    endif
+endfunction
+autocmd BufReadPre * call s:SudaSettingsSave()
+autocmd BufReadPost suda://* call s:SudaSettingsRestore()
 
 
 """ styling
@@ -126,7 +153,8 @@ set listchars=tab:├─,extends:»,precedes:«,space:·,trail:∙,nbsp:■
 
 """ editor
 " always save undo file for all file buffers
-autocmd BufRead * set undofile
+autocmd BufReadPre * setlocal undofile
+
 
 " explicitly use modeline, even on systems where it's disabled by system vimrc
 autocmd BufRead * set modeline
This page took 0.043526 seconds and 4 git commands to generate.