1

I'm configuring my scripts to work with terminal in VIM and have a question regarding :h special-buffers. Among mentioned kinds there were the following:

unlisted    The buffer is not in the buffer list.  It is not used for
            normal editing, but to show a help file, remember a file name
            or marks.  The ":bdelete" command will also set this option,
            thus it doesn't completely delete the buffer.  Settings: >
            :setlocal nobuflisted

terminal    A terminal window buffer, see |terminal|. The contents cannot
            be read or changed until the job ends.

Currently I create a terminal buffer with the function

function! CreateTerminalInstance()
    execute "terminal ++hidden" 
    return bufnr("$")
endfunction

then stores the bufnr of the terminal and use it throughout the session.

The problem is when switching between buffers containing code to be displayed in some window with :bnext it sometimes displays the terminal in the window. This is because the terminal appears in the buffer list:

enter image description here

So I considered making this buffer with :setlocal nobuflisted, but it looks hacky since now the terminal buffer has two kinds: terminal and unlisted as I show above.

What is the preferred way to achieve switching between buffers corresponding to regular opened files?

  • 3
    I think :set nobulisted is the way to go here. BTW: I don't see, why this would look hacky. – Christian Brabandt Dec 2 at 7:03
4

First, your function can be simplified into

let bufnr = term_start(&shell, {"hidden": 1})

Second, it's not a problem to have buftype ==# 'terminal' and set nobuflisted together, as these are two different options. So

if bufnr
    call setbufvar(bufnr, "buflisted", 0)
endif

is very much okay. However, the real question is: why you create a terminal at all if you are never going to show it? Maybe, you want job_start() instead?

  • I do have intention to show it. But I defined 2 functions: one for toggling and another one to make a terminal active (and therefore show if is not shown currently) each which uses the CreateTerminalInstance function. – St.Antario Dec 3 at 9:48

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.