# custom mapping for >italicize marked text / text under cursor< (using vim)

I can't find this here, nor anywhere else. Either it's too simple, or I'm looking at the wrong places, or whatever. (Maybe the answer is out there somewhere, or worse, in here somewhere without my knowing).

I'd like to create a "shortcut". when my cursor is on a certain word, I want this word to become (in output) italic, meaning to surround it by \emph{some word}.

I'm using vim (with LaTeX-Suite) so it is quite straightforward to use FEM to start italic "mode" and ctrl-j to "end it". but on already written text, it becomes more complicated.

after researching,
I tried

:call IMAP ("< S-F6>", "b i FEM < ESC> d e i { < ESC> e a } < ESC>", "tex")*


(I will translate this into words: go to beginning of word, insert, create \emph environment, escape(to normal mode), delete to end of word (i.e., to end of <++>), insert {, escape, go to end of word, insert } (after), then escape back into normal mode. sounds complicated, I guess there's millions of other ways of doing it but that's not the problem)
I tried with various versions of adding \ before < ESC> and } (i think vim likes that), not using spaces, and the like. nothing happened.

I also tried

:nm {< S-F6>} {see above}


and then I ran out of energy and gave up.

alright, so maybe

• the function already exists somewhere
• shift-f6 is not an accepted operator
• ???

in any case, I hope you can help

*N.B. I have added a space after every < because otherwise it wouldn't print. it is not in the code (attempts)

-
I don't know anything about vim, but the introductory phrase of your question deserves a +1. ;-) –  lockstep Oct 25 '10 at 16:43

This is really a vim question rather than a TeX question, but in LaTeX suite, typing em in visual mode puts current selection into \emph{}. To select a word when in VISUAL mode, type aw. So, from normal mode, vawem will select the current word a place in inside \emph{}.

-

This should work, modified and snipped from my .vimrc

imap <F5> <ESC>diwi\emph{<ESC>pi<Right>}


This maps <F5> in insert mode to

1. Escape to normal mode
2. Delete the word under cursor (the diw sequence)
3. Enter insert mode
4. Type \emph{
5. Escape to normal mode
6. Put the yanked word under cursor
7. Enter insert mode again
8. Move right, and type }

Leaves you in insert mode. (Since this is an imap, it start sin insert mode and ends in insert mode. If you want it to start working in normal mode, I suggest you use nmap and move the first <ESC> to the end of the incantation, to start in normal mode and end in normal mode.)

Of course, this would cause trouble if your "words" can include things other than alphanumeric characters, since the diw chant won't work for symbols unless you redefine a few other things (like how vim recognizes word boundaries).

-
Btw, <S-F6> should be allowed in vim, and new maps override old ones. –  Willie Wong Oct 25 '10 at 17:22