2

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?

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

1 Answer 1

6

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?

1
  • 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, 2019 at 9:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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