Results 1 to 9 of 9

Thread: [SOLVED] vim auto insert comments '#'

  1. #1
    Join Date
    May 2006
    Beans
    64

    [SOLVED] vim auto insert comments '#'

    When I copy and paste using the 'right mouse button', comments and tabs automatically inserted in the copied text:

    ie
    Code:
    #!/usr/bin/perl
    use strict;
    my $test;
    ###
         if ($test) {  blah
               }
    my $test2;
    after copied:

    Code:
    #!/usr/bin/perl
    use strict;
    my $test;
    ###
         if ($test) {  blah
               }
    my $test2;
    ###
    #           if ($test) {   blah
    #                           }
    #                            my $test2;
    #
    #

    I am not using any aliases for vi in .bashrc or .bashrc_alliases

    Any ideas how to disable this?

  2. #2
    Join Date
    Feb 2007
    Beans
    4,045
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: vim auto insert comments '#'

    turn off smartindenting and autoindenting (not sure if you need to turn off both, but I never bother to check)
    Code:
    :set nosi noai
    A better solution, in my opinion, is to use one of the graphical versions of vim, which will not indent like that. Install vim-gnome, and try it by running «gvim». It integrates better with the mouse; if you mark something with the mouse, it treats it as a marking in visual mode etc...

  3. #3

    Re: vim auto insert comments '#'

    Another solution would be to turn on paste before pasting

    Code:
    :set paste
    And after pasting, turn it off

    Code:
    :set nopaste

    you can also bind a key to toggle these commands


    regards,
    Hardik

  4. #4
    Join Date
    Feb 2007
    Beans
    4,045
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: vim auto insert comments '#'

    Quote Originally Posted by rangalo View Post
    Code:
    :set paste
    Nice, didn't know about that one. Much better solution

  5. #5

    Re: vim auto insert comments '#'

    Quote Originally Posted by geirha View Post
    Nice, didn't know about that one. Much better solution
    I found this on vim.org they have really nice tips ...

  6. #6
    Join Date
    May 2006
    Beans
    64

    Re: vim auto insert comments '#'

    Quote Originally Posted by rangalo View Post
    Another solution would be to turn on paste before pasting

    Code:
    :set paste
    And after pasting, turn it off

    Code:
    :set nopaste

    you can also bind a key to toggle these commands


    regards,
    Hardik
    ahhh,thank you! that's what I was looking for.

    Quote Originally Posted by geirha View Post
    turn off smartindenting and autoindenting (not sure if you need to turn off both, but I never bother to check)
    Code:
    :set nosi noai
    A better solution, in my opinion, is to use one of the graphical versions of vim, which will not indent like that. Install vim-gnome, and try it by running «gvim». It integrates better with the mouse; if you mark something with the mouse, it treats it as a marking in visual mode etc...
    yeah, i have gvim installed and that was not affected. no worries


    thank you everyone!

  7. #7
    Join Date
    May 2008
    Beans
    1

    Re: vim auto insert comments '#'

    thank you this post.

    I'm just lucky today.
    it took years for me to find the solution.

  8. #8
    Join Date
    Apr 2005
    Beans
    849

    Re: [SOLVED] vim auto insert comments '#'

    Hmm,
    this had been nagging me for years.


    I wonder why this isn't default
    Running 8.10 on a lenovo 3000 n200!
    Fingerprint reader doesn't work.

  9. #9
    Join Date
    Dec 2010
    Beans
    1

    Post Re: [SOLVED] vim auto insert comments '#'

    to someone who will get this info useful..

    to resolve problem with inserting some text/code in vim with comments you can just add in your .vimrc file this line:
    Code:
    set pastetoggle=
    that will make `set paste` on pasting and `set nopaste` when it's done..

    p.s. sorry for necroposting

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •