Changes

Vim Tips

2,615 bytes added, 11:45, 9 August 2020
/* vim write with sudo trick */
The following lines were added (+) and removed (-):
  :set nosi noai  :set noautoindent | set nosmartindent | set nocindent or to Disable auto commenting just for paste operationsCreate a .vimrc for your shell and put the lines in like this set noautoindent set nosmartindent set nocindent  or to Disable auto commenting just for paste operations temporarily while working in a file=== Disable annoying bracket highlighting aka bracket match aka parentheses match ===Using the ":syntax off" doesn't disable bracket match, such as you would see when working with HTML tags.  The problem is that the highlighting is terrible on some terminals such as Konsole.  To disable type :NoMatchParenThe  matchparen plugin has become enabled on your installation.  You can run the :NoMatchParen command to shut it off.  ":he matchparen" has instructions for how to disable it altogether.  You can also find out where 'showmatch' might be getting set bysetting the 'verbose' option to non-zero or using the ":verbose" command.  You can see ":he :set-verbose" for more info on that one.  Colors for the matching bracket or brace can be customized by adding to the .vimrc file. hi MatchParen cterm=none ctermbg=green ctermfg=bluereference: [http://vim.1045645.n5.nabble.com/turning-off-showmatch-td1181954.html turning off showmatch]=== Use vim as a HEX Editor ===The 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.'') vi -b binaryfileNow 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 vimWhen 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