Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I've enabled VIM style editing of bash commands at the bash prompt as default bash setting. On a few occasions I've accidentally opened a blank vim file with some complex bash command I was writing.

Awesome. How do I get the newly written line in vim back into bash? I found another post where the author had the opposite trouble--or so it seems.

What steps put my bash prompt commands into vim and then back again to bash to execute?

share|improve this question
1  
In vim, I like to use :x to save and exit. –  glenn jackman Jul 11 '12 at 3:28
add comment

3 Answers 3

up vote 1 down vote accepted

When you're in normal mode (e.g, when h and l move the cursor left and right), type v to edit the line in vi, or in the editor specified by $VISUAL or $EDITOR. When you're done, just save the buffer as you would after editing any other file, using ZZ or :wq as you prefer.

share|improve this answer
    
I've tried all your suggestions and marked this version because it worked for me. (^x or ^e didn't do anything...) I would add, upon saving the buffer I'm returned to bash and the command was immediately executed. Adding a hash before the command prevented immediate execution of the command. –  xtian Jul 12 '12 at 14:24
add comment

Ctrl+X Ctrl+E will insert your bash command into vim.

To exit vim:

If you are editing (--INSERT-- or --REPLACE-- appears at the bottom), press Esc.

Then press:

:wq or ZZ to save and exit.

:q! to quit without saving.

share|improve this answer
add comment

I believe ctrl-x, ctrl-e is what you want. Writing the file as normal should execute it i think. So :wq in vim.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.