7

Webページまたはvimウィンドウから別の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);

それらを別の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);
     //
     //                                                                                                                                                                     // Add the pseudo-header     

なぜこれが起こるのですか?予想通りに貼り付ける方法は?ありがとう!

4

3 に答える 3

9

わかりました、1つの答えを追加します。

貼り付ける前に検討set pasteしてください(特にインデントのあるコードの場合)。pasteこのオプションには「副作用」がある可能性があることに注意してください。そのためのヘルプを読んでください。

貼り付け後に貼り付けをfalseに戻すことをお勧めします。たくさん貼り付ける場合は、キーをマップして貼り付けオプションを有効/無効にするのが便利です。:)

于 2013-03-19T15:32:20.610 に答える
2

自動インデントまたはスマートインデントのいずれかがこれを実行します。貼り付ける前にこれを行ってください:

: set noai
: set nosi

そして貼り付けます。貼り付けても問題ありません。貼り付けが完了したら、次の手順を実行します。

:set ai
:set si

aiの略ですautoindent

siの略ですsmartindent


質問に対するケントのコメントに続いて、これをで行うこともできます:set paste。公式ヘルプからの理由の説明は次のとおりです。

                        *'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.
于 2013-03-19T15:25:49.813 に答える
1

またはスイッチを入れましたautoindentsmartindentそれらをオフにするには、

:set noai
:set nosi

それらをオンに戻すには、noを削除します。

于 2013-03-19T15:26:22.810 に答える