Solved

Linux: disable vim auto-comment

Posted on 2016-09-27
7
64 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
  • 3
  • 3
7 Comments
 
LVL 11

Accepted Solution

by:
andreas earned 500 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 11

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 11

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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 11

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 11

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 11

Expert Comment

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

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now