48

rock.com

Thursday, September 21, 2006

Delete and End key problem - Linux

After a thrilling exploration, the crack has been finally found out!

If you are a typical non Emacs user on linux and experiencing difficulties over working on TCShell(CShell with command line editing) on linux, for eg., not finding your end and del key to work as expected.... Here is the solution for you!

If you are using the latest Linux distros, from redhat 9 atleast, you are correct in assuming that delete key(which wasnot part of orginial unix) and other keys like end,etc are mapped correctly. I mean, it is bound properly in the key map and delete is mapped to "delete-right", back space is mapped to "delete-left", end is mapped to "end-of-line". So no issues with meddling up with the key bindings and overriding the key maps for XTerm,etc. (It took a while for me to figure this out.)

So what is the problem?
Here its the shell that is the culprit, but not the XTerm as you would assume.

THE FIX:

The problem here is in understanding that CShell has the Emacs key binding as default and all the key bindings are in compliant with that. And you should acknowledge that, Ctrl + d will do the delete and Ctrl + e will do the end-of-line much like a typical Emacs. But a mere change to the vi key binding(by executing "bindkey -v" while the emacs key binding would be reverted back by "bindkey -e") won't do as still the typical del and end key problem persist.

So the fix would be to override the key bindings of the shell and not of the terminal!

The normal user defined information for the respective terminals are present in their respective rc files, you may add one in your ~/ for individual preference or in the /etc for system wide change.

Tip 1) Press Ctrl+V and then the key to find the key binding for that key. For eg. if you press Ctrl+V and then press Home key, you should be getting ^[[1~.
Tip 2) Execute bindkey to find the current key bindings of all the key sequence in your current terminal view.

So the steps would be:

0) First you must understand that, cshell has the default Emacs key binding. Better read the manpage of cshell(say man csh)
1) Create a new file in ~/ with the name .cshrc if one doesn't exist.
2) Add the following lines in your .cshrc file:

if ($term == "xterm" $term == "vt100") then

bindkey "\e[3~" delete-char
bindkey "\e[4~" end-of-line
endif

3) You can add further lines to change the behaviour of any other keys as u wish!

Happy linuxing and happy Firefoxing!! [:D]

0 Comments:

Post a Comment

<< Home