1

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?

D. Ben Knoble
  • 26,070
  • 3
  • 29
  • 65
  • 1
    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. – B Layer Jan 10 '21 at 19:07
  • 3
  • 1
    @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 https://vi.stackexchange.com/questions/3165/edit-different-words-simultaneously-one-the-same-line-like-in-sublime-text-with/3173#3173 – B Layer Jan 12 '21 at 14:11

1 Answers1

1

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