Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Vim-c-cr, a super simple plugin to give ctrl+enter a little magic (github.com/jtmkrueger)
4 points by thatmiddleway on June 1, 2013 | hide | past | favorite | 2 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!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: