statox's comment works, but for what you want, it's not the best solution. You can't simply check for
&buftype == 'terminal. A terminal buffer could be created by a plugin such as fzf and you could end up in a weird state if you blindly try to send text into it.
Probably the best option is to use the neoterm plugin:
nnoremap <f5> :T make<cr>
That will run
make in the terminal buffer that's managed by
Although I think
neoterm will be best for your situation, I'm adding this for the sake of completeness.
For you to be sure that a terminal is yours to do with as you please, you have a couple methods:
autocmd TermOpen *:$SHELL,*:\$SHELL let b:my_term = 1
This will set
b:my_term in a buffer that's created by
:term without arguments. This isn't always reliable, since a plugin could run
command! -nargs=? MyTerm execute 'term <args>' | let b:my_term = 1
This gives you a command that you can be 100% certain is yours.
To find these buffers:
let terms = filter(range(1, bufnr('$')),
\ 'bufexists(v:val) && getbufvar(v:val, "my_term", 0)')
This gives you a list of buffers that have the
b:my_term variable set. Also note that there are other terminal-specific variables that available.
Terminal buffers maintain some information about the terminal in buffer-local
- *b:term_title* The settable title of the terminal, typically displayed in
the window title or tab title of a graphical terminal emulator. Programs
running in the terminal can set this title via an escape sequence.
- *b:terminal_job_id* The nvim job ID of the job running in the terminal. See
|job-control| for more information.
- *b:terminal_job_pid* The PID of the top-level process running in the