Changes

Vim Tips

1,356 bytes added, 11:45, 9 August 2020
/* vim write with sudo trick */
The following lines were added (+) and removed (-):
Open the file with the -b command line switchThe vim editor does not have a HEX Edit mode, but can stream the buffer to an external program called xxd. Open the file with the -b command line switch (''Binary mode. A few options will be set that makes it possible to edit a binary or executable file.'') Once open you have to use Now stream the buffer to xxd from within vim :%!xxdAnd when your done and want to exit the redirect :%!xxd -rIf you are at the command prompt you can display the hex output of a binary file simply by typing xxd binaryfileThis demonstrates how you are actually using xxd from within vim When using vim as a HEX Editor remember to run the filter (:%!xxd to convert to hex, :%!xxd -r to convert back) and to convert back from hex before saving.   ===vim write with sudo trick===Oops!  I opened a file in vim and made a bunch of edits not realizing that I do not have write permission to the file.   [https://stackoverflow.com/questions/33366352/write-to-file-using-vim-when-sudo-privileges-needed Write to file using vim when sudo privileges needed] :w !sudo tee %The !sudo tee part calls tee with administrator privileges.  You can add this to your .vimrc to make this trick easy-to-use: just type :w!!. " Allow saving of files as sudo when I forgot to start vim using sudo. cmap w!! w !sudo tee > /dev/null %ref: [https://stackoverflow.com/questions/2600783/how-does-the-vim-write-with-sudo-trick-work How does the vim “write with sudo” trick work?]
Administrator
662
edits