3

I'm searching through a big text file and want to copy certain lines to another file - there is no specific pattern, I need to visually inspect and copy those lines to an external file. The command :2400p prints line 2400 to the Vim command line, but I can't get it to write (append) it to another file. I could use more or less but not sure that would help any better.

6

You can use :[range]w >> file to append the given range to the given file. If the file does not yet exist, use the ! argument to the :w command to force writing the new file.

So this means you can use :2400w >> my_custom.txt to write line 2400 to my_custom.txt file, or if your cursor is on the current line already, you can simply use :.w >> my_custom.txt (which could then e.g. be used by a :g command, to write lines matching a certain pattern).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.