Saturday, October 2, 2010

How to execute commands at vim exiting?

Hi,

Does anybody know if there is some way to execute commands at vim exiting?


I have the following in my ~/.vimrc to make F-12 key switch between
"auto-created" screen session associated to current buffer file name
(future file directory, but I must deal with path slashes before):


-8<------------------------------------------------------
" F12 -> Per file Screen session: {{{
" ==============================
" cd $(dirname %:p) --> Change to current file's directory.
" screen
" -U -> Run in UTF-8 mode.
" -d -> Deatach if previously attached.
" -dRR vim_$(basename %:p)
" -> Use current buffer file name as sessionname; then
reattach it and, if necessary, detach or create it first. Use the
first session if more than one session with same name are available.
" -e^qa -> Change default screen's escape key to CTRL-Q to
avoid conflict if vim itself is running in other screen session.
" -p %:p -> Use current buffer file full path as preselected
(if available) window.
" * TODO: Create this window by default when not exists.
noremap <f12> :silent<space>!bash<space>-c<space>'cd<space>$(dirname<space>%:p);screen<space>-UdRR<space>vim_$(basename<space>%:p)<space>-e^qa<space>-p<space>"%:p"<space>-c<space>~/.vim/screenrc'<enter>:redraw!<enter>

" Prepare vim's screen configuration:
" ----------------------------------
" Create ~/.vim directory if not already exists.
silent !mkdir -p ~/.vim
" Copy user's ~/.screenrc if exists.
silent !cp ~/.screenrc ~/.vim/screenrc 2>/dev/null
" Bind F12 to 'detach' command in screen.
silent !echo 'bindkey -k F2 detach' >> ~/.vim/screenrc
" }}}
-8<------------------------------------------------------


This works much fine, but it's tremendously easy to forgive many
screen sessions open when exiting.

The main idea is to capture vim pid (any suggestion about it also will
be gratefull) an use it in the building of the screen's label.

This way I could capture all screens generated in the same vim process
and kill it on exiting.


I thought that I can redirect vim command to some script to invoke vim
and do that after it's execution, but I think there must be better
solution...


Regards.

--
Joan Miquel Torres__________________________________
Linux Registered User #164872
http://www.mallorcaweb.net/joanmiquel
BULMA: http://bulma.net http://breu.bulma.net/?l2301

--
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:

Post a Comment