Skip to main content
added 1 character in body; edited title
Source Link
muru
  • 78.3k
  • 16
  • 214
  • 320

In vi/vim, how to writedo I append to a file by appending to it instead of overwriting it?

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:

  1. Open the log file
  2. Select some lines with Shift+v
  3. Write to a file: :w /tmp/samples
  4. Select some more lines with Shift+v
  5. Append to /tmp/samples with :w !cat - >> /foo/samples

Unfortunately step 5 is long, ugly and error prone (missing a > makes you lose data). I hope vimVim has something better here.

In vi/vim, how to write to a file by appending to it instead of overwriting it

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:

  1. Open the log file
  2. Select some lines with Shift+v
  3. Write to a file: :w /tmp/samples
  4. Select some more lines with Shift+v
  5. Append to /tmp/samples with :w !cat - >> /foo/samples

Unfortunately 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?

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:

  1. Open the log file
  2. Select some lines with Shift+v
  3. Write to a file: :w /tmp/samples
  4. Select some more lines with Shift+v
  5. Append to /tmp/samples with :w !cat - >> /foo/samples

Unfortunately step 5 is long, ugly and error prone (missing a > makes you lose data). I hope Vim has something better here.

Tweeted twitter.com/StackUnix/status/717161354633822208
Source Link
Bruno Polaco
  • 363
  • 1
  • 3
  • 6

In vi/vim, how to write to a file by appending to it instead of overwriting it

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:

  1. Open the log file
  2. Select some lines with Shift+v
  3. Write to a file: :w /tmp/samples
  4. Select some more lines with Shift+v
  5. Append to /tmp/samples with :w !cat - >> /foo/samples

Unfortunately step 5 is long, ugly and error prone (missing a > makes you lose data). I hope vim has something better here