Wednesday, August 8, 2012

Re: vim: session of "sessions"

On Fri, 13 Jul 2012, ping wrote:

>> here is another approach to this issue.
>>
>> 1) multiple virtual terminal sessions: i switched to tmux from
>> screen/byobu last year. window navigation, for me, is a critical
>> requirement and it is quite straightforward in tmux. the windows i create
>> in tmux have unique names; therefore each window is directly addressable. i
>> routinely run 20+ windows in tmux. new window set creations and
>> destructions are done with functions, so creating a new batch of some large
>> number of directly addressable windows is easy. command line display of all
>> open windows, from any window, is also a capability i require.
>>
>> 2) mulptiple tabs in vim: i have run vim with 259 open tabs simultaneously
>> with no problems and snappy response. for navigation among the tab pages
>> currently displayed, i employ a homegrown function that creates a list of
>> each tab page currently open, and a key mapping to switch to whatever tab
>> page (and embedded window) that i need. this makes working on large
>> projects quite straightforward. moreover, when i need to cross reference
>> any regular expression across all open tab pages, i have other homegrown
>> functions that control grep sessions across all open tabs and collate the
>> results in a final report, displayed in a new tab page. navigation to the
>> relevant code portions on any of the open tabs is handled by a key map to
>> another function.
>>
>> 3) large project file sets: i maintain vim functions that serve as main
>> project centers for large projects. there are key files for each project
>> that routinely need to be accessed simultaneously, so these functions keep
>> a list of those critical files for each project and open them each in
>> separate tab pages when the project is invoked.
>>
>> contact me for relevant code.
>
> can you share the codes/steps for step 1-3?
> thanks in advance.


I apologize for the delay in responding with this code.

This post is cross-disciplinary in nature; the original user query
centered on a session multiplexer being used to control many vim sessions.
The first part of this reply addresses the multiplexer; the latter part
addresses vim functionality.

All code samples are extracted from current production code. any
constructive critique or bug fixes are welcome. If I have inadvertently
skipped or failed to include a required function or map, please let me
know.

All of the code presented, here, requires zsh (4.3.5+); the vim version
should be 7.3+.

To answer the request for useful code, I have provided an attachement that
contains an archive with the following files:

./vim_posting_aug12/bin/tmux.init
./vim_posting_aug12/.tmux.conf
./vim_posting_aug12/.zsh/functions/setfac
./vim_posting_aug12/.vim/plugin/ckhb.vim
./vim_posting_aug12/.vim/autoload/ckhb_load_once.vim

The archive is in bzip2 tar format. To unload the archive, do something
akin to the following in an appropriate directory.

tar xjvf archive.tb2

To provide the functionality described in paragraph 1), the relevant files
are:

./vim_posting_aug12/bin/tmux.init
./vim_posting_aug12/.tmux.conf
./vim_posting_aug12/.zsh/functions/setfac

tmux.init provides the major functionality for tmux session initialization
and augmentation. The .tmux.conf file provides a rudimentary global
configuration for the tmux session. Several useful aliases and functions
are contained in the setfac file. setfac is normally invoked in zsh
session initialization by an appropriate command in .zshrc.

In normal usage, a tmux session would be initiated by something like:

tmux.init -p

where the p option specifies a set of windows to create. Subsequently,
the session can be augmented by something like:

tmux.init -r

which will append a set of windows to the current session.

To be functional, the tmux.init file will need to be customised with
user-provided site-specific host and user names.

Session information can be obtained by aliases and functions contained in
the setfac file. These aliases and functions in the current
implementation must be invoked from any session on the host where the
session was created. Among other things, they provide the functionality
to list the current windows or sessions, kill specified windows, or jump
to a specified window.

tmux.init creates named windows. This facilitates window navigation:
pressing the hot-key followed by a single quote prompts for the title of
the window to go to. Window titles are displayed in the default status
line.

To provide the functionality described in paragraphs 2 and 3), the
relevant files are:

./vim_posting_aug12/.vim/plugin/ckhb.vim
./vim_posting_aug12/.vim/autoload/ckhb_load_once.vim

To be functional, they need to be copied into their appropriate
subdirectories:

./vim_posting_aug12/.vim/plugin/ckhb.vim => ~/.vim/plugin
./vim_posting_aug12/.vim/autoload/ckhb_load_once.vim => ~/.vim/autoload

To generate a list of the currently available tab pages in the current vim
session, I use the map code <leader>tl. (This mapping is in the file
ckhb.vim.) The default value for <leader> is a backslash. This will
create a new tab page at the end of all current tab pages, with a list of
all currently visible buffers. To navigate to a particular tab page,
place the cursor on the line of the desired file and hit <leader>gt.

To find the occurrence of some term across all currently open files, place
the cursor on the term (space delimited on each end), and hit <leader>gz.
You are then prompted with a menu to choose what files to search. Option
6 in the menu, for example, is all currently open files in the vim
session. This function menu is easily extendable to include other sets of
searchable files. A new tab page is created showing the success or
failure of the search. For any successful results, it is a
straightforward matter of placing the cursor on the file name containing
the reference and hitting the key sequence <ctrl-w>gf (this is the
standard vim g-command for go to file).

I have provided two abbreviated examples of vim functions that are used
for openning large project sets (also in the file ckhb.vim). Each of
these examples is a static list of files selected for the given projects.

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: