Auto-commenting

20 views
Skip to first unread message

Meino....@gmx.de

unread,
Jun 28, 2015, 12:01:07 AM6/28/15
to vim...@googlegroups.com
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 dont know all these editor wars. There is only one editor." ;)


Jack Stratton

unread,
Jun 28, 2015, 12:55:49 AM6/28/15
to vim...@googlegroups.com
Hi,
I believe disabling the 'r' formatoption is what you want.
See ":h formatoptions" for how to change them (and what they are), or
":h fo-table" to see all the available options.

Here's an online copy:
http://vimhelp.appspot.com/change.txt.html#fo-table

'r' is not set by default in vi(m), so I imagine your .vimrc has the
option
set and you simply forgot it was there ;)

HTH,
--
Jack

Eric Christopherson

unread,
Jun 28, 2015, 1:07:47 AM6/28/15
to vim...@googlegroups.com
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

Meino....@gmx.de

unread,
Jun 28, 2015, 1:15:14 AM6/28/15
to vim...@googlegroups.com
Jack Stratton <ja...@phroa.net> [15-06-28 07:08]:
> --
> --
> 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+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

Hi Jack,

thanks for reply and yout help! :)

I looked into my .vimrc and found

set formatoptions-=o

so, no "r" ist set. I dont want to switch of this feature completly.
My search was for a short and handy/elegant way to get into
the first code line from the last comment line.

Best regards,
Meino


Christian Brabandt

unread,
Jun 28, 2015, 3:49:26 AM6/28/15
to vim...@googlegroups.com
Hi Meino.Cramer!

On So, 28 Jun 2015, Meino....@gmx.de wrote:

> I looked into my .vimrc and found
>
> set formatoptions-=o
>
> so, no "r" ist set. I dont want to switch of this feature completly.
> My search was for a short and handy/elegant way to get into
> the first code line from the last comment line.

This could be set by the ftplugin. The best way to check from where this
comes, is in the buffer that has this behaviour issuing:
:verbose set fo?

For me this echoes:
formatoptions=crqol
Zuletzt gesetzt von ~/local/share/vim/vim74/ftplugin/perl.vim

Best,
Christian

--
Was sagt ein Mercedes-Fahrer, wenn sein Auto auf dem Dach liegt?
A: Aaaaaa - Klasse.

Christian Brabandt

unread,
Jun 28, 2015, 3:51:23 AM6/28/15
to vim...@googlegroups.com
Hi Meino.Cramer!

On So, 28 Jun 2015, Meino....@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

I usually do not bother and press enter followed by <Ctrl-U> or <Ctrl-W>
If you are really lazy, you could map this to some other key however.

Best,
Christian
--
Der Weise sagt niemals, was er tut - aber er tut niemals etwas, was
er nicht sagen könnte.
-- Jean-Paul Sartre
Reply all
Reply to author
Forward
0 new messages