how to send command back to the command line after typing 'v' from linux command line in set -o vi mode?

30 views
Skip to first unread message

pixelterra

unread,
Apr 27, 2012, 2:35:39 PM4/27/12
to vim...@googlegroups.com
I recently found this out:

"Suppose you typed a longer command and you noticed that you had made several mistakes, and wanted to do the correction in the vi editor itself. You can type 'v' to edit the command in the editor and not on the command line!"

But after I edit the command in vim, how do I get that command back to the command line? Or do I have to copy / paste manually?

Taylor Hedberg

unread,
Apr 27, 2012, 2:42:37 PM4/27/12
to vim...@googlegroups.com
pixelterra, Fri 2012-04-27 @ 11:35:39-0700:
> But after I edit the command in vim, how do I get that command back to
> the command line? Or do I have to copy / paste manually?

When you save the buffer and quit the editor, the shell then executes
the contents of the saved buffer. So it happens automatically.
signature.asc

Tim Chase

unread,
Apr 27, 2012, 2:48:06 PM4/27/12
to vim...@googlegroups.com, pixelterra
On 04/27/12 13:35, pixelterra wrote:
> "Suppose you typed a longer command and you noticed that you
> had made several mistakes, and wanted to do the correction in
> the vi editor itself. You can type 'v' to edit the command in
> the editor and not on the command line!"

Are you sure you mean typing "v" to edit the command? Usually it
defaults to control+F on the command-line (assuming you haven't
changed the value for 'cedit', something I don't recommend
doing). This opens the command-line window. It should keep
'history' entries around (defaulting to 20)

:help cmdwin
:help 'history'
:help 'cedit'

If you want to get to this window again, you can either press the
colon followed by control+F. Alternatively, you can use

q:

to open the window. Similar editing can be done on search
history with "q/" or pressing control+F in a "/" or "?" search
you've already started.

To navigate, you can scroll back using normal Vi navigation
(searching, h/j/k/l, etc)

> But after I edit the command in vim, how do I get that command
> back to the command line? Or do I have to copy / paste
> manually?

You can recall previous commands using control+P (and control+N)
or <up>/<down>, as well as using Vim navigation in the
command-line window as mentioned above.

-tim



Tony Mechelynck

unread,
Apr 27, 2012, 2:47:50 PM4/27/12
to vim...@googlegroups.com, pixelterra
What happens if you leave Insert mode (e.g. by <Esc>) then type :x
(followed by <Enter>) in your Vim editor?


Best regards,
Tony.
--
Pittsburgh Driver's Test

(7) The car directly in front of you has a flashing right tail light
but a steady left tail light. This means

(a) one of the tail lights is broken; you should blow your horn
to call the problem to the driver's attention.
(b) the driver is signaling a right turn.
(c) the driver is signaling a left turn.
(d) the driver is from out of town.

The correct answer is (d). Tail lights are used in some foreign
countries to signal turns.

pixelterra

unread,
Apr 27, 2012, 2:50:33 PM4/27/12
to vim...@googlegroups.com, pixelterra

Tim, I mean I'm on the linux command line in set -o vi mode.

You can do basic editing there, but anything more complex you can type 'v' and it will open the current command line text in $EDITOR. I'm wondering how to send the edited command back to the LINUX command line (not inside of vim)

pixelterra

unread,
Apr 27, 2012, 2:52:29 PM4/27/12
to vim...@googlegroups.com, pixelterra
:x did the trick. What exactly is that command?

Taylor Hedberg

unread,
Apr 27, 2012, 2:56:58 PM4/27/12
to vim...@googlegroups.com, pixelterra
pixelterra, Fri 2012-04-27 @ 11:52:29-0700:
> :x did the trick. What exactly is that command?

:help :x

*:x* *:xit*
:[range]x[it][!] [++opt] [file]
Like ":wq", but write only when changes have been
made.
When 'hidden' is set and there are more windows, the
current buffer becomes hidden, after writing the file.
signature.asc

Tim Chase

unread,
Apr 27, 2012, 3:00:29 PM4/27/12
to vim...@googlegroups.com, pixelterra
Sorry...I didn't see the entire subject line on my screen and
assumed you were talking about Vim. The bash vi mode ("set -o
vi") is a separate beast.

> But after I edit the command in vim, how do I get that command
> back to the command line? Or do I have to copy / paste
> manually?

Quitting vim will automatically execute the command as Taylor
mentions, which also puts it in your command history. You may
want to try using something like

bash$ fc -3

to edit the command you issued 3 back (or just "fc" to edit the
most recently issued command). Reading up on the "history"
command and bash's "event designators" may also provide you other
options. In emacs mode, using control+P will scroll back through
the history. In vi mode, hitting <esc> and then using k/j will
scroll around in the history, or you can use "/" and "?" to search.

-tim



pixelterra

unread,
Apr 27, 2012, 3:00:43 PM4/27/12
to vim...@googlegroups.com, pixelterra
Actually, I was wrong, this doesn't work. Sorry for the confusion. Any other options?

Gary Johnson

unread,
Apr 27, 2012, 3:49:11 PM4/27/12
to vim...@googlegroups.com
On 2012-04-27, pixelterra wrote:
> Actually, I was wrong, this doesn't work. Sorry for the confusion.
> Any other options?

What do you mean, "this doesn't work"? If you mean you still want
to have the edited command on the command line and not executed when
you exit vim, I don't think bash lets you do that, but I've heard
zsh does.

I usually just exit with :wq or ZZ and let bash execute it.

Regards,
Gary

John Little

unread,
Apr 28, 2012, 4:03:10 AM4/28/12
to vim...@googlegroups.com, pixelterra
On Saturday, April 28, 2012 7:00:43 AM UTC+12, pixelterra wrote:
> Actually, I was wrong, this doesn't work. Sorry for the confusion. Any other options?

It should. Have you got any of VISUAL, EDITOR or FCEDIT set? (A pitfall is to set one of these to just "gvim", which won't work, "gvim -f" is needed.) Is TMPDIR set?

Does vim open in your terminal window? What file is it using? (mine uses /tmp/bash-fc-nnnnnnnnnnn where nnnnnnnnnnn appears to be generated randomly).

You might try setting EDITOR="vim -u NONE" to eliminate the possibility of a .vimrc or plugin interfering.

Regards, John

Reply all
Reply to author
Forward
0 new messages