Note - read Marks & Registers before reading this post.
There are some other ways of copy or delete text in vi.
Working with paragraphs:
If you are in paragraph text you can use } and { to move cursor to the beginning or ending of the paragraph respectively. so if you want to move a paragraph you can use { and d} .
and p to paste the content. if you are already in beginning or ending of a paragraph you can use d} and d{ respectively to cut the paragraph.
If you want to delete 3 continuous paragraphs you can use d3} (From current to next 3 paragraphs will be cut)
And if you want to move multiple paragraphs from multiple locations to other locations we can make use of registers ( Marks & Registers ).
Ex:
I am at para 1: hit "ad3} to cut 3 paragraphs to the register 'a'
I am at para 9: hit "by} to copy next paragraph to the register 'b'
At EOF: hit "ap and "bp to paste the paragraphs.
Copy/Cut by Search:
Search using / or ? is most notable technique in vi. But if you want to copy the content from current line to the next line containing a specific word ??.
for example one can use y/foo to copy the text from current line to next line containing the word 'foo'. similarly 'd' can be used to cut ( d/foo).
y?foo
to copy from the current line to the most recent (previous) line containing 'bar'.Similarly as above we can use registers to copy/cut these content.
Thus if you use
"ay/foo
then you are yanking a copy of the text from here to the next line containing "foo" into the 'a' register. and can use "ap to paste the content.
0 comments:
Post a Comment