mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 23:28:02 +00:00
Add Difference Between wq and x as a vim til.
This commit is contained in:
@@ -302,6 +302,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
|
||||
- [Delete Every Other Line](vim/delete-every-other-line.md)
|
||||
- [Delete Lines That Match A Pattern](vim/delete-lines-that-match-a-pattern.md)
|
||||
- [Deleting Directories Of Files From netrw](vim/deleting-directories-of-files-from-netrw.md)
|
||||
- [Difference Between :wq and :x](vim/difference-between-wq-and-x.md)
|
||||
- [Display Word Count Stats](vim/display-word-count-stats.md)
|
||||
- [Edges Of The Selection](vim/edges-of-the-selection.md)
|
||||
- [End Of The Word](vim/end-of-the-word.md)
|
||||
|
||||
23
vim/difference-between-wq-and-x.md
Normal file
23
vim/difference-between-wq-and-x.md
Normal file
@@ -0,0 +1,23 @@
|
||||
# Difference Between :wq and :x
|
||||
|
||||
The `:wq` command is used in Vim to write and quit. The contents of the
|
||||
buffer are written to disk for the associated file and then the Vim session
|
||||
is terminated. So, what is the difference between this and the `:x` command.
|
||||
The Vim help files give the following description of the `:x` command:
|
||||
|
||||
> Like ":wq", but write only when changes have been made.
|
||||
|
||||
So, `:wq` writes the buffer to disk either way, whereas `:x` just exits if the
|
||||
buffer hasn't changed. Either way the contents of the resulting file are
|
||||
going to be the same. So what's the difference?
|
||||
|
||||
Modification time.
|
||||
|
||||
If you `:x` a buffer that hasn't changed, the modification time will be
|
||||
untouched because the file isn't *re-saved*. The `:wq` command will alter
|
||||
the modification time no matter what.
|
||||
|
||||
This matters if the modification time is used by anything. For instance, a
|
||||
background process that monitors a directory for changed files based on
|
||||
modification times will get some false positives if you use `:wq` to
|
||||
liberally.
|
||||
Reference in New Issue
Block a user