Write Lines To Another File Using Vim/Vi
This page answers questions like these:
- How to write some lines of a file to a new file using vim/vi?
- How to write some lines of a file to another file using vim/vi?
- How to write specific line numbers from one file to another using vim/vi?
Related Links:
Find Surrounding Code Block in Vim
Fold/Collapse/Hide Code Blocks in Vim
Expand/Show/Open Collapsed/Hidden/Folded Text in Vim
Replace with Confirmation in Vim
E432: Tags file not sorted: tags | E257: cstag: tag not found | E426: tag not found:
Copy Specific Line Numbers from One File to Another File:
vim FILE1
:4,17w!FILE2
- Open FILE1 using vim/vi.
- Write (w) from line 4 to line 17 (inclusive) to FILE2.
Copy Some Lines of One File to Another File:
vim FILE1
Move to any position on the first line you want to copy (using commands like j, /, %, etc.)
ma
Move to any position on the last line you want to copy (using commands like j, /, %, etc.)
:'a,.w!FILE2
- Open FILE1 using vim/vi.
- Move to any position on the first line you want to copy (using commands like j, /, %, etc.)
- Mark (m) that line as a. (In fact, you can use any letter from a to z or A to Z that you choose.)
- Move to any position on the last line you want to copy (using commands like j, /, %, etc.)
- Write (w) from the line marked a (i.e. 'a) to the current line (i.e. .) (inclusive) into FILE2.
- N.B. If you marked the last line first, then moved to the first line, you can write out the lines using :.,'aw!FILE2 instead.
Related Links:
Find Surrounding Code Block in Vim
Fold/Collapse/Hide Code Blocks in Vim
Expand/Show/Open Collapsed/Hidden/Folded Text in Vim
Replace with Confirmation in Vim
E432: Tags file not sorted: tags | E257: cstag: tag not found | E426: tag not found:
Home > Vim > Write Lines To Another File Using Vim/Vi
Tags: replace with confirmation, confirmation, confirm, replace with confirm, global replace, replace, yes/no, vim
Copyright © HelpDoco.com
vim-write-lines-to-file.txt
Vim/vim-write-lines-to-another-file.htm
2