1

I am using multiple files within the same tab and when I switch buffers using :bn I reach the terminal, at which point I have to issue the command again to move. Here is the catch, I am using keymaps to do buffer switching instead of typing the entire command.

is there a way to skip the terminal buffer and move on with this keymap.

The possible solution I can think as of now is using a separate tab for the terminal while keeping the present one for code. this is not a huge deal, just keeping my laziness alive.

Any and all ideas are appreciated.

  • 1
    I don't think your suggested workaround will work. Having the terminal buffer open in a tab won't prevent :bn from opening it in another tab. – Rich Jul 10 '18 at 9:27
  • Have you thought about jumping to the exact buffer instead of cycling? You can use :b partial<tab> to go directly where you want to go. Related question: How can I prevent some buffers from being reachable using bnext, bprev? – Peter Rincker Jul 11 '18 at 14:23
  • from what I know, tabs are the group of windows and windows display buffers, I was not aware that buffers can move across tabs. If that is is the case then I might have to rethink my approach. as of now, I am using the full command, will try the answers provided too. – ArunMKumar Jul 13 '18 at 4:12
3

This should work too:

augroup termIgnore
    autocmd!
    autocmd TerminalOpen * set nobuflisted
augroup END
  • You actually posted yours 9s before mine! – Rich Jul 10 '18 at 9:14
  • Stack exchange magic ^^ – Charles Gueunet Jul 10 '18 at 9:15
  • Haha! Anyhow, good solution. +1 – Rich Jul 10 '18 at 9:24
2

This should do the job:

function! BnSkipTerm()
  let start_buffer = bufnr('%')
  bn
  while &buftype ==# 'terminal' && bufnr('%') != start_buffer
    bn
  endwhile
endfunction

nnoremap <leader>bn :call BnSkipTerm()<CR>

It just keeps invoking :bn until it's not in a terminal window, by checking the 'buftype' setting.

  • 2
    What happens if a terminal is the last buffer? Does this abort if the bn fails, or might it get stuck in the loop? – D. Ben Knoble Jul 10 '18 at 13:03
  • 1
    ahem. Fixed. :) – Rich Jul 10 '18 at 13:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.