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

Vim 如何命名/重命名终端缓冲区?,vim,terminal,buffer,Vim,Terminal,Buffer,有没有办法重命名终端缓冲区?使用:b切换缓冲区,终端缓冲区通常显示为/usr/local/bin/fish和/usr/local/bin/fish(1)这不是很有用。理想情况下,它可以自动重命名自己,但我也可以在终端中开始作业后手动命名它们(即,docker compose up)。免责声明:我不是蒂姆·波普 function! RenameTerminalBufferToCurrentCommand() " unable to access $HISTFILE from vim

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

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
函数!重命名TerminalBufferToCurrentCommand()
“无法从vim访问$HISTFILE,因此请将此变量更改为历史文件
让l:historyFile=“~/.zsh_history”
设l:mostRecentCommand=system(“tail-1”.l:historyFile.“| cut-f2--d\\”)
“i prepend”术语便于缓冲区搜索,但可以随意删除
让l:newFileName=“term”。fnameescape(微调(l:mostRecentCommand))
“keepalt停止:file创建替代文件(alt文件为
“缓冲区切换时很烦人)
“:文件重命名缓冲区
静默!执行“保留文件”。l:newFileName
端功能
tnoremap:调用重命名terminalBufferToCurrentCommand()a

    • 我为它做了一个函数。免责声明:我不是蒂姆·波普

      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
      
      函数!重命名terminalBufferToCurrentCommand()
      “无法从vim访问$HISTFILE,因此请将此变量更改为历史文件
      让l:historyFile=“~/.zsh_history”
      让l:mostRecentCommand=系统(“tail-1.l:historyFile.”cut-f2--d\\;“”
      “i prepend”术语便于缓冲区搜索,但可以随意删除
      让l:newFileName=“term”.fnameescape(trim(l:mostRecentCommand))
      “keepalt停止:file创建替代文件(alt文件为
      “缓冲区切换时很烦人)
      “:文件重命名缓冲区
      安静!执行“保留文件”。l:新文件名
      端功能
      tnoremap:调用重命名terminalBufferToCurrentCommand()a