As always, this is a post in progress, I may update it from time to time, so don’t worry if you don’t find what you need, come back later and maybe you will find it next time 🙂
I also apologize for the poor quality of the demonstration, because I find this subject to be very harsh to
reproduce in text-mode, especially to show the reactions on the screen due to the keyboard actions…
Sorry for that.
You need to use ksh of course (set by default) , and set the EDITOR variable to vi in your .profile like this …
# echo $SHELL ksh # grep EDITOR .profile .profile:export EDITOR=vi
… or set the vi mode into your active shell, like this :
# set -o vi
Now we shall start.
I may add that in this topic I wrote ESC +« letter », but it has to be understood as « Hit escape key to go to the vi mode, then hit the key [letter] » … I realize that it is not so obvious when I read it…
Navigating through your command lines
I won’t be insulting you by explaining how you can move between your command lines, but i’ll sum it up here in a few lines, in fact these are the shortcuts I’m using on a every-day basis :
[ESC]+j : go to next line
[ESC]+k : go to previous line
[ESC]+l : go to the next character on the right
[ESC]+h : go to the next character on the left
[ESC]+/ : search a word through the command line history, hit « n » to continue the search, or « enter » to edit the line you wish to use
[ESC]+w : go to the first letter of the next word
[ESC]+e : go to the last letter of the current word
[ESC]+cw : change the rest of the word, starting from the current position
[ESC]+0 : go to the first character of the line
[ESC]+$ : go to the last character of the line
Word Completion, bash-like
One thing we all really miss from bash is the easy word completion with the [TAB] key . I think that’s why so many unix users continue to use bash on AIX , instead of the standard packaged Korn Shell
(that’s not the only reason of course).
Actually, there is a way to keep in line, and stick with ksh like a regular AIX guy, let’s check it out 🙂
Here you can type the first letter of the wanted file/directory , then [ESC+*]
It will execute direct completion if only one file/directory, or write down all the matching files/dir beginning with the provided letter :
# ls .profile .vi_history default.log smit.log .rnd .vimrc lance.config.ksh smit.script .sh_history CBB lance.config.log smit.transaction .ssh config3.ksh listdisk.sh # ls -l c[ESC+*] # ls -l config3.ksh <-- completes your line with the only file starting with "c" # ls -l s[ESC+*] # ls -l smit.log smit.script smit.transaction <-- completes with all files starting with "s"
Now let’s see a small difference in the completion with [ESC+\] :
if you have many files starting with the same letter, [first letter][ESC+*], will write down all files starting with [first letter].
You can narrow down the selection by adding the second letter, reducing the choice of potential candidates, and then choose to type [ESC+\] in order to write only the file you want. if there is still several candidates, you may add a third letter, and so on, and so forth.
Let’s take the same example as above , we have 3 files starting with s, but we want to display only smit.log :
# ls .profile .vi_history default.log smit.log .rnd .vimrc lance.config.ksh smit.script .sh_history CBB lance.config.log smit.transaction .ssh config3.ksh listdisk.sh # ls -l s[ESC+\] <-- nothing happens, because of many "^s" files # ls -l smit.l[ESC+\] <-- narrow down to one candidate, the only one starting with "smit.l" # ls smit.log <-- completion did its job
Getting a list of files/dir
This is equivalent to a single [TAB] in bash, without precising any letter (a luxury we won’t be able to afford with ksh, without adding a * )
It displays a numbered , alphabetically sorted , list of all the files starting with the specified letter.
I find it really useful, I use it all the time !
list all the files/directory in current directory
# ls .profile .vi_history default.log smit.log .rnd .vimrc lance.config.ksh smit.script .sh_history CBB lance.config.log smit.transaction .ssh config3.ksh listdisk.sh # ls [ESC+=] 1) CBB/ 2) config3.ksh 3) default.log 4) lance.config.ksh 5) lance.config.log 6) listdisk.sh 7) smit.log 8) smit.script 9) smit.transaction
Please notice that the hidden files are not displayed, you will have to add a « . » first, like with ls command.
List files starting with …
# ls .profile .vi_history default.log smit.log .rnd .vimrc lance.config.ksh smit.script .sh_history CBB lance.config.log smit.transaction .ssh config3.ksh listdisk.sh # ls -l c[ESC+=] 1) config3.ksh # ls c
See ? it didn’t complete the filename, even though there is only one file/Dir starting with the letter « c ».
Instead it just displays a list of potential candidates for your completion search.
You can see that you are still with your command, uncompleted.
If what is displayed is indeed the right and only choice, you just have to use the completion key
Let’s try with the letters « sm », which can show different smit logfiles:
# ls -l sm[ESC+=] 1) smit.log 2) smit.script 3) smit.transaction [/sourcecode]
So we have 3 candidates : smit.log, smit.script and smit.transaction.
In a perfect world, we would want to just type the number of the file we want , and the shell would
select it and complete the command line. Unfortunately, it doesn’t work that way. You cannot (as far as
I know) select words with the number affiliated to them. So you just have to narrow down the list
of candidates, in order to have only one choice, which will be automatically completed on your command line :
#ls -l smit.[ESC+=] 1) smit.log 2) smit.script 3) smit.transaction #ls -l smit.l[ESC+=] <-- narrowing down the possibilities 1) smit.log #ls -l smit.l[ESC+\] <-- we can complete it now #ls -l smit.log -rw-r--r-- 1 root system 618575 Nov 17 15:26 smit.log [/sourcecode]
It doesn’t look very sexy, but I can assure you that it is as efficient as the good ol’ [TAB] completion in bash, after some practicing. You just need more fingers , but, aren’t unix admins some kind of octopus? 🙂
Recall the last argument of the previous command
It can be useful when you need to recall the same argument with different commands , say I found a file and I want to know what’s its ‘size in Megabytes, without copying/pasting the path or editing my last command
# ls /var/tmp/lpar2rrd-agent-server-root.txt /var/tmp/lpar2rrd-agent-server-root.txt # du -sm [esc+_] # du -sm /var/tmp/lpar2rrd-agent-server-root.txt <-- line automatically completed with the filename
Please participate with your tips if you have some, this post could get bigger and bigger ! 🙂