Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

vi: How I stopped the autoappend # signs

37 views
Skip to first unread message

T

unread,
Jul 29, 2015, 1:43:08 AM7/29/15
to
Hi All,

If you are using vi (i occasionally do) and it has started
auto-appending comment marks "#" at the beginning of every
you paste (drives me nuts), then in your .vimrc, place
the following (all on one line):

:autocmd FileType * setlocal formatoptions-=o formatoptions-=r
formatoptions-=c formatoptions-=t

HTH someone else,
-T

$Bill

unread,
Jul 29, 2015, 2:00:38 PM7/29/15
to
I use gvim and it doesn't do any # appending on pastes - at least none I've
encountered so far. Is it line by line or once per paste ? Does it make a
difference if you're pasting into an existing comment rather than code ?



T

unread,
Jul 29, 2015, 2:16:04 PM7/29/15
to
If the first line of the paste starts with a "#", then vi will
put it on every line. Since my first line is typically
"#!/usr/bin/perl", every subsequent line gets a comment mark
at the beginning. Drives me nuts.

And, this was not always the behavior. It happened after
an update.

I am currently running:
vim-enhanced-7.2.411-1.8.el6.x86_64


Eli the Bearded

unread,
Jul 29, 2015, 8:12:42 PM7/29/15
to
(Note: since all of this is rather off-topic in comp.lang.perl.misc, I
have crossposted and set follow-ups to comp.editors.)

In comp.lang.perl.misc, T <T...@invalid.invalid> wrote:
> If you are using vi (i occasionally do) and it has started
> auto-appending comment marks "#" at the beginning of every
> you paste (drives me nuts), then in your .vimrc, place
> the following (all on one line):

I've never had that happen.

> :autocmd FileType * setlocal formatoptions-=o formatoptions-=r
> formatoptions-=c formatoptions-=t

I believe two of those are useful ("t" and "c") and are automatically
turned off when textwidth (abbreviates as "tw") is set to zero, which
is the only default I've seen. Maybe a new vim has a new default? Or
maybe (and I think this is more likely) someone, eg your distro, set a
default in the system vimrc (perhaps /etc/vimrc).

From ":help fo-table" (which is referenced by ":help formatoptions"):

letter meaning when present in 'formatoptions'

t Auto-wrap text using textwidth
c Auto-wrap comments using textwidth, inserting the current comment
leader automatically.
r Automatically insert the current comment leader after hitting
<Enter> in Insert mode.
o Automatically insert the current comment leader after hitting 'o'
or 'O' in Normal mode.
q Allow formatting of comments with "gq".

I believe the purpose of "r" and "o" is to make continuation of a
comment automatic. When they are set, you can just backspace (<ctrl-W>
or <ctrl-U> also works) over them to end the comment.

The ":help fo-table" introduction tells me that '[t]he default setting
is "tcq", and ":help textwidth" tells me the default is 0, which means
formatoptions should be defaulting to values that don't change behavior
from traditional vi.

Personally, I have "autoindent" set, so that lines automatically start
out matching the indent of the "previous" line (which is the line the
cursor was last on, in the case of an "o" or "O" command), this indent
cannot be backspaced over, but is outdented with a <ctrl-D> as the
first thing typed on the new line. It's probably not for everyone, and
it greatly messes up pasting anything with leading whitespace.

But vim has a trick. You can ":set paste" to disable all automatic
formatting when pasting something, and ":set nopaste" when done. And,
since that's a lot of typing, you can set a hot key to toggle the
setting. I use <Insert> for that:

:set pastetoggle=<Insert>

Elijah
------
wasn't using un<shift>ed <insert> anyway

Eric Pozharski

unread,
Jul 30, 2015, 5:33:51 AM7/30/15
to
with <mpb563$s6t$1...@dont-email.me> T wrote:

*SKIP*
> If the first line of the paste starts with a "#", then vi will put it
> on every line. Since my first line is typically "#!/usr/bin/perl",
> every subsequent line gets a comment mark at the beginning. Drives me
> nuts.

