6

I am a beginning vim user and I am a little confused. It looks like Vim is slower than Geany. And it is a very noticeable difference. When I hold any key in Geany it prints it without any lag (llllllll for example). In Vim it is slow and jumping. Autocomplete in vim is horrible in comparison to Geany. I thought Vim is as fast as light. It looks like it isn't. Is there any advice to change that, make vim faster?

This is my _vimrc file:

" This must be first, because it changes other options as side effect
set nocompatible

" Use pathogen to easily modify the runtime path to include all
" plugins under the ~/.vim/bundle directory
call pathogen#helptags()
call pathogen#infect()

" change the mapleader from \ to ,
let mapleader=","

" Quickly edit/reload the vimrc file
nmap <silent> <leader>ev :e $MYVIMRC<CR>
nmap <silent> <leader>sv :so $MYVIMRC<CR>

set hidden
set nowrap        " don't wrap lines
set tabstop=4     " a tab is four spaces
set backspace=indent,eol,start
                " allow backspacing over everything in insert mode
set autoindent    " always set autoindenting on
set copyindent    " copy the previous indentation on autoindenting
set number        " always show line numbers
set shiftwidth=4  " number of spaces to use for autoindenting
set shiftround    " use multiple of shiftwidth when indenting with '<' and '>'
set showmatch     " set show matching parenthesis
set ignorecase    " ignore case when searching
set smartcase     " ignore case if search pattern is all lowercase,
                "    case-sensitive otherwise
set smarttab      " insert tabs on the start of a line according to
                "    shiftwidth, not tabstop
set hlsearch      " highlight search terms
set incsearch     " show search matches as you type

set history=1000         " remember more commands and search history
set undolevels=1000      " use many muchos levels of undo
set wildignore=*.swp,*.bak,*.pyc,*.class
set title                " change the terminal's title
set visualbell           " don't beep
set noerrorbells         " don't beep

set nobackup
set noswapfile

filetype plugin indent on

autocmd filetype python set expandtab

if &t_Co >= 256 || has("gui_running")
    colorscheme badwolf
endif

if &t_Co > 2 || has("gui_running")
    " switch syntax highlighting on, when the terminal has colors
    syntax on
endif

" Vim can highlight whitespaces for you in a convenient way:
set list
set listchars=tab:>.,trail:.,extends:#,nbsp:.

set pastetoggle=<F2>

set mouse=a " Enable mouse

set encoding=utf-8
set langmenu=en_US
let $LANG = 'en_US'
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim

set autochdir " working directory is always the same as the file you are       editing 
noremap <F5> :w !python %<CR>
inoremap <F5> <ESC>:w !python %<CR>

nmap <leader>t :NERDTree<CR>
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") &&     b:NERDTreeType == "primary") | q | endif

set guifont=Hack:h10:cDEFAULT
let g:Powerline_symbols = 'fancy'
set laststatus=2

python from powerline.vim import setup as powerline_setup
python powerline_setup()
python del powerline_setup

filetype plugin on
set omnifunc=syntaxcomplete#Complete
au CompleteDone * pclose
set completeopt=longest,menuone,preview

set guioptions-=T
set nofoldenable    " disable folding

nmap <silent> ,/ :nohlsearch<CR>
jundymek
  • 1,013
  • 4
  • 18
  • 40
  • 4
    It's properly a problem with your vimrc file. First try to run it without, and see if it makes a difference: `vim -u NONE` – Andreas Louv Jun 05 '16 at 17:28
  • Yes it makes a difference but it is "clear" Vim vs GVim with some plugins. Without plugins vim is very simple editor in my opinion. Power of Vim is it customization. Am i wrong? – jundymek Jun 05 '16 at 17:57
  • 4
    Yes you are wrong. – romainl Jun 05 '16 at 18:10
  • 1
    You are not wrong - about customization, what I'm was suggesting is that you got some gibberish in your vimrc which cases the hang up. – Andreas Louv Jun 05 '16 at 18:11
  • Should I modify my vimrc file? Any tips? I took it mostly from: http://nvie.com/posts/how-i-boosted-my-vim/ . – jundymek Jun 05 '16 at 18:20
  • 3
    Have a look at answer to this question: http://stackoverflow.com/questions/12213597/how-to-see-which-plugins-are-making-vim-slow . Built in Profiling always helped me to find the source of slowness in vim. – dNitro Jun 05 '16 at 18:42
  • 1
    First thing that jumps at me: why are you running `pathogen#helptags()` every time you start Vim? You only need to run it once, after installing or upgrading plugins. As for what else makes your Vim slow; you probably have a zillion plugins that kill it by a thousand cuts. Disable the ones you aren't actually using, then run profiling, as suggested above. – Sato Katsura Jun 05 '16 at 20:50

4 Answers4

15

It could be a lot of things, not necessarily Vim's fault. Actually it's unlikely to be vim's fault.

  1. First, get a feel for how fast Vim can be: run with vim -u NONE and comment out everything in your .vimrc - then do the single thing that seems slow.

  2. Run without the -u NONE and compare. It should be just as fast, or some plugin is autoloaded and is causing problems. If so, try and temporarily move files away from the ~/.vim/bundle directory.

  3. Next, uncomment half of your .vimrc and check if it causes the slowness or not. Keep commenting/uncommenting until you find the exact line.

  4. Google the line that caused the slowness and find out if there are alternatives.

I'm guessing you could be doing an expensive operation with every scroll, such as checking the file syntax.

It's best to hunt down the slowness step by step.

Another issue may be slow terminal and/or drivers (so compare Vim with GVim). If you have a slow terminal with fancy fonts, transparency, small font and big screen size, terminals can be very, very, VERY slow.

Cezary Baginski
  • 2,077
  • 15
  • 14
  • I am trying to find 'bad' plugin but I noticed something strange. When I press any key for long time(llllllllllllllll) just after my import statements, vim prints it without any problem. When I do this in the middle of my program vim slows down and start 'jumping'. I can't find what is going on. – jundymek Jun 06 '16 at 22:05
  • 1
    Seems like syntax coloring. Try ":syntax off". Are your source files very big? What OS? Which version of Vim? Are you using python.vim? If so, which version? Built in? From GitHub? Are you using Tmux or screen? Do you have python support compiled in? Which plugins are you using (list files/dirs in ~/.vim/bundle if you can)? The more answers you can give, the faster you'll get good advice. – Cezary Baginski Jun 06 '16 at 22:54
  • Syntax off doesn't resolve a problem. My test file is rather small - about 350 lines. I am using Windows 10, VIM 7.4. I have python.vim file in my Vim\vim74\syntax, Vim\vim74\ftplugin and Vim\vim74\indent catalogs. I am not using Tmux or screen. I have those plugins in my .vim/bundle directory: command-t, indentpython.vim, vim-flake8. I deleted powerline because I noticed it was slowing down my VIM a little. I installed https://github.com/amix/vimrc for trying and it works great. I think that problem in my vimrc config is autocomplete feature (when typing 'dot' i have to wait second or two). – jundymek Jun 07 '16 at 21:27
  • 1
    @Luk You mention that it is fine just after `import` statements (assuming Python), but then begins to slow down. The most likely suspect then is either your indentpython script (which is probably trying to auto-indent) or flake8 (which runs, IIRC, three syntax checkers against the code). Either or both of them may be slowing things down by trying to do things in realtime. I suggest disabling both. If things are fast again, then re-enable each of them separately and see if only one is slowing it down - and then you have caught the culprit. – Dan Lowe Jun 08 '16 at 14:17
  • 1
    @Luk and looking at your vimrc again, I would also take a look at the autocompletion stuff near the bottom (`omnifunc` to `completeopt`...). Autocomplete in this case would be parsing all of your code and imported libraries to match class and symbol names, and depending on the situation, this could be quite slow. – Dan Lowe Jun 08 '16 at 14:23
  • Finally I uninstalled my Vim, delete all filest and starded from beggining. Now it is fast but without some plugins which I would like to have. I'll try to add extensions wisely. – jundymek Jun 08 '16 at 17:35
6

If you use vim in terminal like me (and not GVim), I just found that, try, and it seems pretty good :

add this in your ~/.vimrc :

set timeoutlen=1000

set ttimeoutlen=0

and this (even more important) in your ~/.screenrc :

maptimeout 0

Since I did that, everything is better.

Community
  • 1
  • 1
Zero Xan
  • 113
  • 1
  • 6
  • 3
    could you provide more info about what this config does? – Gordon Freeman Apr 22 '17 at 23:45
  • 2
    You have a pretty good explain here: https://vi.stackexchange.com/questions/10249/what-is-the-difference-between-mapped-key-sequences-and-key-codes-timeoutl#answer-10284. Short story long, these timeout are constant (in millisecond) for stopping vim to wait if you are in sequence of keycode. Technicaly (that's what i'm understanding) maptimeout is quite the same directly setted on you GNU screen. For me 0 milliseconds are ok, but i can understand that 10 should be better in order to keep having a moment to continue some sequences. – Zero Xan Apr 24 '17 at 07:26
  • Is this supposed to say `~/screenrc`? You have 3 `e`'s in the filename, just wanted to make sure that was a typo :P – jenkizenki Oct 08 '19 at 16:07
  • Thanks! Amazing. Now what's the secret to killing lag on chrome... :-) – zeusstl Jul 10 '20 at 04:09
0

My vim started to fly after I added the following config to my vimrc, this is extremely useful when you keep vim running all day/week long editing a lot of different files with opening and closing them often.

function! CloseHiddenBuffers()
    " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    " close any buffers hidden
    " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    let open_buffers = []

    for i in range(tabpagenr('$'))
        call extend(open_buffers, tabpagebuflist(i + 1))
    endfor

    for num in range(1, bufnr("$") + 1)
        if buflisted(num) && index(open_buffers, num) == -1
            exec "bdelete ".num
        endif
    endfor
endfunction

au BufEnter * call CloseHiddenBuffers()
j5shi
  • 797
  • 1
  • 8
  • 21
0

I had a similar problem where pasting paragraphs of text or just typing at a typical speed would hang vim.

You could troubleshoot your .vimrc, and if you are, take a look at this question to see which plugins are slow. You could also skip the troubleshooting and use neovim, which is fully compatible with vim and asynchronous.

My issues with input lag disappeared once I started using it. It uses an async library libuv, which is the same library powering node. I'm using the same .vimrc as with vim (copied to ~/.config/nvim/init.vim), so it's not a matter of different plugins. I also see this responsiveness improvement on both Ubuntu 20.04 and Macos 10.14.

I'm posting this answer because I wish it had existed when I last read this question.

Ross Jacobs
  • 2,962
  • 1
  • 17
  • 27