# Type into two places at once [duplicate]

I am working in macvim with a latex file where I have an index where terminology is being stored (using \usepackage{imakeidx} and \makeindex).

I have a command for inserting terminology with emphasis and then indexing said terminology:

autocmd Filetype tex inoremap :nx \emph{<++>} \index{<++>}<++><Esc>01k<C-j>


The issue is that I have to type the same word or term twice which gets a bit annoying.

Is there a way of typing in both places at once?

• Search this site for "multiple cursors". There's plenty of into about plugins as well as reasons for not using them and doing things in a more Vim way. Jan 10 '21 at 19:07
• One example: Multiple cursors at desired location Jan 10 '21 at 19:09
• @D.BenKnoble The one I linked/duped mentions vim-multiple-cursors...though it's in the question. Here's one that mentions the same plugin in an answer vi.stackexchange.com/questions/3165/… Jan 12 '21 at 14:11

I have not a direct way, but you can use a command as a workaround.

I am assuming the <++> is the terminology you want to insert.

autocmd Filetype tex inoremap :nx <Esc>:NX<Space>

command! -nargs=1 NX execute "normal! i\\emph{".<q-args>."} \\index{".<q-args>."}".<q-args>."01k\<Esc>"


When you type :nx in insert mode, you will be prompted in the command-line mode (juste at the bottom of the screen) with the pending command :NX that is waiting for an argument to be given.

Exemple:

:NX Entry


will create:

\emph{Entry} \index{Entry}Entry01k

Infos: :help :command :help <q-args> :help :execute :help :normal

• I like this command approach and it works. Jan 10 '21 at 19:56
• The 01k isnt meant to be inserted literally; it’s a series of normal-mode commands Jan 10 '21 at 21:01