将选项卡名称和 ConqueShell 与 Vim 会话一起保存

2023-12-07

有没有办法让 vim 保存选项卡名称(通过分配选项卡名称脚本)和/或终端仿真器(通过设置康克外壳脚本)发出后:mksession [fileName]命令?

观察下面(放大),我在左侧有一个工作会话,并且通过vim -S fileName命令,在右边。分配的选项卡标签恢复为绝对路径,ConqueShell 终端被解释为文件。

Failed Session


在学习了一些基本的 VimScript 后,我​​放弃了,转而使用 Python(举一个例子,如果它是一个列表,则无法将全局信息保存到会话中)。这是我找到的用于保存选项卡名称的解决方案(如果我找到的话,将发布 ConqueShell 的解决方案)

将以下内容放入您的.vimrc文件并使用您想要快速保存和加载会话的任何映射

"Tokenize it so it has the following form (without spaces)
"Label1 JJ Label2 JJ Label3 JJ Label4
"Or if you prefer use something other than 'JJ' but DO NOT
"use symbols as they could interfere with the shell command
"line
function RecordTabNames()
   "Start at the first tab with no tab names assigned
   let g:TabNames = ''
   tabfirst

   "Iterate over all the tabs and determine whether g:TabNames
   "needs to be updated
   for i in range(1, tabpagenr('$'))
      "If tabnames.vim created the variable 't:tab_name', append it
      "to g:TabNames, otherwise, append nothing, but the delimiter 
      if exists('t:tab_name')
         let g:TabNames = g:TabNames . t:tab_name  . 'JJ'
      else
         let g:TabNames = g:TabNames . 'JJ'
      endif

      "iterate to next tab
      tabnext
   endfor
endfunction

func! MakeFullSession()
   call RecordTabNames()
   mksession! ~/.vim/sessions/Session.vim
   "Call the Pythin script, passing to it as an argument, all the 
   "tab names. Make sure to put g:TabNames in double quotes, o.w.
   "a tab label with spaces will be passed as two separate arguments
   execute "!mksession.py '" . g:TabNames . "'"
endfunc

func! LoadFullSession()
   source ~/.vim/sessions/Session.vim
endfunc

nnoremap <leader>mks :call MakeFullSession()<CR>
nnoremap <leader>lks :call LoadFullSession()<CR>

现在创建以下文本文件并将其放在您的某个位置PATH多变的 (echo $PATH为了得到它,我的在/home/user/bin/mksession.py)并确保使其可执行(chmod 0700 /home/user/bin/mksession.py)

#!/usr/bin/env python

"""This script attempts to fix the Session.vim file by saving the 
   tab names. The tab names must be passed at the command line, 
   delimitted by a unique string (in this case 'JJ'). Also, although
   spaces are handled, symbols such as '!' can lead to problems.
   Steer clear of symbols and file names with 'JJ' in them (Sorry JJ
   Abrams, that's what you get for making the worst TV show in history,
   you jerk)
"""
import sys
import copy

