minor vi/vim qstn
Polytropon
freebsd at edvax.de
Thu Sep 26 13:32:19 UTC 2013
On Wed, 25 Sep 2013 19:47:08 -0700, Gary Kline wrote:
> dunno how you know im using the zsh, but yup.
This is because of my magical allknowinglyness. :-)
You wrote:
> > > pts/14 17:11 <tao> [5011] vi!
> > > zsh: command not found: vi!
^^^
This gave me the impression you're using the Z shell.
The C shell says:
% vi!
vi!: Command not found.
And bash says:
$ vi!
bash: vi!: command not found
So the shell that says "zsh" should be the Z shell, or a different
shell that's just lying. :-)
> with the bang stuff
> if you do a
>
> % !-3
>
> you go back three vi cmds. !-N, N cmds.
Yes, this also works in C shell. You can use the "h" (or "history")
builtin command to get an impression of content of the last commands
submitted to the shell.
At least in csh,
% !-1
equals
% !!
and repeats the last command.
You could use the following command to print the last 20 commands
with the relative number (-1, -2, -3 and so on) printed infront of
them:
% history 20 | awk 'BEGIN {cmds=20} { printf("\t%2d\t%s\n", -(cmds-i), $0); i++ }'
It's probably a good idea to define an alias for that, like "h20"
(history of last 20 commands).
You could also use the zsh's equivalent of the "precmd" alias: It
is a command that will be executed prior to displaying the shell
prompt, so after you're done with a command, the last commands
(maybe shortened to 10, just substitute the two appearances of
the "20" to "10") will be displayed before the prompt appears;
this will make it easier (and save keystrokes) to check the last
commands and maybe repeat one.
Downside: The command "pollutes" the list of commands with itself,
so it should probably be grepped away.
% history 20 | awk 'BEGIN {cmds=20} { printf("\t%2d\t%s\n", -(cmds-i), $0); i++ }' | grep -v "history"
It might be good to define a better exclusion pattern than just
"history" because that might lead to false-positives. I'd suggest
to rename the variables in the awk script to something unique and
then grep for those instead...
> thankfully there are shortcuts!
And shell aliases. :-)
> ps: zsh is sort of a ksh clone; I remember porting the zsh onto
> my 286 in 1989. got a lot of csh-isms :)
The Z shell combines nice interactive features of the C shell
(to be correct: the tcsh) and the scripting features of sh and
bash. It's considered one of the most powerful shells. So it's
a wise move to use it, because it combines "the _good_ things of
both worlds" (and not the bad things, as the csh is a terrible
scripting shell, just as plain sh is an awful dialog shell).
--
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...
More information about the freebsd-questions
mailing list