On 09/12/2009 07:25 AM, Ismael Barros² wrote:
> Looks like ":wq!" on the back would actually be a great
> conversation starter!
In that vein, I find this an interesting topic for a
conversation :-)
One of things I really enjoy about this mailing list is the
opportunity to improve my Vim knowledge. I often end up at the
:help command to read (or, often enough, re-read) about the
topic at hand. Realizing I didn't know with certainty how :wq!
worked, I checked the help:
:wq [++opt] Write the current file and quit. Writing fails when
the file is read-only or the buffer does not have a
name. Quitting fails when the last file in the
argument list has not been edited.
:wq! [++opt] Write the current file and quit. Writing fails when
the current buffer does not have a name.
When I was first learning Vim, I thought :wq was actually just a
shortcut way of writing two commands together (:w and :q), and I
spent some time trying to generalize to the rules for combining
commands. In reality, of course, it's just a separate command
that takes its name from the other two.
I went to the help today because I realized I didn't know
whether the "!" was, loosely speaking, applying to the :w
portion or the :q portion of the :wq command. From the manual
again:
:w[rite] [++opt] Write the whole buffer to the current file. This is
the normal way to save changes to a file. It fails
when the 'readonly' option is set or when there is
another reason why the file can't be written.
For ++opt see |++opt|, but only ++bin, ++nobin, ++ff
and ++enc are effective.
:w[rite]! [++opt] Like ":write", but forcefully write when 'readonly' is
set or there is another reason why writing was
refused.
Note: This may change the permission and ownership of
the file and break (symbolic) links. Add the 'W' flag
to 'cpoptions' to avoid this.
:q[uit] Quit the current window. Quit Vim if this is the last
window. This fails when changes have been made and
Vim refuses to |abandon| the current buffer, and when
the last file in the argument list has not been
edited.
If there are other tab pages and quitting the last
window in the current tab page the current tab page is
closed |tab-page|.
:q[uit]! Quit without writing, also when visible buffers have
changes. Does not exit when there are changed hidden
buffers. Use ":qall!" to exit always.
Given the above, I think the "!" in ":wq!" seems to apply to
both the :w and the :q operations implied by :wq, in that a
read-only file will be forcibly written (as if via :w!) and the
quit will succeed even in the face of unvisited files in the
argument list (as if via :q!). Does this seem like the correct
interpretation? I'd like to think of it this way, but only if
that's actually what's going on. I did a test or two, and I
note that both :q! and :wq! fail to actually quit if a hidden
buffer has unsaved changes (a feature described in the help for
:q! but not for :wq!).
Michael Henry
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---