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>
7
  • 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 Jun 5, 2016 at 17:28
  • 4
    Yes you are wrong.
    – romainl
    Jun 5, 2016 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. Jun 5, 2016 at 18:11
  • 3
    Have a look at answer to this question: stackoverflow.com/questions/12213597/… . Built in Profiling always helped me to find the source of slowness in vim.
    – dNitro
    Jun 5, 2016 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. Jun 5, 2016 at 20:50

4 Answers 4

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.

6
  • 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 6, 2016 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. Jun 6, 2016 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 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 7, 2016 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 8, 2016 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 8, 2016 at 14:23
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.

4
  • 3
    could you provide more info about what this config does? Apr 22, 2017 at 23:45
  • 2
    You have a pretty good explain here: vi.stackexchange.com/questions/10249/…. 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, 2017 at 7: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 8, 2019 at 16:07
  • Thanks! Amazing. Now what's the secret to killing lag on chrome... :-)
    – zeusstl
    Jul 10, 2020 at 4: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()
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.