0

I'm in a file and want to copy and edit part of the file content in a new tab temporarily.

I know that I can write it in a file using :'<,'> w /tmp/list.txt, then :tabnew /tmp/list.txt.

But what if I don't want to write a file and open it afterwards? Do you know a better and/or faster way?

pedyram
  • 101
  • 1

2 Answers2

1

Imagine you want to have range 6, 16 of lines into a new tab buffer:

  1. tabnew
  2. :call setline(1, getbufline('#', 6, 16))

Alternate buffer # would be set to the buffer you start tabnew from.

Or, for example, if you want to "copy" a visual:

func! IntoNewTab() abort
    let lines = getline("'<", "'>")
    tabnew
    call setline(1, lines)
endfunc
xnoremap g<C-t> :<C-u>call IntoNewTab()<CR>
Maxim Kim
  • 13,376
  • 2
  • 18
  • 46
0

A simple (as in no mappings or function calls) version of Maxim Kim's answer is

  1. Yank the text you want to edit (plenty of ways to do this)
  2. :tabnew
  3. p
  4. Edit…
  5. :%yank the modified text back
  6. :tabclose
  7. Put the modified text over top of the original
D. Ben Knoble
  • 26,070
  • 3
  • 29
  • 65