I know I can write to a file by simply doing :w <file>. I would like to know though how can I write to a file by appending to it instead of overwriting it.Example use case: I want to take some samples out of a log file into another file. To achieve that today I can do:Open the log fileSelect some lines with Shift+vWrite to a file: :w /tmp/samplesSelect some more lines with Shift+vAppend to /tmp/samples with :w !cat - >> /foo/samplesUnfortunately step 5 is long, ugly and error prone (missing a > makes you lose data). I hope Vim has something better here.
In vi/vim, how do I append to a file instead of overwriting it?
text processing;vim;vi
From :h :w:                                                :w_a :write_a E494:[range]w[rite][!] [++opt] >>                        Append the specified lines to the current file.:[range]w[rite][!] [++opt] >> {file}                        Append the specified lines to {file}.  '!' forces the                        write even if file does not exist.So, if you have selected the text using visual mode, just do :w >> /foo/samples (:'<,'> will be automatically prepended). If you miss out on a >, Vim will complain:E494: Use w or w>>