Skip to content

Vim-c-cr, a super simple plugin to give ctrl+enter a little magic

github.com/jtmkrueger
4 pointsthatmiddleway2 comments
On HN

Comments

Note that <C-CR> only works in GUI Vim because it is virtually indistinguishable from <CR> in (most?) terminal emulators. They actually send different signals but Vim doesn't care.

I've had many slightly dumber variations of that mapping in my ~/.vimrc for a while, using <leader><CR> instead of <C-CR> for the reason outlined above.

Edit

I borrowed you Closer() function and modified it to make it work simply on <CR>, based on my previous mapping:

    " my previous mapping
    inoremap <leader><CR> <CR><C-o>==<C-o>O

    " your revised function
    function! Closer()
      let  prevchar = getline(".")[col(".")-2]
      if prevchar ==# "{"
        return "\<CR>}\<C-o>==\<C-o>O"
      elseif prevchar ==# "["
        return "\<CR>]\<C-o>==\<C-o>O"
      elseif prevchar ==# "("
        return "\<CR>)\<C-o>==\<C-o>O"
      else
        return "\<CR>"
      endif
    endfunction

    " your revised mapping
    inoremap <expr> <CR> Closer()

This is potentially very nice for CSS. Thanks for sharing!

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.