Wiki

by yszheda

View project onGitHub

Tip 45: Save a File as the Super User

Return to the top: <<Practical Vim>>

:w !sudo tee % > /dev/null
  • :write !{cmd}: send the contents of the buffer as standard input to the specified {cmd}

References

# If you open the file in vim,
# then you can \"ayy@a the next line to execute the vim command: 
:h :write_c
  • %: expands to represent the path of the current buffer

References

# If you open the file in vim,
# then you can \"ayy@a the next line to execute the vim command: 
:h :_%