" NOTE: neovim uses ShaDa (SHAred DAta) format for viminfo and swap, and uses a
" different version of undo file, so these types of files when created by
" vim cannot be used with neovim, and the 'viminfofile', 'directory', and
-" 'undodir' directories cannot be shared.
-" NOTE: neovim has a nice default for these directories and files so
-" customizing them is not necessary for it.
+" 'undodir' directories cannot be shared. since neovim has a nice default
+" for these directories and files, customizing them is not necessary.
if !has('nvim')
" viminfo
- " NOTE: 'viminfofile' is a deprecated alias for 'shada' in neovim
execute 'set viminfofile='.x.'/.viminfo'
" swap
" should be default disabled but just in case
set nomodelineexpr
+"" enable editorconfig parsing for new buffers
+let g:EditorConfig_enable_for_new_buf = 1
+
"" indent
" always use shiftwidth instead of tabsize
set smarttab
autocmd FileType javascript set softtabstop=2 shiftwidth=2 expandtab
autocmd FileType json set softtabstop=2 shiftwidth=2 expandtab
autocmd FileType html set softtabstop=2 shiftwidth=2 expandtab
-let g:EditorConfig_enable_for_new_buf = 1
"" syntax
autocmd Syntax php syn clear phpHereDoc phpNowDoc
" 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_backup = &backup
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_backup') && b:sev_suda_backup
- " XXX: suda.vim uses setlocal for this, even though it's global...
- " https://github.com/lambdalisue/vim-suda/issues/85
- setlocal backup
- endif
if exists('b:sev_suda_swapfile') && b:sev_suda_swapfile
- setlocal 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!')