Why is pasting a long one-liner very slow in Vim's insert mode?

后端 未结 9 1114
别那么骄傲
别那么骄傲 2020-12-23 14:35

My Macbook was stuck yesterday, when I tried to paste 1200 lines of 80 characters to Vim. It was much faster to download the file, and not to paste the text.

I have

相关标签:
9条回答
  • 2020-12-23 15:03

    If you use Apple Terminal try an other terminal, like iTerm. Sometimes, the "build-in" terminal is not really reactive for common task. Don't know why...

    0 讨论(0)
  • 2020-12-23 15:07

    That is "normal". It's slow because redrawing the text thousands of times is slow.

    As you paste the long line in, it's constantly update the display (because of how vim deals with text, or how the terminal is handing vim text, I guess).

    I tried pasting the text in vim (using iTerm) and it has the same issue, it takes a while to paste. I tried :set paste and :set nowrap and still as slow. Pasting the line straight into a terminal is equally slow

    With the dpaste link you mention, there is a plain-text link, which you could just wget and edit:

    curl http://dpaste.com/115362/plain/ | vim -
    
    0 讨论(0)
  • 2020-12-23 15:11

    if you :syntax off you can sometimes improve an in place paste of a long single line file. An example would be a machine generated xml file.

    you can probably disable vim's redraw whilst pasting as well, look at :he redraw , but it's always worth using command line stuff as If you are repeating the procedure or similar you can always automate it with a script / vim macro

    0 讨论(0)
  • 2020-12-23 15:14

    I don't know if this is a Mac issue or something else, but I have no problems whatsoever with pasting that amount of text in Vim. I have tried on Windows and Linux, and haven't seen any problems.

    I have successfully edited files of several hundred megs (log files) in Vim (loading is slow, but once the text is read everything is pretty snappy).

    0 讨论(0)
  • 2020-12-23 15:17

    If you paste it into a terminal window, Vim thinks you're typing it out by hand, and it will try and update the display as you go. You can access your clipboard (on OS X) using the pbpaste and pbcopy commands, so you can just do this in Vim:

    :read !pbpaste
    

    or in a shell:

    bash$ pbpaste | vim -
    

    If you were using GUI Vim, you would use the "* register to paste (this is what the context menu does):

    "*P   <- in normal mode
    

    Pasting into the terminal window is usually a bad idea, try and use pbpaste where you can.

    0 讨论(0)
  • 2020-12-23 15:18

    But if it's on the web, you should have tried:

    :e http://link/to/file 
    

    Then if necessary save it as a local file.

    And if it's slow because of the redrawing, look at this option:

                *'lazyredraw'* *'lz'* *'nolazyredraw'* *'nolz'*
    'lazyredraw' 'lz'   boolean (default off)
                global
                {not in Vi}
        When this option is set, the screen will not be redrawn while
        executing macros, registers and other commands that have not been
        typed.  Also, updating the window title is postponed.  To force an
        update use |:redraw|.
    

    And if it's a local file, then pasting is not necessary: try

    :read file 
    

    instead.

    0 讨论(0)
提交回复
热议问题