On 2015-08-12 06:35, Dhyanesh wrote:
Hi
I typically have a single screen session to which I connect using
screen -x. Whenever I want to edit a file with vim, I'd like to:
1. Open a new xterm.
2. Connect to the screen session.
3. Create a new screen window and start vim in it.
Ideally I'd like the following command to work (from within a screen
session):
xterm -e screen vim foo.cc
However, it partially works, the new xterm is created and has the STY
variable. Thus screen opens a new window in that same session and
starts vim. However, the new xterm window doesn't connect to that
session. Any thoughts on why this happens? I'm using screen version
4.02.
When I try that command with screen 4.02.01, I don't get a new xterm,
but I do get the new screen window running vim, which isn't selected, I
get my prompt back in the window I typed the command in.
In any case, here's what I do, I tend to work in one xterm with one
screen session.
All shell my shell bits assume you're running bash, might work in ksh or
zsh, you'll have to make adjustments if you're in tcsh.
In my .vimrc:
" If we're in screen, rename the current window to the filename we're
editing
if &term =~ '^screen'
set title
" VimTip #1126
set t_ts=
set t_fs=
let &titleold = fnamemodify(&shell, ":t")
endif
Then as a bash function:
svim () {
screen -X msgwait 0
screen vim $*
screen -X msgwait 4
}
You can put that in your .bashrc, .bash_profile, in a separate file that
gets sourced by one of those, etc.
Now, when I want to edit a file:
svim foo.cc
This will open a new screen window running vim on the named file. Vim
will see that it's running in a screen session and rename that window to
be the name of the file, which makes it easy to see in your window list
(with ^A-"). When you're done and exit vim, that window auto-closes and
returns you to the previously used screen window, which, if you've not
done any window switching, will be the one you originally ran the
command in.
Now, for extra fun, you can now do things like:
for i in *.cc, do svim $i ; done
This will open a new screen window running vim for each file matching
the glob (*.cc), all named for the file that is being edited.
--
Michael Parson
Austin, TX
KF5LGQ
_______________________________________________
screen-users mailing list
screen-users@gnu.org
https://lists.gnu.org/mailman/listinfo/screen-users