[Tex/LaTex] custom mapping for >italicize marked text / text under cursor< (using vim)

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 ctrlj 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
  • shiftf6 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)

Best Answer

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, vaw`em will select the current word a place in inside \emph{}.