betabug... Sascha Welter

home english | home deutsch | Site Map | Sascha | Kontakt | Pro | Weblog | Wiki

10 September 2007

veni, vi, map!

Fun editing

Yesterday's pet riddle: Editing a large file, where quotation marks should become "smart" (or typographical) quotation marks. The file being LaTeX, it also contained a big heap of quote marks in code, mainly used for German umlauts (which to LaTeX are written as {\"a}). So I opened the file in vi for some playing...

Step one was to search for the quotation marks, but not giving me all the German umlauts: /[^\\]" would do that trick.

I could then go and change "text in quotes" to "`text in quotes"', by moving the cursor a bit over (the regex stops at one character before the ") and inserting ` for the opening quote char or ' for the closing one. That gets boring pretty fast in a large file.

Next thing was then to define two shortcuts, or "maps" as they are called in vi land:

:map v la`ESC
:map f la'ESC
where the ESC is produced by hitting control-v and then Esc on the keyboard. Note that I'm redefining existing command keys, which usually is a bad idea. But this is a temporary solution, I'm not putting this in any settings file. Next time I'll start up vi, these shortcuts are gone again.

Now I went through the file simply by hitting "n" (for "search next") and then typing "f" or "v" for closing or opening quote marks. It becomes a game.

Posted by betabug at 13:02 | Comments (0) | Trackbacks (0)
ch athens
Life in Athens (Greece) for a foreigner from the other side of the mountains. And with an interest in digital life and the feeling of change in a big city. Multilingual English - German - Greek.
Main blog page
Recent Entries
Grüezi mitenand! (10/03 22:13)
It rained in September (09/30 19:35)
Dirty Fun with the CX Bike (09/05 17:59)
Kein Wasser im Paradies (08/31 23:05)
Best of
Some of the most sought after posts, judging from access logs and search engine queries.

Apple & Macintosh:
Security & Privacy:
Misc technical:
Athens for tourists and visitors:
Life in general:
<< Lost and Found: Bookshop | Main | My List of English Bookshops in Athens >>
There are no comments.
You can trackback to:
There are no trackbacks.
Leave a comment