function Sudowrite() execute 'w !sudo tee "%"' endfunction nnoremap w :call Sudowrite() function MakeFileExecutable(sudo = 0) if a:sudo execute '! sudo chmod +x "%"' else execute '! chmod +x "%"' endif endfunction nnoremap x :call MakeFileExecutable(0) nnoremap xx :call MakeFileExecutable(1)