Well,
:help pastetoggle

Saved me when I've turned from vim-gtk to vim-nox (I was overusing "*
back then).

> And, this was not always the behavior. It happened after an update.
> I am currently running: vim-enhanced-7.2.411-1.8.el6.x86_64

Now imagine what's coming. Makes me wanting to rebuild nvi with perl
support enabled (for reasons unknown debian doesn't ship nvi with perl).

--
Torvalds' goal for Linux is very simple: World Domination
Stallman's goal for GNU is even simpler: Freedom

$Bill

unread,
Jul 30, 2015, 8:26:06 AM7/30/15
to
On 7/29/2015 11:16, T wrote:
>
> If the first line of the paste starts with a "#", then vi will
> put it on every line. Since my first line is typically
> "#!/usr/bin/perl", every subsequent line gets a comment mark
> at the beginning. Drives me nuts.
>
> And, this was not always the behavior. It happened after
> an update.
>
> I am currently running:
> vim-enhanced-7.2.411-1.8.el6.x86_64

OK on gvim 7.4 (Windows native port).


Eli the Bearded

unread,
Jul 31, 2015, 4:26:55 PM7/31/15
to
In comp.lang.perl.misc, T <T...@invalid.invalid> wrote:
> If the first line of the paste starts with a "#", then vi will
> put it on every line. Since my first line is typically
> "#!/usr/bin/perl", every subsequent line gets a comment mark
> at the beginning. Drives me nuts.
>
> And, this was not always the behavior. It happened after
> an update.
>
> I am currently running:
> vim-enhanced-7.2.411-1.8.el6.x86_64

Vim 7.2 is from 2008. 7.3 is from 2010. 7.4 came out in 2013. If your
"update" is to seven year old code, then it is possible that you're
going to be running into things that have been fixed.

But for all versions of vim 7.0 to 7.4, the default setting of
formatoptions is "tcq" (from source inspection). That setting will not
show this behavior. Your issue is with changes to to defaults made
elsewhere. I suspect your distro's config options are at fault.

Elijah
------
is very careful about vi (and vim) configuration

T

unread,
Aug 1, 2015, 1:37:44 AM8/1/15
to
On 07/31/2015 01:26 PM, Eli the Bearded wrote:
> In comp.lang.perl.misc, T <T...@invalid.invalid> wrote:
>> If the first line of the paste starts with a "#", then vi will
>> put it on every line. Since my first line is typically
>> "#!/usr/bin/perl", every subsequent line gets a comment mark
>> at the beginning. Drives me nuts.
>>
>> And, this was not always the behavior. It happened after
>> an update.
>>
>> I am currently running:
>> vim-enhanced-7.2.411-1.8.el6.x86_64
>
> Vim 7.2 is from 2008. 7.3 is from 2010. 7.4 came out in 2013. If your
> "update" is to seven year old code, then it is possible that you're
> going to be running into things that have been fixed.

Ha!

I am running Scientific Linux 6.6, which is a Red Hat Enterprise
Linux 6.6 clone, also know as "Old-Out-of-date". This is on purpose
to provide a stable server platform. Drives me nuts. It is a
double edged sword.

Red Hat says support till 2020, but in reality, they have stopped
supporting anything but security back ports.

I am endeavoring to upgrade to SL 7. That code I wrote for determining
the Network is part of updating my firewall for SL7 (I have SL7
running in a Virtual Machine). Right now I am trying to get
my VM to give me an extra Ethernet port without bitching that
it is connected to nothing. (My base system uses two Ethernet
ports: one to the Internet and one to internal devices.)

>
> But for all versions of vim 7.0 to 7.4, the default setting of
> formatoptions is "tcq" (from source inspection). That setting will not
> show this behavior. Your issue is with changes to to defaults made
> elsewhere. I suspect your distro's config options are at fault.

I hope a lot of things get better when I finally get to 7!
0 new messages