如何命名/重命名终端缓冲区



有办法重命名终端缓冲区吗?使用:b切换缓冲区,终端缓冲区通常显示为!/usr/local/bin/fish!/usr/local/bin/fish (1),这不是很有用。理想情况下,它可以自动重命名自己,但我也可以在终端中开始工作后手动命名它们(即docker-compose up(。

这是我为它制作的一个函数。免责声明:我不是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
  • https://unix.stackexchange.com/questions/3497/how-to-change-the-name-of-a-vim-buffer
  • https://www.reddit.com/r/unix/comments/9u7le4/running_the_zsh_history_command_to_load_result/e928r7y/
  • https://www.reddit.com/r/vim/comments/7bcrkf/what_to_do_with_unlisted_buffers/

最新更新