diff --git a/README.md b/README.md index e23ea77..38983aa 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/vim/difference-between-wq-and-x.md b/vim/difference-between-wq-and-x.md new file mode 100644 index 0000000..199939d --- /dev/null +++ b/vim/difference-between-wq-and-x.md @@ -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.