2013-03-19 33 views
6

Chcę wkleić serię linii ze strony internetowej lub okna vim do innego vim oknie użyłem myszki do kopiowania i wklejania oryginał jest:teksty zniekształcone po wklejeniu na vim

// Calculate the sum           // 
    sum = 0; 
    while (len > 1) 
    { 
      sum += *buf++; 
      if (sum & 0x80000000) 
        sum = (sum & 0xFFFF) + (sum >> 16); 
      len -= 2; 
    } 

    if (len & 1) 
      // Add the padding if the packet lenght is odd   // 
      sum += *((uint8_t *)buf); 

po ich wklejeniu na innym vim linie te stają się następujące:

 // Calculate the sum           // 
    //   sum = 0; 
    //     while (len > 1) 
    //       { 
    //            sum += *buf++; 
    //                if (sum & 0x80000000) 
    //                      sum = (sum & 0xFFFF) + (sum >> 16); 
    //                          len -= 2; 
    //                             } 
    // 
    //                               if (len & 1) 
    //                                   // Add the padding if the packet lenght is odd   // 
    //                                       sum += *((uint8_t *)buf); 
    // 
    //                                          // Add the pseudo-header  

dlaczego tak się dzieje? i jak wykonać wklejanie zgodnie z oczekiwaniami? dzięki!

+4

'zestaw wklej', a następnie wklej. – Kent

+0

@kent: To robi. Powinieneś dodać to jako własną odpowiedź. –

+0

OK, działa to jak czar !! – user138126

Odpowiedz

7

ok, dodam jedną odpowiedź.

należy rozważyć set paste przed wklejeniem (specjalnie dla kodów z wcięciami). zauważ, że opcja paste może mieć "efekty uboczne". przeczytaj pomoc na ten temat.

Lepsze ustawienie wklej z powrotem do false po wklejeniu. byłoby wygodnie zamapować klucz, aby włączyć/wyłączyć opcję wklejania, jeśli często wklejasz. :)

+1

+1 ... Zrobiłem skrót do przełączania go, ponieważ przez większość czasu nie jest to, co chcę, ale kiedy nadejdzie czas, to dwa kluczowe uderzenia, aby uzyskać zachowanie. – 0xC0000022L

+0

jak to wyłączyć? – user138126

+3

@ user138126: with ': set nopaste' –

2

Robi to za Ciebie albo automatyczne wcięcie, albo inteligentne wcięcie. Zrób to przed wklejeniem:

: set noai 
: set nosi 

A następnie wklej. powinien wkleić ok. Kiedy skończysz wklejanie, należy:

:set ai 
:set si 

ai jest skrótem autoindent.

si jest skrótem od smartindent.


Po komentarzu Kenta na pytanie możesz to zrobić również pod numerem :set paste. Oto wyjaśnienie, dlaczego z oficjalnej pomocy:

     *'paste'* *'nopaste'* 
'paste'   boolean (default off) 
      global 
      {not in Vi} 
    Put Vim in Paste mode. This is useful if you want to cut or copy 
    some text from one window and paste it in Vim. This will avoid 
    unexpected effects. 
    Setting this option is useful when using Vim in a terminal, where Vim 
    cannot distinguish between typed text and pasted text. In the GUI, Vim 
    knows about pasting and will mostly do the right thing without 'paste' 
    being set. The same is true for a terminal where Vim handles the 
    mouse clicks itself. 
    This option is reset when starting the GUI. Thus if you set it in 
    your .vimrc it will work in a terminal, but not in the GUI. Setting 
    'paste' in the GUI has side effects: e.g., the Paste toolbar button 
    will no longer work in Insert mode, because it uses a mapping. 
    When the 'paste' option is switched on (also when it was already on): 
     - mapping in Insert mode and Command-line mode is disabled 
     - abbreviations are disabled 
     - 'textwidth' is set to 0 
     - 'wrapmargin' is set to 0 
     - 'autoindent' is reset 
     - 'smartindent' is reset 
     - 'softtabstop' is set to 0 
     - 'revins' is reset 
     - 'ruler' is reset 
     - 'showmatch' is reset 
     - 'formatoptions' is used like it is empty 
    These options keep their value, but their effect is disabled: 
     - 'lisp' 
     - 'indentexpr' 
     - 'cindent' 
    NOTE: When you start editing another file while the 'paste' option is 
    on, settings from the modelines or autocommands may change the 
    settings again, causing trouble when pasting text. You might want to 
    set the 'paste' option again. 
    When the 'paste' option is reset the mentioned options are restored to 
    the value before the moment 'paste' was switched from off to on. 
    Resetting 'paste' before ever setting it does not have any effect. 
    Since mapping doesn't work while 'paste' is active, you need to use 
    the 'pastetoggle' option to toggle the 'paste' option with some key. 
+0

Próbowałem, jak ci powiedziano, problem nadal istnieje – user138126

1

Trzeba albo autoindent lub smartindent włączony. Aby je wyłączyć, usuń bez, aby je ponownie włączyć.

Powiązane problemy