LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Navigating the command line (https://www.linuxquestions.org/questions/linux-software-2/navigating-the-command-line-482681/)

pwc101 09-12-2006 03:59 AM

Navigating the command line
 
I often write quite long commands into a terminal, something like this
Code:

awk '{print $3}' data.txt | pshistogram -JX15 -R0/6/0/10 -Ba0.5f0.25:"Grain Size (cm)":/a1f0.5:%::."Grain Size Distribution":WeSn -W0.01 -G100/100/100 -L0/50/200 -T0 -Z1 -K -P -Xc -Yc > histogram.ps && gs histogram.ps
before I put them in a script.

As I'm testing the command, I need to edit various flags in order to get my graph (in this instance) to look right. My problem is that it takes a while to scroll through the commands letter by letter using the arrow keys. I've discovered that ctrl+a and crtl+e take me to the beginning and end of the line respectively, but I was wondering if there were any commands that can shift me backwards and forwards by one word, much like w, e and b do in vi?

Any help gratefully received :)

unSpawn 09-12-2006 04:21 AM

Check Bash "bind" builtin values: "bind -p|grep ward-word".

odcheck 09-12-2006 04:23 AM

I just copy and paste your text and I tried simply
CONTROL+KEY LEFT or RIGHT then it does jump from word to word.
Is that what you've been looking for?

pwc101 09-12-2006 04:55 AM

odcheck: If I try ctrl+left or crtl+right, it types D and C (and ctrl+up and ctrl+down gives A and B).

unSpawn: I don't fully understand what you said. I've had a look at the bash manpage, and it seems I need to add something to ~/.inputrc. However, the default shell on these machines is csh, not bash (I'm at university and I don't have root access); sorry, should have mentioned that before. Currently running RHEL4.

druuna 09-12-2006 05:03 AM

Hi,

Which editor is your bash using? It defaults to emacs (too my knowledge).
If it is emacs: Check the emacs docs for key navigation (sorry, cannot tell you which keys. I'm a vi edict :) ). It should also be mentioned in the bash manpage.

If you like vi, you can also change your default editor (try set -o vi from the command line and start using vi codes.

Hope this helps.

pwc101 09-12-2006 05:17 AM

Thanks druuna. I checked out the csh manpage (since I'm using csh and not bash) and csh defaults to emacs style navigation (but "bindkey can change the key bindings to vi-style bindings en masse" apparently). Running the bindkey command displays all the possible keystroke combinations, some of which I knew (crtl+a, crtl+e), but a whole host of which I didn't. However, I'm still a little confused because I don't understand the syntax of the shortcuts. For example, the commands I'm looking for are these:
Code:

"^[b"          -> backward-word
"^[f"          -> forward-word

however, I have no idea what ^[f is in terms of keystrokes. I tried ctrl+[+f, and that didn't work. Can anyone clarify for me?

edit: having looked around on google a bit, it seems that ^[ is escape. problem solved :)

edit 2: just in case anyone needs info on the csh shell and setting keybindings for custom shortcuts, I found this page quite useful http://www.sm.luth.se/~alapaa/file_f...pt/ch30_14.htm

I also added this to my ~/.cshrc:
Code:

# bindkey functions (ctrl+something = function)
bindkey ^f forward-word
bindkey ^b backward-word

which makes ctrl+f and ctrl+b move one word forwards and one word backwards respectively.

ntubski 09-12-2006 12:08 PM

As you found ^[ is escape, but it can also be typed ctrl+[. There is a third option if the terminal is setup properly: you can type alt+f instead of esc+f.


All times are GMT -5. The time now is 05:58 PM.