0

I would like to make a new tab page from part of the current text. I would use visual selection, or other means to specify a text range.
Is there a single command like "New tab from selection"?

Writing this, I see the command is not exactly of vim style.

In that case, a small script may solve it.

Possibly there is a related plugin containing it?
Here, one could reasonably hope for useful related features like creating a new file with derived name.

1
  • 1
    Simple way is map key to three command in row <,>y - for yank visual range tabnew - for creating new tab p - for paste yanked text in first step
    – Alex Kroll
    May 28, 2015 at 13:42

1 Answer 1

8

Persisted

If you intend to persist the selected lines under a new filename (and it's complete lines), you can do:

:'<,'>w new-name | '<,'>delete _ | tabedit #

The '<,'> range is inserted automatically when you enter command-line mode from visual mode. :write can take a range, and afterwards, the filename is accessible via the alternate file (#) shortcut.

Unpersisted

If you just need a scratch buffer that is not written to disk, you have to delete and put:

d:tabedit +set\ buftype=nofile new-name | put!

If you use this frequently, I would write a custom command (that also saves and restores the original register contents) for it.


If you want cloning, not moving, drop the :delete / change d into y.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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