Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am relatively new to linux. I am connecting to a remote linux machine sometimes via telnet and sometimes via NX client for windows. When I connect via telent I would like the default editor to be vim, and when I connect via NX I would like the default editor to be gvim. Is there a way to automatically detect which connection I am using when the alias file is sourced? Right now I have the following in my alias file:

alias usevim 'setenv CSCOPE_EDITOR vim; setenv EDITOR vim'
alias usegvim 'setenv CSCOPE_EDITOR gvim; setenv EDITOR gvim'
echo 'using vim'
usevim

This sets the default editor to vim. When I connect via NX, the first thing I will do is type 'usegvim'. I would like to not have to do this every time! Is there a way to detect whether a display is present or not?

Thanks!

UPDATE: if($?DISPLAY) doesn't work because my .cshrci file has a line with "setenv DISPLAY ..."

UPDATE: I am now using cygwin to ssh into the remote box and using Cygwin XWin Server to display my gui apps. Now I don't need to worry about which editor to use because gvim is always available. I will probably ditch NX client because everything I need can now be launched directly from the command line and gui apps work just like native windows apps.

share|improve this question

migrated from stackoverflow.com Oct 20 '12 at 1:12

This question came from our site for professional and enthusiast programmers.

2  
Why on earth would you use telnet in this day and age? The only sane choice is SSH. In fact, enabling a telnet server on these days is (quite rightly) a fair amount of effort. –  Marko Oct 19 '12 at 22:03
    
as an addition to the comment before: telnet is sending everything unencrypted in plain text, wheras ssh uses very secure encryption by default. everyone on the way from one machine to the other could read everything you do! –  twall Oct 20 '12 at 2:52
    
Good point. I am now using ssh. –  derekswanson08 Nov 7 '12 at 20:52
add comment

2 Answers 2

The DISPLAY variable is set when an X11 (graphical) display is in use. When using telnet, DISPLAY will not be defined.

It looks like you're using a csh derivative which I don't really know, but I think you could add something like this to your .tcshrc file:

if ($DISPLAY) then
    setenv CSCOPE_EDITOR gvim
    setenv EDITOR gvim
else
    setenv CSCOPE_EDITOR vim
    setenv EDITOR vim
endif
share|improve this answer
    
Revised my answer to fix the inverted logic. New code will use gvim when DISPLAY is set. –  Kurt Stutsman Oct 19 '12 at 22:17
add comment

Just always use "gvim" or "vim -g". It will complain if the X display isn't available, but it will still start the console version.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.