4

Get manual with help:

help :w_c:
:[range]w[rite] [++opt] !{cmd}

      Execute {cmd} with [range] lines as standard input
      (note the space in front of the '!').  {cmd} is
      executed like with ":!{cmd}", any '!' is replaced with
      the previous command |:!|.

  1. What does ++opt means?

No words describe it in the text.

  1. To where do the w save ?

w means to save,save file in some directory,when :[range]w !{cmd} is my command form,to where do the w save?

showkey
  • 1,130
  • 2
  • 11
  • 30
  • 1
    Regarding :w !cmd, it actually doesn't write to a file, but it starts running external cmd with a pipe attached to it, and Vim then sends the contents of the buffer (or of the selected range) to that pipe, effectively passing it as the standard input of the external command. – filbranden Apr 17 '22 at 03:47

1 Answers1

7

You can actually find more about that under :help ++opt, which lists the 5 or 6 possible keywords that can be used under that setting.

The available settings typically control special file attributes, such as file format (DOS vs Unix), or file encoding (Unicode or Latin-1 or plain ASCII or some other special encoding for specific languages) or what to do when encountering invalid sequences for that encoding, or whether to use binary mode (preserving special characters when editing binary data).

For example, to write the current buffer to a file, in DOS format, with Latin-1 encoding, you could use:

:w ++ff=dos ++enc=iso-8859-1 myfile.txt

The ++opt settings are also available through options you can use :set on, so for :w it's often possible to just set those explicitly (e.g. :set ff=dos fenc=iso-8859-1) and simply use :w.

However, when opening a new file with :e, it's usually not possible to set these options after the file has already been read, since these options affect how the contents of the file will be handled while reading it, so the ++opt settings become essential to properly handle those files while opening them. Usually the settings are preserved from :e, so as long as you opened the file correctly, you typically don't need to pass the same ++opt settings to :w when simply saving the file with the same options.

filbranden
  • 28,785
  • 3
  • 26
  • 71