tabedit and closing

32 views
Skip to first unread message

rwmit...@gmail.com

unread,
Mar 18, 2021, 10:02:33 AM3/18/21
to vim_use
I have multiple tabs open using :tabedit
I'm in a tab other than the right most.
:tabedit  opens a new tab to the right of the current tab
:q closes that tab but also advances the current tab again to the right.

Is there a setting to instead advance the current tab to the left?
I'd prefer to return to the previous tab, where I had just run :tabedit

BPJ

unread,
Mar 18, 2021, 10:51:20 AM3/18/21
to vim_use
I have this in .vimrc:

:com Tc tabclose | tabprevious
nnor <F12>t :Tc<cr>

Works like a charm!



--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/7354d4ed-085b-47ae-b48e-13cb2ae8e0een%40googlegroups.com.

rwmit...@gmail.com

unread,
Mar 18, 2021, 11:24:35 AM3/18/21
to vim_use
Does that require using the F12 key or does it somehow also work when just using :wq  ?

BPJ

unread,
Mar 18, 2021, 12:09:28 PM3/18/21
to vim_use
Den tors 18 mars 2021 16:25rwmit...@gmail.com <rwmit...@gmail.com> skrev:
Does that require using the F12 key or does it somehow also work when just using :wq  ?

You can't redefine the :wq command since user commands have to start with a capital letter but you could certainly call the command Wq or WQ if you like, but since my command does *not* write the file automatically. To get that behavior I would rather use

:com Wq wq | tabprevious

The nnor is a mapping, not a command, so that in normal mode I can just type F12 + c (<F12>t was a typo for <F12>c) to execute the command above without going into ex mode first (the map does that for me!) If you want such a mapping at all you can assign it to any free key sequence. I would advise against mapping it to wq however since it is all too easy (at least for me!) to type wqq by mistake and thereby starting to record everything you type into the @q register.

However I have the whole set of :tab... commands mapped to F12 combos in my .vimrc because I use them all the time:

nnor <F12>n :tabnext<cr>
nnor <F12>p :tabprevious<cr>
nnor <F12>f :tabfirst<cr>
nnor <F12>l :tablast<cr>
nnor <F12>t :ls t<cr>
com Tc tabclose | tabprevious
nnor <F12>c :Tc<cr>


--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.

Gary Johnson

unread,
Mar 18, 2021, 12:14:43 PM3/18/21
to vim_use
On 2021-03-18, rwmit...@gmail.com wrote:
> On Thursday, March 18, 2021 at 10:51:20 AM UTC-4 BPJ wrote:
>
>> Den tors 18 mars 2021 15:03rwmit...@gmail.com <rwmit...@gmail.com> skrev:
>>
>> I have multiple tabs open using :tabedit
>> I'm in a tab other than the right most.
>> :tabedit  opens a new tab to the right of the current tab
>> :q closes that tab but also advances the current tab again to the
>> right.
>>
>> Is there a setting to instead advance the current tab to the left?
>> I'd prefer to return to the previous tab, where I had just run :tabedit
>>
>>
>> I have this in .vimrc:
>>
>> :com Tc tabclose | tabprevious
>> nnor <F12>t :Tc<cr>
>>
>> Works like a charm!
>
> Does that require using the F12 key or does it somehow also work when just
> using :wq ?

The following seems to work in both cases, though I haven't tested
it extensively.

:autocmd TabClosed * tabprevious

Regards,
Gary

rwmit...@gmail.com

unread,
Mar 18, 2021, 12:44:00 PM3/18/21
to vim_use
On Thursday, March 18, 2021 at 12:14:43 PM UTC-4 Gary Johnson wrote:
On 2021-03-18,gmail.com wrote:
> On Thursday, March 18, 2021 at 10:51:20 AM UTC-4 BPJ wrote:
>
>> Den tors 18 mars 2021 15:...@gmail.com> skrev:
>>
>> I have multiple tabs open using :tabedit
>> I'm in a tab other than the right most.
>> :tabedit  opens a new tab to the right of the current tab
>> :q closes that tab but also advances the current tab again to the
>> right.

The following seems to work in both cases, though I haven't tested
it extensively.

:autocmd TabClosed * tabprevious

Regards,
Gary

Beautiful!
Just works.  No change to how I work. 

( I appreciate all responses, but this is what I was looking for! )

BPJ

unread,
Mar 18, 2021, 2:32:23 PM3/18/21
to vim_use
I quite like it too! I probably should take some time to learn about :autocmd!


( I appreciate all responses, but this is what I was looking for! )

I was also looking for this, without knowing it! :-)

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages