7

Any way to save changes in vi without exiting the editor? I'm experimenting with php and checking my work in the browser. To get back to my code I have to reopen the php file which is an extra step.

Thanks.

Scandalist
  • 3,091

3 Answers3

7

:w to save

:q to quit

:q! to quit in spite of unsaved changes

I'm assuming that you are asking becasue you have been using combination of the two :wq

sgp667
  • 731
4

These commands operate only on the current buffer:

:write, or :w to save

:update, or :up to save only if changes were made (vim only)

:wq to save (current buffer only) and quit

:exit, or :x to save (current buffer only), but only if changes were made, then quit

These all have 'force' variants, e.g. :wq!, to write the current buffer and quit, even if other buffers contain unsaved changes.

 

Multiple buffers:

:wall, or :wa to write all buffers which have changed (vim only)

:wqall, or :wqa to write all changed buffers, then quit (vim only)

 

Shortcuts:

The key sequence ZZ in normal mode is a shortcut for :exit

The key sequence ZQ in normal mode is a shortcut for :q! (vim only)

2
:w filename 

This will write to that specified filename.

... useful when you're trying to track changes and not overwrite.

slhck
  • 228,104
JanFrazini
  • 21
  • 2