开发者

Overwrite without getting Do you really want to write to it (y/n)? in vim editor

开发者 https://www.devze.com 2023-03-07 03:57 出处:网络
How to get rid of the message mentioned in the tit开发者_运维问答le of the postFrom vims help on :w!:

How to get rid of the message mentioned in the tit开发者_运维问答le of the post


From vims help on :w!:

                            *:w!*
:[range]w[rite]! [++opt] {file}
            Write the specified lines to {file}.  Overwrite an
            existing file.

Or is it this you are after?:

                *'confirm'* *'cf'* *'noconfirm'* *'nocf'*
'confirm' 'cf'      boolean (default off)
            global
            {not in Vi}
    When 'confirm' is on, certain operations that would normally
    fail because of unsaved changes to a buffer, e.g. ":q" and ":e",
    instead raise a |dialog| asking if you wish to save the current
    file(s).  You can still use a ! to unconditionally |abandon| a buffer.
    If 'confirm' is off you can still activate confirmation for one
    command only (this is most useful in mappings) with the |:confirm|
    command.
    Also see the |confirm()| function and the 'v' flag in 'guioptions'.

Or perhaps even autowrite/autowriteall:

                 *'autowrite'* *'aw'* *'noautowrite'* *'noaw'*
'autowrite' 'aw'    boolean (default off)
            global
    Write the contents of the file, if it has been modified, on each
    :next, :rewind, :last, :first, :previous, :stop, :suspend, :tag, :!,
    :make, CTRL-] and CTRL-^ command; and when a :buffer, CTRL-O, CTRL-I,
    '{A-Z0-9}, or `{A-Z0-9} command takes one to another file.
    Note that for some commands the 'autowrite' option is not used, see
    'autowriteall' for that.

             *'autowriteall'* *'awa'* *'noautowriteall'* *'noawa'*
'autowriteall' 'awa'    boolean (default off)
            global
            {not in Vi}
    Like 'autowrite', but also used for commands ":edit", ":enew", ":quit",
    ":qall", ":exit", ":xit", ":recover" and closing the Vim window.
    Setting this option also implies that Vim behaves like 'autowrite' has
    been set.

A great future in vims help system is that you type something and then press "ctrl-d", vim will then display all matching entries:

:help autowrite ctrl-d
'autowrite' 'autowriteall' 'noautowrite' 'noautowriteall'

What you also can do is to have vim write to file as soon as the focus changes by adding this to your .vimrc file:

au FocusLost * :wa
0

精彩评论

暂无评论...
验证码 换一张
取 消