Saturday, June 27, 2015

Re: Auto-commenting

On Sun, Jun 28, 2015, Meino.Cramer@gmx.de wrote:
> Hi,
>
> when using vim for editing Perl sources, vim proceeds
> the next line with an comment sign '#', if the previous
> one was a comment line using <RET> in insert mode.
>
> To not to miss even one of the wonderful feature of vim ;) :
>
> Suppose the situation is as follows (inser mode)
>
> # this is a comment in perl _
>
> and "_" is, where my coursor is, Now I want to start
> coding in the next line. <RET> gives me a new line, but
> with a "#" in front of it, which I need to delete.
>
> Another way to get "commentless" to the next line would
> be <ESC>o
>
> Is there any other more elegant and/or shorter way to accomplish this?
>
> Thanks a lot for any help in advance!
> Best regards,
> Meino

I use these two mappings, Alt+Enter and Shift+Enter. I've found that
different Vim UIs have issues with one or the other of these, so I map
both.

inoremap <silent> <A-CR> <C-o>:let b:fo=&fo<Bar>set fo-=r<CR><CR>x<Backspace><C-o>:let &fo=b:fo<Bar>normal! gi<CR>
inoremap <silent> <S-CR> <C-o>:let b:fo=&fo<Bar>set fo-=r<CR><CR>x<Backspace><C-o>:let &fo=b:fo<Bar>normal gi<CR>

I believe Raimondi on FreeNode did most of the work on creating these.
fo is formatoptions (:h formatoptions).

--
Eric Christopherson

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment