Play with VIM Editor to Start a New Shell, Change the Permission and More

By Angsuman Chakraborty, Gaea News Network
Thursday, 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.

  1. 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.
  2. You can be smarter and from another terminal, you can change the permission of the file. Save and Exit.
  3. 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.

Discussion

Ed Greenberg
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 %

YOUR VIEW POINT
NAME : (REQUIRED)
MAIL : (REQUIRED)
will not be displayed
WEBSITE : (OPTIONAL)
YOUR
COMMENT :