LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   vim - auto comment (https://www.linuxquestions.org/questions/linux-general-1/vim-auto-comment-696916/)

baddah 01-13-2009 01:22 AM

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

angel115 01-13-2009 05:21 AM

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

chrism01 01-13-2009 06:03 AM

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.
:)

baddah 01-14-2009 07:50 AM

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

Beet1ejuice 01-26-2009 06:07 PM

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


All times are GMT -5. The time now is 11:19 AM.