Need help with key bindings in .cshrc

I want to enable some common key bindings for t/csh on my dedicated server (freebsd 11 rel) but noticed some really weird behavior!
Let me explain the situation. My .cshrc follows
Code:
umask 22
set path = (/sbin /bin /usr/sbin /usr/bin /usr/local/sbin /usr/local/bin $HOME/bin)

setenv  EDITOR vi
setenv  PAGER less
setenv  LESS -iM
setenv  BLOCKSIZE K
setenv  NCURSES_NO_UTF8_ACS 1
setenv  CLICOLOR 1

if ($?prompt) then
        # An interactive shell -- set some stuff up
        set prompt = "%N:%~ %# "
        set promptchars = "%#"

        set filec
        set history = 5000
        set savehist = (5000 merge)
        set autolist = ambiguous
        # Use history to aid expansion
        set autoexpand
        set autorehash
        set mail = (/var/mail/$USER)

        if ( $?tcsh ) then
            bindkey "^W" backward-delete-word
            bindkey -k up history-search-backward
            bindkey -k down history-search-forward
            bindkey "\e[1~" beginning-of-line
            bindkey "\e[4~" end-of-line
            bindkey "\e[3~" delete-char
            [color=red]bindkey "^[[OC" forward-word
            bindkey "^[[OD" backward-word[/color]
        endif
endif

Those two lines in red, work fine when entered manually from csh command line or running source .cshrc but not working automatically when log in shell.
That's really weird, because .cshrc is parsed normally, all other commands executed including the rest bindings, everything works except those two lines!

Please give some advice because I'm really confused! If those bindings were not supported by terminal why they work fine when entering them from command line or manually sourcing .cshrc?

PS: terminal is xterm accessed via putty. Also tried others with exactly the same results.

Thank you folks!
 
Don't' know the exact answer, honestly I don't have a complete picture of your setuo, however you are using a different notation for the ESCAPE char in those two red lines ... ^[ while the rest are using "\e", so I would ttry to change them as follow:
Code:
           bindkey "\e[OC" forward-word
            bindkey "\e[OD" backward-word
They should be equivalent (assuming you used CTRL-V followed by ESC to obtain ^[ which is a single character), but may be they get expanded differently at some point.
 
Thanks for answering ASX, however still not worked when parsed from .cshrc and that is the actual problem. These two bindkey commands work fine when entered from command line but not when autoexecuted from ..cshrc when log in.

Not mentioned my setup details, because it's a default 11r installation with all defaults including the dot files.

BTW, all other key bindings in cshrc work fine, only those two seem to be ignored!
 
Notice how the other, working, three bindings use '\e' instead of '^['. And you appear to have a '[' too many. Just look at the default mappings:
Code:
"^[OC"         -> forward-char
"^[OD"         -> backward-char
 
CTRL-LEFT cursor control sequence is "^[[OD" (via od or ctrl-V) and can be written as \e[OD.
It works fine when binding is manually entered from command line, but not when parsed from .cshrc and that is the actual issue.
Other shells, including bash, zsh, mksh etc have no problem with these btw

PS: I had to bind backward-word to ALT-Left "^[^[[D" or "\e^[[D". This works, but ctrl-left nope!
 
I never use these, but they are defined in my setup and worked just now when I tried them:
Code:
bindkey "\e[1;5D" vi-word-back
bindkey "\e[1;5C" vi-word-fwd
 
What is your console "type" in /etc/ttys?

Never mind, it doesn't work in a true console here either.
 
I have the same Issue.
As a temporary decision, I had to copy this two Lines from ~/.cshrc to ~/.login, and it works, but I suspect that this is not correct…
~.login:
Code:
bindkey   "^[OD"   backward-word       # Ctrl+Left Arrow.
bindkey   "^[OC"   forward-word       # Ctrl+Right Arrow.
 
Last edited by a moderator:
I had to copy this two Lines from ~/.cshrc to ~/.login,
Check your shell, you're probably using /bin/sh (or /usr/local/bin/bash) instead of /bin/csh or /bin/tcsh. The ~/.cshrc file is only read by the CSH shells.

Edit: Had to look it up. There are so many different scripts, for different shells, interactive vs. non-interactive, it's hard to keep track. But the remarks in ~/.login state:
Code:
# .login - csh login script, read by login shell, after `.cshrc' at login.

If it didn't work for you in ~/.cshrc you probably made a mistake there, perhaps you added it at the wrong place? Or introduced an error that prevented further execution. You can easily test it without having to logout and login again, simply by running: source ~/.cshrc. It should not produce errors.
 
what if you cd ~ && mv .cshrc .cshrc.old && cat .cshrc.old .cshrc?

What if you echo the commands in .cshrc?

just out of curiosity, does it do the same thing if you set it in /etc?
 
Back
Top