首页 > 解决方案 > 如何命名/重命名终端缓冲区?

问题描述

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

标签: vimterminalbuffer

解决方案


这是我为它制作的功能。免责声明:我不是蒂姆·波普

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

推荐阅读