Vim Tips Wiki
(update header + tweak)
Line 90: Line 90:
   
 
----
 
----
  +
  +
No problem with your modifications. Two comments: (a) The tip states it good for version 6.0. This is probably true, but I can't vouch for this. I've never used vim before 7.0. (b) On another, unrelated, note, there is a weird Home and End keys issue with Screen+vim which I want to fix. I'll update this page if I succeed (or contact the mailing list if I don't). [[User:Tlgrok|tlgrok]] 00:31, 15 January 2009 (UTC)

Revision as of 00:31, 15 January 2009

Tip 965 Printable Monobook Previous Next

created 2005 · complexity basic · author tlgrok · version 6.0


GNU Screen is a terminal multiplexer. This tip deals with Screen and Vim integration.

Getting the Esc key to work

If you use Vim under Screen, you might find that the Esc key doesn't work. To fix this, add the following to your .screenrc:

maptimeout 5

This may be necessary so Screen will wait no more than 5 milliseconds between characters when detecting an input sequence.

Getting other things to work properly

In addition to the Esc key, you might find that all sorts of other things don't work the way they should. This is because, by default, Screen sets the $TERM environmental variable to "screen", which Vim does not recognize. There are two ways to fix this:

(I'm going to assume you're using an xterm-compatible terminal, such as gnome-terminal, but you should obviously replace "xterm" with the terminal you use if this is not the case.)

Modify your .screenrc

Add the following line to your .screenrc:

term xterm

Note: This changes the $TERM variable, so it affects more than Vim.

Modify your .vimrc

The very simplest thing to do is to add the following lines to your .vimrc:

if $TERM == 'screen'
  set term=xterm
endif

If you want different behaviors whenever you're running Screen (see below for ideas), use the following alternative:

if $TERM == 'screen'
  set term=xterm
  let g:GNU_Screen_used = 1
else
  let g:GNU_Screen_used = 0
endif
" Screen-ify an external command.
function InScreen(command)
  return g:GNU_Screen_used ? 'screen '.a:command : a:command
endfunction

Screen-aware commands

If you decided you'd like there to be a g:GNU_Screen_used variable, you may use it in all sorts of ways.

Say, for instance, you've defined a command to play a music file under your cursor:

let s:music_player = 'mplayer'
function PlayTune()
  exe '!'.s:music_player.' "'.expand('<cfile>').'"'
endfunction

If you're using Screen, you may well want mplayer to open in a different terminal window (but open normally if Screen is not in use). To achieve this, use the following alternative:

let s:music_player = InScreen('mplayer')
function PlayTune()
  exe '!'.s:music_player.' "'.expand('<cfile>').'"'
endfunction

Comments

Pursuant to taking over this page, I hereby dully suggest that it be renamed "GNU Screen integration" or "Working with GNU Screen" or "Fluffy pink bunnies", although I would be very surprised if the latter were accepted. Nobody likes bunnies anymore. tlgrok 10:48, 14 January 2009 (UTC)


You're right ... I've noticed some Vim people lack a sense of humour! I'll rename it to "GNU Screen integration" in the next day or two.

I removed the {{review}} line in the hope that you will check that everything on the page actually works.

Please delete your comments and my comments when you think they have been dealt with (for example, if you delete the line above, I will assume you're happy about the "review").

I have taken a bit of a liberty by changing the InScreen code to clarify what I meant on your user subpage. Please check it out. If you want, put it back to however you like. It occurs to me that g:GNU_Screen_used could probably be s:GNU_Screen_used but there is no need to optimise everything.

I also added a quick explanation for the maptimeout (fix if necessary). Thanks for improving this tip. I hope to get you to clean up a couple more Linux and/or terminal tips! --JohnBeckett 23:59, 14 January 2009 (UTC)


No problem with your modifications. Two comments: (a) The tip states it good for version 6.0. This is probably true, but I can't vouch for this. I've never used vim before 7.0. (b) On another, unrelated, note, there is a weird Home and End keys issue with Screen+vim which I want to fix. I'll update this page if I succeed (or contact the mailing list if I don't). tlgrok 00:31, 15 January 2009 (UTC)