if __name__ == "__main__":
   labels = sys.argv[1].split('JJ')
   labels = labels[:len(labels)-1]

   """read the session file to add commands after tabedit
   " "(replace 'USER' with your username)
   "
   f = open('/home/USER/.vim/sessions/Session.vim', 'r')
   text = f.read()
   f.close()

   """If the text file does not contain the word "tabedit" that means there
   " "are no tabs. Therefore, do not continue
   """
   if text.find('tabedit') >=0:
      text = text.split('\n')

      """Must start at index 1 as the first "tab" is technically not a tab
      " "until the second tab is added
      """
      labelIndex = 1
      newText = ''
      for i, line in enumerate(text):
         newText +=line + '\n'
         """Remember that vim is not very smart with tabs. It does not understand
         " "the concept of a single tab. Therefore, the first "tab" is opened 
         " "as a buffer. In other words, first look for the keyword 'edit', then
         " "subsequently look for 'tabedit'. However, when being sourced, the 
         " "first tab opened is still a buffer, therefore, at the end we will
         " "have to return and take care of the first "tab"
         """
         if line.startswith('tabedit'):
            """If the labelIndex is empty that means it was never set,
            " "therefore, do nothing
            """
            if labels[labelIndex] != '':
               newText += 'TName "%s"\n'%(labels[labelIndex])
            labelIndex += 1

      """Now that the tabbed windowing environment has been established,
      " "we can return to the first "tab" and set its name. This serves 
      " "the double purpose of selecting the first tab (if it has not 
      " "already been selected)
      """
      newText += "tabfirst\n"
      newText += 'TName "%s"\n'%(labels[0])

      #(replace 'USER' with your username)
      f = open('/home/USER/.vim/sessions/Session.vim', 'w')
      f.write(newText)
      f.close()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

将选项卡名称和 ConqueShell 与 Vim 会话一起保存 的相关文章

  • 如何隐藏显示终端命令输出

    当我运行这个命令时 sudo htpasswd b home reynolds htpasswd admin admin 我正在得到输出Updating password for user admin在终端中 但我不想显示该输出 所以我在谷
  • 如何在Vim中正确显示UTF-8字符

    我想要 需要编辑包含 UTF 8 字符的文件 并且我想使用 Vim 在我被指责问以前问过的问题之前 我已经阅读了有关编码 文件编码 s 术语编码等的 Vim 文档 用 google 搜索了该主题 并阅读这个问题 https stackove
  • Vim 状态栏预测/完成?

    昨天我玩了一些 vim 脚本 并设法对我目前正在输入的内容进行一些超出状态栏的预测 通过循环 请参阅屏幕截图 灰色 黄色条 问题是 我不记得我是如何得到它或找到我用于 vim 魔法的代码片段 我记得它非常简单 它要么是文档中的示例 要么是我
  • 为什么“script”命令会生成 ^[ 和 ^M 字符以及如何使用 vim 搜索和替换删除它们?

    在linux上 使用bash shell 当我使用script命令时 生成的文件称为typescript 当我用 vim 打开该文件时 每一行都包含 M字符 并且有几行 由于我的彩色命令提示符 包含一个字符 我想用任何东西替换这些字符 从而
  • tomcat-maven-plugin 使用 Tomcat 7 - tomcat:deploy 有效,tomcat:undeploy 无效

    我有一个 tomcat deploy 的工作配置 但是当我取消部署 WAR 时 出现以下错误 这让我很困惑 INFO Scanning for projects WARNING WARNING Some problems were enco
  • 编写一个 shell 脚本,find-greps 并在 1 行中输出文件名和内容

    要查看所有包含 abc 的 php 文件 我可以使用这个简单的脚本 find name php exec grep l abc 我可以省略 l 并且提取部分内容而不是文件名作为结果 find name php exec grep abc 我
  • 如何迭代 Bash 中变量定义的数字范围?

    当范围由变量给出时 如何在 Bash 中迭代数字范围 我知道我可以做到这一点 在 Bash 中称为 序列表达式 文档 http www gnu org software bash manual bashref html Brace Expa
  • 如何从正则表达式中获取所有匹配项?

    我想获得所有出现的情况 0 9A Z 以供稍后处理 我有 if cat file 0 9A Z then echo BASH REMATCH fi 这给了我第一个匹配项 但是我如何处理文件中的所有匹配项 谢谢 如果您只想获取正则表达式的匹配
  • 有没有办法改变vim的默认模式

    有谁知道如何更改vim的默认模式 它的默认模式是命令模式 但是我可以将其更改为插入模式吗 只需将以下行添加到您的 vimrc 中 start Vim s default mode will be changed to Insert mode
  • 在 Android 中隐藏 TabHost 中的选项卡

    if tabHost getTabWidget getChildAt 0 setVisibility View GONE to hide the first tab in the TabHost 这段代码有什么问题吗 当我在 onCreat
  • Vim 无法在 OS X 上使用 python 进行编译

    我一直在尝试编译vim 7 3 with 蟒蛇2 7支持苹果系统 X 10 6 Vim 本身编译得很好 但嵌入的 python 编译得不太好 我已采取的步骤 hg clone https vim googlecode com hg vim
  • 有没有办法在 (g)Vim 中突出显示多个搜索?

    我想在 Vim gVim 中搜索多个字符串 并用不同的颜色突出显示它们 有没有办法用开箱即用的 Vim 或插件来做到这一点 在 vim 编辑器中突出显示多个单词有两种简单的方法 进入搜索模式 即输入 然后输入 v后面是您要搜索的单词 以 分
  • Bash:替换管道标准输入中的子字符串

    我尝试用新的子字符串替换标准输入中的某个子字符串 在读取几个文件后 我必须从管道获取标准输入cat 然后我想将更改后的字符串向前推到管道中 这是我尝试做的 cat file1 file2 echo cat path to file path
  • 在 vim 中设置文本宽度而不覆盖特定于文件类型的内容

    我希望 vim 中默认的文本宽度为 80 但如果特定文件类型有自己的文本宽度 特别是 gitcommit 其中 tw 72 我希望 vim 尊重该宽度 在我的 vimrc 中 我有以下行 set tw 80 我也尝试过 setlocal t
  • 如何创建浏览器插件?

    我必须创建一个插件 当用户将鼠标悬停在某些术语上时 该插件必须显示信息 谁能告诉我如何做的方向 我对创建插件没有太多想法 我知道我想要做的事情可以通过java脚本来完成 但是java脚本文件可以作为浏览器插件安装吗 任何对此的想法将不胜感激
  • gVim 和 gVim easy 有什么区别?

    这个问题是不言自明的 但经过一个小时的搜索 我还没有找到任何资源可以解释其中的差异 在对两者进行了一些研究后 发现 gVim 和 gVim easy 是相同的 gVim Easy 启动并锁定在插入模式 您输入的每个字符都像简单的记事本一样打
  • 如何在 .zip 文件中使用 grep

    有 3 个文件 a csv b csv c csv 压缩为 abh zip 现在可以在 abh zip 上执行 grep 命令 是否有任何通配符 仅对里面的 c csv 文件运行 grep压缩 如果你有zipgrep 据我所知 它是随zip
  • 如何在变量中存储标准错误

    假设我有一个如下所示的脚本 无用 sh echo This Is Error 1 gt 2 echo This Is Output 我还有另一个 shell 脚本 也无用 sh useless sh sed s Output Useless
  • 为什么 ls -l 中的“总计”加起来不等于列出的总文件大小? [关闭]

    Closed 这个问题不符合堆栈溢出指南 help closed questions 目前不接受答案 为什么是total在输出中ls l打印为64并不是26078列出的所有文件的总数是多少 ls l test ls total 64 rw
  • Vim 重复点(“.”)命令缓冲区?

    我真的很喜欢 YankRing 的行为 它让我可以访问我最近完成的几件事y固定或d已删除或c不假思索地被吊死了 然而 这样的补充功能对于 重复命令 最常见的是当我键入我真正想重复的内容时 然后按x清理一些东西 通常 可以通过视觉模式拉动我刚

随机推荐