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
endif
-""" package config
-"" suda
-" https://github.com/lambdalisue/vim-suda/issues/32#issuecomment-829608925
-if ! &diff
- let g:suda_smart_edit = 1
-endif
-
-
""" styling
" nice default theme
colorscheme murphy
""" 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
let g:EditorConfig_enable_for_new_buf = 1
"" syntax
+autocmd Syntax php syn clear phpHereDoc phpNowDoc
"" mappings
" use more accessible escapes, as C-n and C-o are shadowed by some terminals
if !has('nvim') && maparg('<C-L>', 'n') ==# ''
nnoremap <silent> <C-L> :nohlsearch<C-R>=has('diff')?'<Bar>diffupdate':''<CR><CR><C-L>
endif
+
+
+""" package config
+"" suda
+" https://github.com/lambdalisue/vim-suda/issues/32#issuecomment-829608925
+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 b:sev_suda_swapfile = &swapfile
+ let b:sev_suda_undofile = &undofile
+ " fix https://github.com/lambdalisue/vim-suda/issues/87
+ setlocal noswapfile
+endfunction
+function s:SudaSettingsRestore()
+ if filereadable(expand('<afile>')[7:])
+ if exists('b:sev_suda_swapfile') && b:sev_suda_swapfile
+ try
+ setlocal swapfile
+ catch
+ " ignore swapfile errors, they should have been shown already
+ echohl ErrorMsg
+ for line in split(v:exception, '\n')
+ echomsg printf('[suda] %s', line)
+ endfor
+ echohl None
+ endtry
+ endif
+ if exists('b:sev_suda_undofile') && b:sev_suda_undofile
+ setlocal undofile
+ endif
+ endif
+endfunction
+function s:SudaProcessUndo(cmd)
+ let p = expand('<afile>')[7:]
+ if has('win32') || !&undofile || !filereadable(p)
+ return
+ endif
+ let p = resolve(p)
+ " XXX: comments are from :help backupdir to mark implementation details
+ let x = &undodir
+ " For backwards compatibility with Vim version 3.0 a '>' at the start
+ " of the option is removed.
+ if stridx(x, '>') == 0
+ let x = x[1:]
+ endif
+ " To include a comma in a directory name precede it with a backslash.
+ for u in split(x, '\v\\@1<!,')
+ " Spaces after the comma are ignored, other spaces are considered part
+ " of the directory name.
+ let u = trim(u, ' ', 1)
+ " To have a space at the start of a directory name, precede it with a
+ " backslash.
+ if stridx(u, '\ ') == 0
+ let u = u[1:]
+ endif
+ " Empty means that no backup file will be created.
+ if empty(u)
+ continue
+ elseif u == '.'
+ " A directory "." means to put the backup file in the same
+ " directory as the edited file.
+ let d = fnamemodify(p, ':p:h')
+ elseif stridx(u, './') == 0
+ " A directory starting with "./" (or ".\" for MS-Windows) means to
+ " put the backup file relative to where the edited file is.
+ let d = printf('%s%s', fnamemodify(p, ':p:h'), expand(u))
+ else
+ let d = u
+ endif
+ " NOTE: env vars are not expanded, and backslashes are not handled...
+ if u[-2:-1] == '//'
+ let f = fnamemodify(p, ':p:gs?/?%?')
+ else
+ let f = printf('.%s.un~', fnamemodify(p, ':t'))
+ endif
+ " A directory name may end in an '/'.
+ let d = trim(d, '/', 2)
+ if !isdirectory(d)
+ continue
+ endif
+ try
+ execute printf('%s %s/%s', a:cmd, fnameescape(d), fnameescape(f))
+ break
+ catch
+ continue
+ endtry
+ endfor
+endfunction
+autocmd BufReadPre suda://* call s:SudaSettingsSave()
+autocmd BufReadPost suda://* call s:SudaSettingsRestore()
+autocmd BufReadPost suda://* call s:SudaProcessUndo('silent! rundo')
+autocmd BufWritePost suda://* call s:SudaProcessUndo('wundo!')