complement to <ctrl-w>T

14 views
Skip to first unread message

sco...@ckhb.org

unread,
Jan 6, 2023, 12:32:31 AM1/6/23
to vim...@googlegroups.com

is there a complement to <ctrl-w>T?

i do file diffs in a split tab page and occassionally move one of the windows to
a new tab page. is there any existing mechanism for moving a file in a tab page
to an empty window in another tab page?


--

Enan Ajmain

unread,
Jan 6, 2023, 1:13:00 AM1/6/23
to vim...@googlegroups.com
There is no existing mechanism, no. And I don't think there is any
concept of an "empty window" in Vim. I guess you're talking about
':new' windows with unnamed buffer ([No Name]).

In any case, you should be able to build yourself a function.

1. Get current buffer number (see ':h bufnr'). Say it's "3".
2. Move to the tab where you want to move the buffer (':norm! <n>gt'),
where "<n>" is an integer.
3. Split a window and open the buffer "3" (':split | b3').
4. Return.

--
Enan
3nan....@gmail.com
https://git.sr.ht/~enan/
https://www.github.com/3N4N

Salman Halim

unread,
Jan 6, 2023, 9:41:26 AM1/6/23
to vim...@googlegroups.com
I use the following mappings to create a new tab and move the current buffer from here to there or to copy it to there (so that it remains here AND shows up in the new tab, also):

" Moves the current buffer to a new tab; I can type this faster than <c-w>T
nmap <leader>nt <c-w>T
" Opens a new tab with the current buffer in it, leaving the current buffer in the current tab as well.
nmap <leader>nT :sp<cr><leader>nt

If you want to move the current file to an already existing tab, then I included MoveToTab and CopyToTab commands in my tab manager (https://www.vim.org/scripts/script.php?script_id=3536) that takes a single parameter: the number of the destination tab, $ to mean the last tab, n to mean the next tab or p to mean the previous tab.

I hope one of these does what you want.

All the best,

Salman 
Reply all
Reply to author
Forward
0 new messages