l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
November 4: Social gathering
Next Installfest:
TBD
Latest News:
Oct. 10: LUGOD Installfests coming again soon
Page last updated:
2004 Nov 30 14:33

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] vim question: making mapping atomic w.r.t the '.'command
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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



LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
EDGE Tech Corp.
For donating some give-aways for our meetings.