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.

3
  • 1
    As far as I recall, using TeX ligatures is discouraged in modern (Unicode-aware) implementations of LaTeX. So the solution is to either use the proper Unicode quotes or a package like csquotes that handles them for you. Just my two cents and definitely offtopic here.
    – Friedrich
    Sep 4 at 11:09
  • @Friedrich, I didn't know of this "discouragement", so it's good to know, thanks!
    – Enlico
    Sep 4 at 11:35
  • It's something I picked up, you might want to do a little digging. Next thing, you will ask a question how to turn a quote into the appropriate csquote macro depending on context :-)
    – Friedrich
    Sep 4 at 11:42

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.