0

The usecase is LaTeX, which I write using VimTeX.

To make double quoted words one would write ``words''.

However, I'm much more used, from many other contexts (both prose and code), to type " for both opening and closing double quotes, and I often forget I have to press `` and ''.

So I'd like a way to change " to `` or '' depending on whether it's preceded by a space (or tab) or not.

So far I've come up with the solution I propose in the self answer, but I'd like to know whether there's something better.

1 Answer 1

0

This is the solution I've come up with,

inoremap <buffer> <expr> " <sid>expand_double_quote()
fun! s:expand_double_quote()
  if col('.') < 2 || getline('.')[col('.') - 2 ] == ' '
    return "``"
  else
    return "''"
  endif
endf

which I've put in $HOME/.vim/after/ftplugin/tex.vim.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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