0

I have a document that needs a lot of symbols in math environment, that have both superscripts and subscripts like x_1^1, x_1^2, x_2^1, x_2^2, with different bases. x could be y, z, etc....

Having to type Shift+^ and Shift+_ all the time really hurts. Is there an easier way to type these repeating symbols this?

Just typing x11, x12, x21, x22 and then replacing these strings with the respective strings with _ and ^ (x_1^1, etc...) helps, but is there a more VIM way to do it?

  • 1
    1) I don't have VIM but i thing you can configure the shortcuts 2) if you have \omega_1^1 repeted you can use \newcommand{\om}{\omega_1^1} and then replace \omega_1^1 bu \om – touhami Mar 26 '15 at 19:11
  • 1
    may be this help in some cases \newcommand{\s}[3]{#1^#2_#3} and than $\s x11+\s x12+ \s\beta11$ – touhami Mar 27 '15 at 10:33
  • This is so cool and it's just right for me! Thanks!!! (copy/paste the comment as answer and I'll obviously accept.) – Konstantinos Mar 27 '15 at 17:39
1

Here is a Vimscript solution. In ~/.vim/ftplugin/tex.vim, add the following:

function! <SID>SubSuperscripts(keyOne, keyTwo)
  let l = strpart(getline("."), col(".")-4, 3)
  if len(l) == 3 && l[2] == a:keyOne
    return join(["\<bs>\<bs>\<bs>_", l[0], "^",  l[1]], "")
  else
    return a:keyTwo
  endif
endfunction
inoremap <buffer> <silent> & <C-R>=<SID>SubSuperscripts("^", "&")<CR>

Now, in insert mode the key sequence ^& changes the preceding 2 characters into a subscript and superscript respectively. For example, inserting x12^& will change to x_1^2 and \omega11^& will change to \omega_1^1.

The key sequence^& can be customised by changing ^ and & on the final line. (Don't forget the first & too.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.