ap / vim-buftabline

Forget Vim tabs – now you can have buffer tabs
http://www.vim.org/scripts/script.php?script_id=5057
MIT License
791 stars 72 forks source link

Mapping for changing buffer with a count #59

Closed psmolak closed 6 years ago

psmolak commented 6 years ago

Instead of these

nmap <leader>1 <Plug>BufTabLine.Go(1)
nmap <leader>2 <Plug>BufTabLine.Go(2)
nmap <leader>3 <Plug>BufTabLine.Go(3)
nmap <leader>4 <Plug>BufTabLine.Go(4)
nmap <leader>5 <Plug>BufTabLine.Go(5)
nmap <leader>6 <Plug>BufTabLine.Go(6)
nmap <leader>7 <Plug>BufTabLine.Go(7)
nmap <leader>8 <Plug>BufTabLine.Go(8)
nmap <leader>9 <Plug>BufTabLine.Go(9)
nmap <leader>0 <Plug>BufTabLine.Go(10)

I would like to have a simple maping for <space> which would take a count parameter. Then after invoking 5<space> I would expect vim to switch to 5'th buffer according to the ordinal numbering g:buftabline_numbers = 2.

I wouldn't bother, however I simply can't spend days reading Vim's documentation and figuring out its quirks just to do such simple thing :disappointed:

EDIT: Great plugin btw!

ap commented 6 years ago

Voilà: nmap <expr> <Space> '<Plug>BufTabLine.Go(' . v:count . ')'

psmolak commented 6 years ago

Works like a charm. I allowed myself a small tweak:

nmap <expr> <tab> v:count > 0 ? '<Plug>BufTabLine.Go(' . v:count . ')' : ':bnext<cr>'
nmap <expr> <s-tab> v:count > 0 ? '<Plug>BufTabLine.Go(' . v:count . ')' : ':bprev<cr>'

Thank you!

ap commented 6 years ago

Gladly 😊