54

If I have multiple files in tabs on VIM and I edit few of them. How to save them with one command?

rp101
  • 1,239
  • 2
  • 10
  • 10

6 Answers6

63

The command wa (short for wall) will write all changed buffers. You can also use :tabdo w, which is definitely exactly what you want, and generalizes nicely.

Cascabel
  • 479,068
  • 72
  • 370
  • 318
  • 20
    `:tabdo w` is not equivalent to `:wa`. If a tab has multiple windows open, `:tabdo w` will only save the currently focused window in each tab, whereas `:wa` will save all of them. `:wa` will also save hidden buffers. – Andrew Marshall Feb 08 '13 at 17:29
28

Just do

:wa

(followed by return) which is a shorthand for

:wall

Also to "save everything and exit" you can do

:wqa or :xa

(="write-quit-all")

kenorb
  • 155,785
  • 88
  • 678
  • 743
Paul
  • 7,836
  • 2
  • 41
  • 48
11

It's possible to suffix a[ll] for a number of Vim command-line commands (i.e. type : when in normal mode), include:

  • :wa - save all tabs / unsaved buffers

  • :xa/:wqa - save all tabs / unsaved buffers and exit Vim

  • :qa - exit vim (will warn if unsaved buffers exist)

kenorb
  • 155,785
  • 88
  • 678
  • 743
snowbound
  • 1,692
  • 2
  • 21
  • 29
7

To save all the files just use an a after the write command to write all the files.

:wa
Colin Newell
  • 3,073
  • 1
  • 22
  • 36
4

And you can use :tabdo! w too, I'm just adding this, because it's useful for other things too (e.g. :tabdo! g/somepattern/ s/something/anything/... I use it all the time for refactoring purposes...)

Zsolt Botykai
  • 50,406
  • 14
  • 85
  • 110
  • 1
    I'd recommend a read on `help :g`, but in short, it only applies the next command (in my case the `s/something/anything/` to the lines, that matches `somepattern`). Yeah I know, that usually I can do that without the `:g`, but sometimes not (I used to match multiline regexes via `\\_.`), and the best part is `:g`'s little "sister" `:v`. – Zsolt Botykai Nov 22 '10 at 22:01
  • See [my comment on the other post above](http://stackoverflow.com/questions/4246268/how-to-save-all-files-in-tabs-on-vim#comment20689678_4246310) for why `:tabdo w` may not work as expected. – Andrew Marshall Feb 08 '13 at 17:32
  • @AndrewMarshall Thanks TIL about those behavior of `:tabdo w`. – Zsolt Botykai Feb 10 '13 at 19:27
3

Check out :wall command

Arnis Lapsa
  • 45,880
  • 29
  • 115
  • 195