Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Linux: disable vim auto-comment

Posted on 2016-09-27
7
Medium Priority
?
263 Views
Last Modified: 2016-09-29
Hi UNIX/Linux experts,

Sometimes I copy and paste code into a text file which I have opened with vim (vi improved).  By default, if any line I paste starts with a comment character ("#"), vim will automatically prefix all subsequent lines with a "#".  To avoid this from happening, I can type this command before I do the pasting:
    :set comments=
Although that works, I would like to have this option set by default.  I have tried putting this:
    set comments=
into my .vimrc file, but it doesn't seem to make any difference.

Please post tested solutions only.

I'm using vim version 7.4.160 on Linux (GNU).

Thanks.
tel2
0
Comment
Question by:tel2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 12

Accepted Solution

by:
andreas earned 2000 total points
ID: 41819588
Try putting
autocmd FileType * setlocal fo-=r 

Open in new window

in your .vimrc file

Then auto commenting will be turned off for all file types.
0
 
LVL 12

Author Comment

by:tel2
ID: 41820635
Thanks andreas!

That seems to work.

Where did you get that from?  Can you provide a (blind) link, please?    8)
0
 
LVL 12

Author Comment

by:tel2
ID: 41820745
...and I just noticed that after adding the command you gave me to .vimrc, and then removing it again, I can't reproduce the problem.  Any ideas why?  Is it just a one-off which doesn't have to stay in .vimrc?  If so, where is the fact that it's been executed remembered?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Expert Comment

by:andreas
ID: 41820829
can you turn it on again by putting +r insted on -r? and then remove from vimrc again? does it stay on?

I'm not sure if it is normal behavior, until now i naver had to change .vimrc for myself as happy with default config on my distro.

Here is the link where i found the command. http://vim.1045645.n5.nabble.com/Turning-off-auto-comment-yes-already-tried-that-td5488277.html
0
 
LVL 12

Author Closing Comment

by:tel2
ID: 41820848
Hi andreas,

Cancel my last post.  I've just realised that the cause was.  My original problem was with .pl files, but I was testing your solution with a file with no extension, e.g.:
    vim testfile
but it seems the problem would never have occurred with that last scenario.

Thanks for the link!

tel2
0
 
LVL 12

Expert Comment

by:andreas
ID: 41821213
Ok but thanks for the feedback.
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question