I have a section in file1 that should be moved to file2 . I usually did this by visually selecting a block, deleting it :wq from file1 , open file2 , then paste.
section
file1
file2
:wq
Is there an easy way to move a block of text from file to file2 without closing vim ?
file
vim
You can open your new file in a split with :sp newfile , and then remove the block as usual from your first file. Then move on to another split using ctrl w and w . Then use p to put the deleted content in another file.
:sp newfile
p
As an alternative:
write the selection to a new file :'<,'>w file2
:'<,'>w file2
then reselect and delete with gvd
gvd
The first step is described in vimtutor Lesson 5.3: SELECTING TEXT TO WRITE .
Lesson 5.3: SELECTING TEXT TO WRITE
You can open the file in a new buffer.
just open the file with :e file2 and paste the text. To quickly move between buffers, use either :e # or :b #
:e file2
:e #
:b #
see :help buffers for more information
:help buffers
Since no one mentioned this: you can use tabs instead.
Select your block.
Delete it with d
d
Create a new buffer in a new tab with :tabnew newfile.name
:tabnew newfile.name
Insert it and save with p and :w
:w
You can return with gT or close the current tab with :q
gT
:q
Personally, new usage buffers are only tabs. Read more about them in :help tabpage
:help tabpage