Is there a way to rename the terminal buffer? using :b to switch buffers, terminal buffers are often shown as !/usr/local/bin/fish
and !/usr/local/bin/fish (1)
which isn't very useful. Ideally It could auto rename itself, but I'm also okay with manually naming them (i.e. docker-compose up
) after I start the job with in a terminal.
Asked
Active
Viewed 347 times
2

Oguz Bilgic
- 3,392
- 5
- 36
- 59
1 Answers
1
Here's a function I made for it. Disclaimer: I'm no Tim Pope
function! RenameTerminalBufferToCurrentCommand()
" unable to access $HISTFILE from vim, so change this variable to your history file
let l:historyFile = "~/.zsh_history"
let l:mostRecentCommand = system("tail -1 " . l:historyFile . " | cut -f2- -d\\;")
" i prepend "term" for easy buffer searching, but feel free to delete
let l:newFileName = "term " . fnameescape(trim(l:mostRecentCommand))
" the keepalt stops :file from creating an alternative file (alt files are
" annoying when buffer switching)
" :file renames the buffer
silent! execute "keepalt file " . l:newFileName
endfunction
tnoremap <Enter> <Enter><C-\><C-n>:call RenameTerminalBufferToCurrentCommand()<Enter>a

David M
- 195
- 3
- 13