Next Meeting: April 21: Google Glass Next Installfest: TBD Latest News: Mar. 18: Google Glass at LUGOD's April meeting Page last updated: 2004 Nov 30 14:33
Re: [vox-tech] vim question: making mapping atomic w.r.t the '.'command

# Re: [vox-tech] vim question: making mapping atomic w.r.t the '.'command

Hi Henry,

On Mon 29 Nov 04,  6:27 PM, Henry House <hajhouse@houseag.com> said:
> I have a nice mapping in Vim 6:
>
> 	:nmap gfe cw\empf{^[pa}^[
>
> which emphasises a word when the buffer contains LaTeX source.

This macro works, but you have to position the cursor on the beginning of the
word, otherwise, you end up with only a part of the word emphasized.  Another
strategy would be:

1. Find the previous space character.
2. Move the cursor right by one.
3. Then change the word.

Here would be that strategy expressed as a macro:

:nmap gfe F lcw\empf{<esc>pa}<esc>

The deficiency with my macro is that it doesn't work on the first word of
each line since there's no space before it.

The benefit is that you can be "anywhere" in the word (provided the word
doesn't start a new line) and it'll work.

Depends on which you find is the bigger annoyance.  ;-)

> It would be groovy if this were considered one action by Vim for the
> purpose of repeating it using the . operator. In other words, I want to
> find a word, emphasise it using gfe, then find another word, and emphasise
> it by hitting the period. Can anyone suggest an inplementation method?

Indeed.  The dot operator is useful, but has its limitations.  It only works
for atomic edits.  Unfortunately, the last "edit" in your macro is:

a}

There's no way of getting around this, so the dot operator isn't what you're
looking for.  My first instinct (which is wrong) was to use the recording
mechanism.  Try this in command mode:

qaF lcw\emph{<esc>pa}<esc>q           (1)

Note: the <esc> should not be taken literally in (1).  Actually press the
escape key.  From here on out, you can use @a to redo the macro.

Unfortunately, this doesn't help matters either.  I was hoping that the dot
operator would perform the command @a, but it doesn't.  Maybe vim has a
wishlist...

If you want to use a single keystroke to emphasize text, I think perhaps the
best strategy would be to put this in your .vimrc file:

au BufNewFile,BufRead *.tex nmap <F1> F lcw\empf{<esc>pa}<esc>

where <F1> would be whatever key you want to remap.  This mapping would only
affect files that end in ".tex".

BTW, another possibility would be:

:nmap gfe bcw\empf{<esc>pa}<esc>

This would work anywhere in the word except for the first letter, which isn't
too much of an annoyance.  Presumably, you've already typed the word and want
to add emphasis, so the cursor is already to the right of the cursor.

It's a frustrating problem, isn't it?  I think it boils down to the fact that
you can only assign so many things to single character commands.  At some
point, you really need multiple character commands (otherwise, Vim would be
the equivalent to the Beeblebrox's "Heart of Gold".  ;-)

I'd love to hear other takes on this.

Pete

--
The mathematics of physics has become ever more abstract, rather than more
complicated.  The mind of God appears to be abstract but not complicated.
He also appears to like group theory.  --  Tony Zee's "Fearful Symmetry"

PGP Fingerprint: B9F1 6CF3 47C4 7CD8 D33E  70A9 A3B9 1945 67EA 951D
_______________________________________________
vox-tech mailing list
vox-tech@lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox-tech