![]() One such command is specifying the name, or save as, of the file before you write it to disk. In order to be effective with the editor, it is important to know all the commands. It has been around since 1976 and you either love it or hate it. ![]() So that is a way to save work performed in vi to a file which had originally been owned by someone else using vi, diff, and ed.The vi (or vim) text editor is a very effective text editor for Linux / UNIX systems. Ed then applies this script to the writable copy of the original file, and writes those modified buffer changes back out to the file. What this command sequence does in words is to catenate the script we generated with diff and echoes the ed write command, 'w', to the standard input of ed. Here is how to accomplish that from the bash command line prompt, '$': $ (cat ~/my_ed_script & echo 'w') | ed - writable_copy_of_original_file Now exit vi, and use this ed script to obtain the the edited file that couldn't be saved in the first place. So, save the script away to a writable location, for instance, your login folder: :w ~/my_ed_script We then want to save this ed script away to a safe place, and apply the script to a version of the original file we can write to. This replaces all lines in the current buffer (.,$!) with the diff generated ed script (diff -ed -) necessary to convert the original file into the contents of the current buffer. So, assuming an edited vi buffer, then perform the following. This ed script may be applied to the original file (or other similar files) at a later time outside of vi with the ed line editor.Ī way to save the current edit session as an ed script is to pass the original file name and the edited vi buffer as standard input to the diff utility with the -ed command line switch i.e. One way to accomplish this is to save the changes made to the original file as an ed script from within vi. The second way assumes someone else owns the file, and you would like to save your changes to that file. ![]() Will cause vi to overwrite the original READONLY file. This of course assumes that you have permission to write and execute in the current folder. Just use vi's exclamation mark suffix to the write command (:w!) to force overwriting your own READONLY file. The first way assumes you own the file, but the file is READONLY. I won't explain it here but the references above cover many shortcuts. Then you can just type :w!! to save with sudo powers. cnoremap w!! execute 'silent! write !sudo tee % >/dev/null' edit!.Use :w! ~/tempfile.ext to write your changes to a temporary file and then take measures to move the temp file to the directory (send the temp file to the directory owner/admin).Īs it is often the case problem #2 ( permission problem, with sudo), you can to your /etc/vim/vimrc (or ~/.vimrc) the following shortcut:.A permission problem ( no sudo): you don't have rights to write the file and you don't have admin access.And as tee is run with sudo powers, tee can modify the file. This will write the buffer to tee, a command that receives pipe information and can write to files. A permission problem ( sudo): you can't write but you have sudo rights.Issue :set noreadonly and then just use normal :w. ![]() There seems to be some different approachs, depending on your current problem: ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |