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

时间:2012-02-29 09:22:59

标签: shell vim plugins tabs

有没有办法让vim在发出:mksession [fileName]后保存标签名称(通过Tab Name script分配)和/或终端模拟器(通过Conque Shell script设置)命令?

观察下面(放大),左边有一个工作会话,右边是通过vim -S fileName命令加载的同一个会话。指定的选项卡标签将恢复为绝对路径,ConqueShell终端将被解释为文件。

Failed Session

1 个答案:

答案 0 :(得分:3)

在学习了一些基本的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)并确保使其可执行({{ 1}})

chmod 0700 /home/user/bin/mksession.py