保存选项卡名称和ConqueShells以及Vim会话

保存选项卡名称和ConqueShells以及Vim会话

本文介绍了保存选项卡名称和ConqueShells以及Vim会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

有什么方法可以使vim保存选项卡名称(通过标签名称脚本)和/或终端模拟器(通过发出:mksession [fileName]命令后是否征服了Shell脚本)?

Is there any way to get vim to save the tab names (assigned via the Tab Name script) and/or a terminal emulator (set up via the Conque Shell script) upon issuing the :mksession [fileName] command?

在下面观察(放大),我在左侧有一个工作会话,而在右侧通过vim -S fileName命令加载了相同的会话.分配的选项卡标签将还原为绝对路径,ConqueShell终端将解释为文件.

Observe below (zoom in), I have a working session on the left, and the same session loaded via the vim -S fileName command, on the right. The assigned tab labels revert to absolute paths, ConqueShell terminal is interpreted as a file.

推荐答案

学习了一些基本的VimScript之后,我只是放弃了而改用Python(举一个例子,如果全局信息是一个会话,则不能将其保存到会话中.列表).这是我找到的用于保存标签名的解决方案(如果找到一个解决方案,它将为ConqueShell发布解决方案)

After learning some basic VimScript I just gave up and used Python instead (to cite one example, you can't save global information to a session if it is a list). Here is a solution I found for saving tab names (will post a solution for ConqueShell if I find one)

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

Put the following in your .vimrc file and use whatever mapping you want to quickly save and load your sessions

"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)

Now create the following text file and put it somewhere in your PATH variable (echo $PATH to get it, mine is at /home/user/bin/mksession.py) and make sure to make it executable (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()

这篇关于保存选项卡名称和ConqueShells以及Vim会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 20:09