Play with VIM Editor to Start a New Shell, Change the Permission and More
By Angsuman Chakraborty, Gaea News NetworkThursday, January 15, 2009
Suppose you were concentrating hard to develop something new and editing a file in vim editor. Just when you thought you are done with the problem, the save option reminded you how unfortunate you are. You don’t have the freaking permission for that read-only file to edit. So what should you do next? Here is a solution.
- Just exit without saving; change the permission of the file, then edit the file again in vim and then save the file. But that is not exactly what I will tip you by writing an article.
- You can be smarter and from another terminal, you can change the permission of the file. Save and Exit.
- But you can be a real cool cat if you do this.
here is an command in vi to create a new shell from vi , its called sh. So go to ex mode and type
:sh
sh looks up the user’s default shell (e.g. the Bourne shell or the C shell) and starts a new shell. In that shell change the permission of the file, type exit, you will be in the same vi session; now save your file.
4. You can be really tricky at times I know. So why don’t you try this too?
- Hit ctrl-Z to suspend the vim process, which should bring you back to the shell where you started vim.
- Then you can make your permission changes
- At last use the fg command to un-suspend vim.
Tags: Bash scripts, Linux tip, Open a new shell through VI, So what
June 14, 2009: 1:29 pm
If you have sudo rights to a user that CAN edit the file, try this: :w! sudo tee % or :w! sudo -u username tee % |
January 20, 2009: 12:11 pm
Also :! chmod 700 filename.txt https://unstableme.blogspot.com/2008/10/start-new-shell-from-vi-editor-vim-tips.html // Jadu |
Ed Greenberg