Skip to content

Instantly share code, notes, and snippets.

@koturn
Created July 14, 2015 15:52
Show Gist options
  • Save koturn/49fb1429d4c722e932a9 to your computer and use it in GitHub Desktop.
Save koturn/49fb1429d4c722e932a9 to your computer and use it in GitHub Desktop.
if executable('sudo')
function! s:save_as_root(is_bang, filename)
if a:filename ==# ''
let l:filename = '%'
else
let l:filename = a:filename
endif
execute 'write' . a:is_bang ' !sudo tee > /dev/null ' . l:filename
endfunction
else
function! s:save_as_root(is_bang, filename)
echoerr 'sudo is not supported in this environment.'
endfunction
endif
command! -bar -bang -nargs=? -complete=file Write call s:save_as_root('<bang>', <q-args>)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment