将选项卡名称和 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 会话一起保存 的相关文章

  • 如何在 Highcharts / Highstock 上显示 x 轴上的十字线选定值和 y 轴上选定的日期?

    我正在研究这个项目 其中包括在交互式图表上显示历史数据 我得出的结论是 Highcharts Highstock 是最好的选择 因为它提供了最多的定制选项 我想要实现的目标是 当我将鼠标悬停在一个点上时 分别在 x 轴和 y 轴上显示所选值
  • Bash 中所有匹配的^单词^替换^?

    为了澄清 我正在寻找一种方法来执行global搜索并替换先前使用的命令 word replacement 似乎只替换了第一场比赛 有没有一些set我无法选择的选项 尝试这个 echo oneone oneone gs one two Rep
  • 在压缩存档内的文本文件上运行“head”,而不解压存档

    问候 我接手了之前的团队并编写了处理 csv 文件的 ETL 作业 我在 ubuntu 上结合使用 shell 脚本和 perl csv 文件很大 它们以压缩档案形式到达 解压后 很多都超过 30Gb 是的 那是 G 旧进程是在 cron
  • 如何成功使用 VIM 作为 Code::Blocks 的外部编辑器?

    我真的很喜欢 Code Blocks 的构建系统和单步调试能力 也就是说 我真的很喜欢使用 gcc gdb 的包装器 而不是从 Makefile 或命令行使用它们 问题是 多年来使用 VIM 使我的大脑受到了严重损伤 或者有些人可能会说被宠
  • jqueryui tabs:当内容垂直滚动时是否可以保持导航选项卡可见?

    我的 jqueryui 选项卡集由几页相当长的内容组成 用户必须垂直滚动才能浏览每个文档 这是一个简化版本 MAIN TEXT END NOTES blah blah blah lots more text the end 如果用户正在阅读
  • Vim 在 Mingw 上表现异常

    我在 MinGW 4 6 2 上的 Vim 表现得很奇怪 例如 在插入模式下按 Backspace 会删除字符 但我必须用箭头键移动光标才能删除的字符消失 而且它也会使我退出插入模式 另一个例子 按 Del 删除字符有时会生成奇怪的字符 例
  • Android 后退按钮无法与 Flutter 选项卡内的导航器配合使用

    我需要在每个选项卡内有一个导航器 因此当我推送新的小部件时 选项卡栏会保留在屏幕上 代码运行得很好 但是 android 后退按钮正在关闭应用程序而不是运行 Navigator pop import package flutter mate
  • Vim 搜索模式,如果出现则删除到行尾

    我正在尝试在文本文件中搜索特定模式 如果出现这种模式 则意味着该行的其余部分不需要 因此可以删除 我尝试过使用以下命令 但到目前为止还没有成功 s pattern d g pattern d 如果有人有任何建议 他们将不胜感激 would
  • 并行运行 shell 脚本

    我有一个 shell 脚本 打乱大型文本文件 600 万行和 6 列 根据第一列对文件进行排序 输出 1000 个文件 所以伪代码看起来像这样 file1 sh bin bash for i in seq 1 1000 do Generat
  • 有选择地设置 iskeyword

    通常我需要搜索大型 xml 模式文件以查找光标下单词的下一个出现位置 但如果它是一个标签或结束标签 则最好不要搜索 在下面的示例中 是光标所在的位置 使用 or 与 iskeyword 不包括 gt or lt 将在之间移动
  • SVN 提交后挂钩在提交后不会运行

    我的服务器上设置了 SVN 存储库 并且遇到提交后问题 我在 iMac 上使用 SmartSVN 作为客户端 我通过 SmartSVN 的 ssh svn 连接 我能够成功连接到 SVN 并对其进行更改 但从 SVN 客户端提交后 我的提交
  • 使用 python 脚本更改 shell 中的工作目录

    我想实现一个用户态命令 它将采用其参数之一 路径 并将目录更改为该目录 程序完成后 我希望 shell 位于该目录中 所以我想实施cd命令 但需要外部程序 可以在 python 脚本中完成还是我必须编写 bash 包装器 Example t
  • 每次重新运行终端时,我都必须输入 export PATH=~/anaconda/bin:"$PATH"

    我已经安装了 Anaconda for Mac 但出现了一些问题 当我输入命令时which conda or which ipython I get conda not found and ipython not find 然后我找到这个命
  • 如何在 *nix 中登录时运行脚本?

    我知道我曾经知道如何做到这一点 但是 如何在 unix 中登录时运行脚本 bash 可以 From 维基百科 Bash http en wikipedia org wiki Bash 28Unix shell 29 当 Bash 启动时 它
  • 在 PHP 应用程序中实现插件的设计模式

    对于如何在 PHP 应用程序中实现插件有共识吗 我已经调查过观察者模式 http devzone zend com 1732 implementing the observer pattern with splobserver and sp
  • [A-Z] 表示 [A-Za-z] 是怎么回事?

    我已经注意到 至少在我使用的一些基于 Unix 的系统上 ls A Z 已经给了我预期的结果ls A Za z 让我无法轻松获得以大写字母开头的该死的文件列表 我刚刚遇到了同样的事情grep 我无法让它停止与小写字母匹配 A Z 直到我最终
  • 从 `git commit` 调用时 Vim 使用非标准配置?

    我注意到每当我编写提交消息时 git 似乎都会使用不同的 vim 设置 我有git svn安装 Macports 我已经检查过 MYVIMRC变量 它被设置为正确的文件 尽管如此 每次我提交消息时 我都会受到每行 80 个字符的限制 区分大
  • 如何在 Vim 中对所选文本执行“base64 –decode”?

    我正在尝试执行base64 decode在可视化模式下选择的一段文本上 但似乎是整行传递给base64命令 而不仅仅是当前选择 我在可视模式下选择文本 然后进入普通模式 这样我的命令行如下所示 lt gt base64 decode 如何仅
  • 如何找到进程启动时使用的原始用户名?

    有一个 perl 脚本需要以 root 身份运行 但我们必须确保运行该脚本的用户最初没有以用户 foo 身份登录 因为它将在脚本运行期间被删除 那么 我如何查明自登录以来可能已多次起诉的用户是否在该链中的任何时间都没有模拟过 foo 我发现
  • Bash 循环遍历具有行和列的变量

    经过几个小时的搜索测试不同的解决方案后 我尚未找到可行的解决方案 Bash 和 Shell 脚本不是我的强项 我有一个变量 其中有行 换行 和列 制表符分隔 我想要做的是循环遍历行并获取 Column X 然后将该项目放入变量中 以便我可以

随机推荐