LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 01-13-2009, 02:22 AM   #1
baddah
Member
 
Registered: Feb 2006
Location: Cape Town,South Africa
Distribution: Fedora Core 8
Posts: 183

Rep: Reputation: 30
vim - auto comment


Hi,

I am copying some code from a perl source file into a new one. What happens each time is that if the code i'm copying from contains a comment (#) the vim i am copying to adds a # to all subsequent lines!

So if a am copying

Code:
#this is a comment
print ("Hallo");
print ("World");
it comes out as

Code:
#this is a comment
#print ("Hallo");
#print ("World");

I'd like to switch this off,but i have not been able to find the command yet. Any one know what this is so i can switch it off.

Thans
 
Old 01-13-2009, 06:21 AM   #2
angel115
Member
 
Registered: Jul 2005
Location: France / Ireland
Distribution: Debian mainly, and Ubuntu
Posts: 494

Rep: Reputation: 75
Hi Baddah,

Can you please explain me how do you do to copy the code? So I can try to reproduce, and maybe find a solution.

Best regards,
Angel
 
Old 01-13-2009, 07:03 AM   #3
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
I was having the same prob and managed to fix it. Its when you've got 2 xterm/vim sessions open and you copy/paste with the mouse from one to the other.
If the src window/file had a comment at the end of the line (or as the whole line) as in Perl/shell ie '#', then the target ended up with '#' on each line and the next newline, as per his example.
Not exactly sure how I fixed it ( ), but :

1. mv /etc/vimrc /etc/vimrc_bak
2. mv /etc/virc /etc/virc_bak
3. here's my new/current $HOME/.vimrc

Code:
" Use Vim settings, rather then Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible

" allow backspacing over everything in insert mode
set backspace=indent,eol,start

" Only do this part when compiled with support for autocommands.
if has("autocmd")
  " When editing a file, always jump to the last known cursor position.
  " Don't do it when the position is invalid or when inside an event handler
  " (happens when dropping a file on gvim).
  autocmd BufReadPost *
    \ if line("'\"") > 0 && line("'\"") <= line("$") |
    \   exe "normal g`\"" |
    \ endif
endif " has("autocmd")


if &term =~ "xterm"
        if has("terminfo")
       set t_Co=8
       set t_Sf=[3%p1%dm
       set t_Sb=[4%p1%dm
   else
       set t_Co=8
       set t_Sf=[3%dm
       set t_Sb=[4%dm
   endif
endif

syntax enable
colorscheme delek
set noshowmatch
set noautoindent
set tabstop=4
set shiftwidth=4
set softtabstop=4
set ruler
set history=100

" stop auto matching parentheses, but shift-% still works
let loaded_matchparen = 1
Hope it works for you. You may need to logout (completely) and in again to avoid any caching effects.
 
Old 01-14-2009, 08:50 AM   #4
baddah
Member
 
Registered: Feb 2006
Location: Cape Town,South Africa
Distribution: Fedora Core 8
Posts: 183

Original Poster
Rep: Reputation: 30
Quote:
I was having the same prob and managed to fix it. Its when you've got 2 xterm/vim sessions open and you copy/paste with the mouse from one to the other.
If the src window/file had a comment at the end of the line (or as the whole line) as in Perl/shell ie '#', then the target ended up with '#' on each line and the next newline, as per his example.
This is exactly the problem yes. I remembered i found a coomand last time that i used to switch it off, but i can't rememeber the code. I'll try your .vimrc file i suppose, but i'm sure there was a command to switch it off and on.

Thanks
 
Old 01-26-2009, 07:07 PM   #5
Beet1ejuice
LQ Newbie
 
Registered: Jan 2009
Location: Sweden
Distribution: Fedora
Posts: 1

Rep: Reputation: 0
Hi Baddah,

You're probably looking for this command
:set paste

Or you can add this line to your ~/.vimrc (which will allow you to toggle between paste and nopaste with Ctrl+P)
nm <C-P> :se invpaste paste?<CR>

Br, Beetle
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Disabling Auto-Formatting in vim? Sir Meowdengalf Linux - Software 1 10-24-2008 03:16 PM
vim: auto-completion in ex chexmix Solaris / OpenSolaris 1 08-28-2008 03:26 PM
comment multiple lines in vim Furlinastis Slackware 9 12-11-2007 02:01 PM
vim auto indenting? kryptobs2000 Linux - Software 2 10-20-2007 04:11 PM
LXer: Cream for Vim - Making Vim more user friendly LXer Syndicated Linux News 0 06-18-2006 12:54 AM


All times are GMT -5. The time now is 05:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration