Tips for using vim over a slow connection?

2019-01-22 19:39发布

I'm using vim over a slow connection and it is a little painful. Is there anything I can do in vim to alleviate the pain?

标签: vim ssh vi
15条回答
孤傲高冷的网名
2楼-- · 2019-01-22 20:10

Few things to look into.

  • :he lazyredraw
  • :he ttyfast
  • :he nofsync
查看更多
太酷不给撩
3楼-- · 2019-01-22 20:14

The trick to working out what is causing the performance issues is to disable everything in vim, and then slowly introduce parts back in until you work out what is causing your performance issues.

I.e. delete (or move or rename) the following files/directories to quickly disable:

  • C:\Program Files\Vim\_vimrc
  • C:\Program Files\Vim\vimfiles
  • C:\Program Files\Vim\vim72\autoload
  • C:\Program Files\Vim\vim72\plugin

On Unix/Linux/OS X, these files should exist at:

  • ~/.vim/plugin
  • ~/.vim/autoload

If you can't find it in either of those places, then the :version command can show you which .vimrc files are being used. The plugin directory should be close by.


Start up vim - it will probably look weird without any settings. But it should perform acceptably now.

Then start introducing bits back in piece-by-piece until you find out what is causing the problem.

I did this and found the following stock plugins cause problems when using Vim over a VPN:

  • matchparen.vim
  • netrwPlugin.vim
  • vimballPlugin.vim

Most of the problems these plugins introduce is adding new autocmds (like during BufEnter), which do not perform well when editing remote files. You may find you also have your own plugins which will may be causing performance problems.

I then wrote a function to delete these autocmds for when working remotely:

let g:NotEditingRemotely = 1

function! s:ToggleRemoteFile()
    if exists("g:NotEditingRemotely")
        " Disable the matchparen.vim plugin"
        :NoMatchParen

        " Turn off detection of the type of file"
        filetype off

        " Disable the netrwPlugin.vim"
        au! Network
        au! FileExplorer

        " Remove tag scanning (t) and included file scanning (i)"
        set complete=.,w,b,u,k

        " Remove these autocommands which were added by vimBallPlugin.vim"
        au! BufEnter *.vba
        au! BufEnter *.vba.gz
        au! BufEnter *.vba.bz2
        au! BufEnter *.vba.zip

        unlet g:NotEditingRemotely

        :echo 'Remote Edit mode turned on'
    else
        " Enable the matchparen.vim plugin"
        :DoMatchParen

        " Turn on detection of files"
        filetype on

        " Add back in tag scanning (t) and included file scanning (i)"
        set complete=.,w,b,u,t,i,k

        let g:NotEditingRemotely = 1

        :echo 'Remote Edit mode turned off'
    endif
endfunction

command! -nargs=0 ToggleRemoteFile call s:ToggleRemoteFile()
noremap <F6> :ToggleRemoteFile<CR>

Put in your vimrc and see if it makes a difference.

查看更多
一纸荒年 Trace。
4楼-- · 2019-01-22 20:15

Over a slow connection, it's painful to move the cursor character by character, because you don't get immediate visual feedback, so you always end up moving too much or too little.

So what's most effective to me is to use smarter movements and commands, like:

  • fx -- jump to next letter x
  • 5w -- move 5 words forward
  • ci( -- replace what's between the parentheses
  • dap -- delete current paragraph
  • and a long etcetera.

I miss those commands all the time when typing in browser's textareas, like now :)

查看更多
走好不送
5楼-- · 2019-01-22 20:18

vi was created to use over 300 baud modem, that is why there is all those funny and strange (and short) command to move and navigate. Learn them...

Play with things like

 :10 -> jump to line 10
 7j -> move 7lines down

And since my keyboard has a little physical dot at the keys f and j, I use the dot on key j to easy find the vim navigation "hjkl".

But the best thing is to never ever scroll at all, search to move is a life saver. When you search your pointer ends up right at the thing you search for, meaning that those slow navigations is not needed. This is really useful if you end up editing really big files over ssh...

查看更多
forever°为你锁心
6楼-- · 2019-01-22 20:22

Are you on SSH? If so, use SSH compression. ssh -C should help quite a bit.

查看更多
Explosion°爆炸
7楼-- · 2019-01-22 20:24

Vim was designed for slow connections. Are you taking advantage of the motion commands and line selection operations? My suggestion is to learn the non-cursor key parts of Vim really well.

查看更多
登录 后发表回答