I want to set up some mapping that:
- if there are multiple open tabs, then goes to the next tab, like
:gt
- otherwise it cycles through the open buffers, like
:bn
How do I go about doing this?
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.
Sign up to join this communityYou could use expression mappings:
nnoremap <expr> YOUR_KEY len(gettabinfo()) > 1 ? 'gt' : ':bn<CR>'
nnoremap <expr> YOUR_KEY len(gettabinfo()) > 1 ? 'gT' : ':bN<CR>'
<expr>
says to interpret the mapping as an expression. gettabinfo()
returns the list of the open tabs so if the length of this list is greater than one you know you have more than one tab. Depending on the result you want your mapping to execute either the tab command or the buffers one.