One way is to exit vim with the :cq command. See
:help :cq
That will quit vim with an error code telling bash that the editing
was unsuccessful.
Another is to delete the contents of the vim buffer before saving
and quitting as normal, e.g., dd if there is only one line in the
buffer or ggdG to if there is more than one line, followed by ZZ or
:wq to save and quit.
In this case, you _do_ want to save something because that something
is what bash will execute.
I usually use dd:wq because the :w makes me feel more sure that
the empty buffer has actually been written.
Regards,
Gary
On Fr, 23 M�r 2012, Ven Tadipatri wrote:
> Hi,
> This may sound like a real newbie question, but when I do the "set -o
> vi"
> in the bash command line shell, if I hit <Esc> and v on the command line,
> it goes into vi editing mode. This is kind of cool, as I can exercise
> the full editing power of vi, and when I exit the editor it runs the
> command.
> Unfortunately, sometimes I may have a really
> powerful/dangerous/unnecessary
> command that I've typed, and all I want to do is just cancel, not execute
> the
> command. How do I do this?
> :q! doesn't seem to work, as the command still runs. :wq , well, I don't
> want
> to save anything, I just want to get out of the editor and return to the
Actually, :q! should work and always did for me.
I would guess, that bash only executes the file, if it's timestamp has
been changed. May be some plugin that sets an WriteCmd autocmd or
something?
Mit freundlichen Gr��en
Christian
--
Wie man sein Kind nicht nennen sollte:
Don Erstag
I always ddZZ and I think it's the best approach because this is
not something you might use often and remembering a special :cq
for it makes no sense because everybody knows dd and it works
perfectly well for this use case.
I like it better than :q! because it's easier to type, because
I hardly ever use :q! and dd is more visually explicit, i.e.
you can see "this is what will get executed - nothing", with
:q! I think if I take a longer time to edit the command, I
might save it accidentally as I'm working on it, and then
exiting will run the saved version.
I also use the same dd command when I edit the regular command
line and then decide I don't want to run it.
-ak
Numbered commands like 4k work too, of course. I use 2k very often, but
I don't think I ever use higher numbers than that. -ak
Hi Ven!
Mit freundlichen Grüßen
Try 0D
(move cursor to beginning of line, delete contents from cursor to
end-ofline)
Regards,
Chip Campbell
I think dd is easier. The OP said, though, that he is talking about
vim launched from command line. -ak
I'm afraid that I've looked over the OP's first two messages and don't
see where vim was launched, though:
Title: Bash's vi command line editing mode
Excerpt: ...but when I do the "set -o vi" in the bash command line shell,...
Excerpt: ...if I hit <Esc> and v on the command line, it goes into vi
editing mode...
Excerpt: ...when I exit the editor it runs the command... (when one
exits Vim, typically it doesn't cause any commands to run)
Regards,
Chip Campbell
When you hit Esc and v in bash (or zsh), it does start the vim
editor, and when you exit it, it puts the buffer in command line,
it doesn't run it immediately but waits for you to press Enter.
-ak
Regards,
Chip Campbell
> When you hit Esc and v in bash (or zsh), it does start the vim
> editor, and when you exit it, it puts the buffer in command line,
> it doesn't run it immediately but waits for you to press Enter.
It has never waited for me, using either ksh or bash--the shell has
always immediately executed the contents of the vim buffer as soon
as I exit vim. I wonder if there is some shell option that controls
that.
Regards,
Gary
I actually use zsh, and that's what it does, I only assumed bash
does the same. -ak
I'm afraid that I've looked over the OP's first two messages and don't see where vim was launched, though:
Title: Bash's vi command line editing mode
Excerpt: ...but when I do the "set -o vi" in the bash command line shell,...
Excerpt: ...if I hit <Esc> and v on the command line, it goes into vi editing mode...
Excerpt: ...when I exit the editor it runs the command... (when one exits Vim, typically it doesn't cause any commands to run)
Regards,
Chip Campbell
--
I use vi mode with bash on OSX (10.9). As expected, <esc> v puts the current command into a buffer. However, when I :wq, the command is *not* executed.
Could there be a setting in .vimrc that causes this?
originally, they were set to:
nobackup
nowritebackup
backupcopy=no
I tried enabling some/all of them, but still no luck.
I then just removed my .vimrc, which made the command execute. Then I went with a good old trial and error: comment out my entire .vimrc and enable section after section. Luckily, it was already the 2nd paragraph that broke the execution: it is my pathogen settings:
filetype off
silent! call pathogen#runtime_append_all_bundles()
silent! call pathogen#helptags()
filetype plugin indent on
I tried commenting in/out just individual lines, but they all broke it. After some more fiddling around, I came up with this workaround, which looks nasty (and I'm not happy about it) but it works:
if expand('%:t') =~?'bash-fc-\d\+'
setfiletype sh
else
filetype off
silent! call pathogen#runtime_append_all_bundles()
silent! call pathogen#helptags()
filetype plugin indent on
endif
Basically: when I'm editing commands, I prevent pathogen from running (which means none of my plugins get loaded). If somebody has a better way or knows what I need to do to pathogen to make it work, please let me know!
In the meantime, I hope this helps other people in my position.
I tried this, but unfortunately it didn't work either.
Thanks for the tip though. I updated my version of pathogen and changed my vimrc to use the new function.
Maybe it's a combination of things on my system. The workaround is fine for now. Once I have more time, I will have another look at this. If I find the culprit (probably an incompatible bundle?!?), I will post here.
Gilles