The comment auto-insert feature is often very helpful and otherwise very annoying, depending on the kind of comment I am writing. Is it possible to bind the auto-insertion of // exclusively to <shift+enter>, and skip the auto-comment for ordinary <enter>? I thought about binding a key to some kind of temporary setlocal, but it seems too complicated since setlocal is meant for local scope (obviously) and not for immediate modifiers.

This earlier question is similar but really not the same: Remove automatic comment leader

  • inoremap <S-Enter> <C-\><C-O>:setl fo+=r<CR><CR><C-\><C-O>:setl fo-=r<CR>
    – Matt
    Sep 28 '19 at 20:25
  • Thanks, well it works when I map it to C-y or any other control combo, but <S-Enter> seems not to be mappable. Any suggestion why not? Sep 29 '19 at 1:58
  • Your terminal doesn't send distinct character code when typing Enter vs Shift Enter. Vim can't distinguish keypresses that your terminal doesn't distinguish. You'd either have to configure your terminal to send a different escape sequence on Shift Enter, or use GVim (GUI Vim) which is preconfigured to handle this correctly.
    – Lie Ryan
    Sep 29 '19 at 4:50

Your Answer

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

Browse other questions tagged or ask your own question.