-- Leo's gemini proxy

-- Connecting to thrig.me:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini

Some #forth folks did not know the f F t T commands in vi(1), so on the odds that other vi users likewise do not know them, what follows is a short primer on these commands. Hopefully your version of vi hasn't mangled these commands too much; I'm using a somewhat modified version of the vi(1) that ships with OpenBSD.


"f" is short for find.

"t" is short for "up to".

You may want to invent your own mnemonics for these.

To spell "mnemonics" it's the last two letters of "damn" and then "demonic" minus the first letter.

"F" and "T" do the same thing as "f" and "t", only that they search backwards in the line from where the cursor is instead of forwards.

The next key you press is the character found or moved to.

";" and "," are relevant after a previous "f", "F", "t", or "T" command.

Numeric prefixes and other commands can be used with the above.


Examples may help.


    .i le mlatu cu cadzu le djacu

Assuming the cursor is at the beginning of the above line, one may want to jump to the "djacu". The command "/dj^M" would get you there, but that's four characters, and you might want to reserve that search buffer for something else. The command "fd" or "find dee" will take the cursor to the "d" in "cadzu", and then the command ";" will move to the next "d". If you notice the "d" in cadzu you maybe could use "2fd" to advance directly to the second "d" found from where the cursor is, but here "fd;" would also work, among other command patterns.


With "^" representing the cursor position followed by vi commands, a clumsy illustration of this may run something like:


    .i le mlatu cu cadzu le djacu
    ^ 2fd
    .i le mlatu cu cadzu le djacu
                            ^ cwdargu^[
    .i le mlatu cu cadzu le dargu

So that's "2fdcwdargu^[" to replace "djacu" (water) with "dargu" (road). I've memorized all this, a lot, so it pretty much happens automatically. Probably like piano scales it needs to be practiced.


Even fancier is to combine the "f" or "t" with the "c" (change) or "d" (delete) commands. With the cursor at the end of the following line of C code, a "T(" and then a "2;" will move the cursor to the "p" in promptbuf. (An "upto" search needs a "2;" to jump over the already adjacent match). Then, "c2t)" will allow you to rewrite the entire argument list to sprintf: change, 2nd match, upto, the letter "t". You could also use "Fp;;" instead of "T(2;" to move back to the "p" in promptbuf, or maybe "0f(l" to get there (beginning of line, find "(", one right).


    sprintf(promptbuf, "Which %c do you want? (0-f)", obj->o_type);

Or, "df." will delete to the end of a sentence, while "ct." will change upto the end of said (assuming no inner "." within the sentence, like this one has). Whether these commands make sense for how you edit things will require practice.


Even more complicated is "yt)", which would yank upto the next ")" character. With the command "ayf) and then "ap (the " is part of the commands here) you can yank and then put what got placed into the "a" buffer.


On an unrelated note, gewöhnungsbedürftig is a funny word I learned about today, being not much exposed to German. On an even more unrelated note, I did once play a bit of a Beethoven piano sonata in West Berlin (this was some years ago).


tags #vi

-- Response ended

-- Page fetched on Tue May 21 23:01:16 2024