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>
It could be a lot of things, not necessarily Vim's fault. Actually it's unlikely to be vim's fault.
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.
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.
Next, uncomment half of your .vimrc and check if it causes the slowness or not. Keep commenting/uncommenting until you find the exact line.
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.
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.
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()
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.
Related
I recently ran into this answer when trying to remove highlighting from Vim, after pressing the # key accidentally. I followed the user's code and entered this at the bottom of my .vimrc file:
" <Ctrl-l> redraws the screen and removes any search highlighting.
nnoremap <silent> <C-l> :nohl<CR><C-l>
I exited Vim, and ran source vimrc
And it returned the following error:
Unmatched ".
So I take this to mean that double quotes need a corresponding fullstop afterwards at the end of the line, as the user has done. But I'm looking through my .vimrc and none of the "s have matching fullstops. Indeed, when I deleted the line I inserted and tried to run source vimrc, it still returned an Unmatched ". error. Here's an example:
" main
syntax enable
set encoding=utf-8
set tabstop=4
set shiftwidth=4
set softtabstop=4
set expandtab
set smarttab
set number
set showcmd
set bs=2 " use backspace in INSERT mode
"set nomodeline " turn off modeline parsing
And another:
" split nav
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>
My problem here is that I don't understand the function of " here, and haven't been able to find any information from Googling or searching previous SO questions. It seems to be used like a comment, but I thought that # was used for comments. I'm a complete Linux beginner - I don't know what the correct syntax is to fix the dotfile, if it needs fixing.
So my question is twofold:
How should I fix this? Should I go through the whole dotfile and add fullstops at the end of each line starting with a "?
What is the function of " anyway?
I'm using TCSH, I believe.
EDIT: Here's the dotfile:
" main
syntax enable
set encoding=utf-8
set tabstop=4
set shiftwidth=4
set softtabstop=4
set expandtab
set smarttab
set number
set showcmd
set bs=2 " use backspace in INSERT mode
"set nomodeline " turn off modeline parsing
set cursorline
set autoindent
filetype indent on
filetype on
filetype plugin on
set wildmenu " autocomplete menu
set lazyredraw " redraw only when necessary
set showmatch " highlight matching parentheses
set smartcase
set incsearch " search as char entered
set hlsearch " highlight search matches
nnoremap #<space> :nohlsearch<CR> " #<space> turn off search hl
set foldenable " enable folding
set foldlevelstart=10 " open most folds be default
set foldnestmax=10 " 10 nested fold max
nnoremap <space> za " space open/closes fold
set foldmethod=indent " fold based on indent level
nnoremap j gj " move down visually
nnoremap k gk " move up visually
nnoremap gV `[v`] " highlight latest - ins mode
" status line that shows more information than the default one
" set statusline=%F%m%r%h%w\ [FMT=%{&ff}]\ [T=%Y]\ [HEX=\%02.2B]\ [POS=%04l,%04v\ (%p%%)]\ [lines=%L]
" set laststatus=2
" split
set splitbelow
set splitright
" split nav
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>
You seem to confuse shell dot files with your .vimrc. Shells source shell dotfiles, while vim sources a vimrc. Shells don't understand vimrc notation, in particular, " introduces a comment for vim, while it starts a double quoted word in the shell. The shell expects double quotes to come in pairs, that's why you get the Unmatched ".
In other words, don't tell the shell to source .vimrc, simply start vim and it will automagically source the $HOME/.vimrc for you, because that feature is built into vim.
If you change .vimrc from within vim (and why would you use another editor?) then you can source it without exiting vim by typing :source ~/.vimrc and make the changes take effect.
In vim, frequently when I perform a ':help ' command, I get an error. Here's an error I see when I perform ':help tags' for example:
"tagsrch.txt.gz" [readonly][noeol] 42L, 11288C
Error detected while processing function gzip#read:
line 51:
E303: Unable to open swap file for "/usr/share/vim/vim74/doc/tagsrch.txt.gz", recovery impossible
41 fewer lines
Press ENTER or type command to continue
When I press enter, the help comes up as desired, but this is still a nuisance. What have I done wrong? My google-foo is apparently too weak for this because I don't see other people complaining about this.
Is this because I have this set for my swap directory?
set directory=~/.vim/swap,.
Let me know if it would be helpful to paste my entire vimrc. I'm on rhel7 with vim 7.4, in case it's helpful.
Here's my ~/.vimrc:
" vim:softtabstop=4:shiftwidth=4:et
" Tab preferences
set shiftwidth=4
set softtabstop=4
set autoindent
set expandtab
execute pathogen#infect()
" Where to store swap files. By default, they will go into ~/.vim/swap, but
" if that doesn't work, they will go in cwd.
set directory=~/.vim/swap,.
filetype plugin indent on " enables filetype indent specific plugins
" Instructions on how to tab complete filenames.
" set wildmode=longest,list,full
set wildmode=longest,list
set wildmenu
" In case there are vim modelines at the top of the file, as there
" is with this one.
set modeline
" Always show the status line.
set laststatus=2
" Look for a tags file.
set tags=./tags,tags;
" Also search for .git/tags files.
set tags^=./.git/tags,*/.git/tags;~
" Make Ctrl-] show the list of options by default.
nnoremap <C-]> g<C-]>
nnoremap <C-w><C-]> <C-w>g<C-]>
" Colors
" Have syntax highlighting in terminals which can display colours:
if has('syntax') && (&t_Co > 2)
syntax on
else
syntax off
endif
set background=dark
set hlsearch
set incsearch
" I so often type teh instead of the.
abbreviate teh the
" To help vim deal with pasting text
:map <F9> :set invpaste <CR>
set pt=<F9>
" Toggle vim's spell checker with <F5>
:map <F5> :setlocal spell! spelllang=en_us<cr>
" Shortcuts for c code.
map! ,bc /* */^[hhi
map! ,bz #if 0^M#endif /* 0 */^[O
" Ignore whitespace when diffing files.
map ,iw :set diffopt+=iwhite<CR>
set path^=/home/bneradt/work/trafficserver/**
In my situation / partition is full. Cleaned it and it works now.
I can't get the horizontal split to work. Ctrl+enter does nothing, Ctrl+S does nothing.
I've been googeling this for a bit and the only solutions I've found so far are related to OSX.
On both Arch Linux and Ubuntu, having same problem (but also the same config).
I'm not using Janus or anything like it, just a very basic config
set t_Co=256
set tabstop=2
set expandtab
set shiftwidth=2
set fileencoding=utf-8
set encoding=utf-8
set termencoding=utf-8
set showcmd
filetype plugin indent on
"color molokai
syntax enable
autocmd! BufNewFile * silent! 0r ~/.vim/skel/tmpl.%:e
set laststatus=2 " Always show the statusline
set backspace=indent,eol,start " backspace through everything in insert mode
"" Searching
set hlsearch " highlight matches
set incsearch " incremental searching
set ignorecase " searches are case insensitive...
set smartcase " ... unless they contain at least one capital letter
call pathogen#infect()
colorscheme jellybeans
" use comma as <Leader> key instead of backslash
let mapleader=","
" Double <Leader> to switch between buffers
nnoremap <leader><leader> <c-^>
" double percentage sign in command mode is expanded
" to directory of current file - http://vimcasts.org/e/14
cnoremap %% <C-R>=expand('%:h').'/'<cr>
map <leader>f :CommandTFlush<cr>\|:CommandT<cr>
map <leader>F :CommandTFlush<cr>\|:CommandT %%<cr>
[~]$ ls .vim/bundle
rbenv:system
command-t jellybeans.vim snipmate-snippets tlib_vim vim-addon-mw-utils vim-powerline vim-snipmate
I was hoping someone would be able to shed some light on this, it's getting really frustrating.
Not entirely sure whats wrong but it have work occasionally, but not at all right now.
Pressing CTRL+S does nothing, shift+enter just opens it normally in the current buffer and ctrl+enter just hops down the search results list in Command-T.
In most terminals, Vim cannot distinguish between Enter and its combinations with Ctrl or Shift, unfortunately; these only work in GVIM.
The terminal's flow control commands may interfere with Ctrl-S and Ctrl-Q; this can be fixed (in the terminal, not in Vim!) with
stty start undef stop undef
in ~/.bashrc, ~/.zshrc, etc.
I looked around but haven't found an answer to this. I have a CentOS 6.2 server running with the same .vimrc as my CentOS 5.8 server, however when I hit enter in VIM on my 6.2 server, it adds the first character of the previous line if it's a certain character (% or # are the ones I've seen). This is what happens in VIM (The seconds lines are right after hitting enter, but without typing anything else):
# <enter>
#
% <enter>
%
Here's my .vimrc:
set autoindent
set smartindent
set tabstop=4
set shiftwidth=4
set showmatch
set number
imap jj <Esc> " Professor VIM says '87% of users prefer jj over esc', jj abrams disagrees
" Indenting *******************************************************************
set ai " Automatically set the indent of a new line (local to buffer)
set si " smartindent (local to buffer)
" Cursor highlights ***********************************************************
"set cursorline
"set cursorcolumn
" Set an orange cursor in insert mode, and a red cursor otherwise.
" Works at least for xterm and rxvt terminals.
" Does not work for gnome terminal, konsole, xfce4-terminal.
"if &term =~ "xterm\\|rxvt"
" :silent !echo -ne "\033]12;red\007"
" let &t_SI = "\033]12;orange\007"
" let &t_EI = "\033]12;red\007"
" autocmd VimLeave * :!echo -ne "\033]12;red\007"
"endif
" Searching *******************************************************************
set hlsearch " highlight search
set incsearch " Incremental search, search as you type
set ignorecase " Ignore case when searching
set smartcase " Ignore case when searching lowercase
" Colors **********************************************************************
"set t_Co=256 " 256 colors
set background=dark
syntax on " syntax highlighting
"colorscheme darkzen
Ran a diff against it and the one on my 5.8 server (where I don't have this problem) and there was no difference at all. Any idea why this may be happening?
It looks like automatic comment insertion.
Take a look at :help formatoptions and :set formatoptions. These are probably being set by file type.
Run verbose set formatoptions. You should get back a string that contains 'r', which Automatically inserts the current comment leader after hitting <Enter> in Insert mode. The verbose bit should point you at the file(likely a filetype plugin) who is the culprit.
I prevent vim from hijacking my formatoptions via the autocommand au FileType * set formatoptions=lq in my vimrc. Most of the options drive me absolutely crazy, although r and o are by far the worst.
I am currently using VIM in the terminal and have perfect syntax highlighting happening. But then when I try to use gvim no matter what type of file or how many times I type: ":syntax on" I don't get any syntax highlighting. Any ideas anyone?
Thank you.
Here is my .vimrc for those who are interested:
" Turn on pathogen for all plug-ins installed after 9/13/2010
call pathogen#helptags()
call pathogen#runtime_append_all_bundles()
" My color theme for vim
colors sorcerer
" Disable line wrapping for now
set nowrap
" Enable the mouse even when vi is used in the terminal
set mouse=a
" Since I use linux, I want this
let g:clipbrdDefaultReg = '+'
" This shows what you are typing as a command. I love this!
set showcmd
" Automatically cd into the directory that the file is in
autocmd BufEnter * execute "chdir ".escape(expand("%:p:h"), ' ')
"Fix Vim's regex...
nnoremap / /\v
vnoremap / /\v
" Gimme some breathing room at the bottom please...
set scrolloff=5
" makes vim usable with screen
set restorescreen
" Disable the arrow keys... helps the learning
map <up> <nop>
map <down> <nop>
map <left> <nop>
map <right> <nop>
imap <up> <nop>
imap <down> <nop>
imap <left> <nop>
imap <right> <nop>
"Kill error bells
set noerrorbells
set visualbell
set t_vb=
" Turn on spell check
" set spell
" Thesaurus!!
set thesaurus+=/usr/share/myspell/dicts/mthesaur.txt
" Some NERDTree love
let NERDTreeBookmarksFile=expand("$HOME/.vim/NERDTreeBookmarks")
let NERDTreeShowBookmarks=1
let NERDTreeQuitOnOpen=1
let NERDTreeHighlightCursorline=1
let NERDTreeShowFiles=1
let NERDTreeShowHidden=1
" Make swapping windows easier...
map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l
" Allow for buffers to be hidden so that they need not be closed to go to
" another file
set hidden
" Turn on incremental search
set incsearch
set smartcase
" Long history is long
set history=1000
set undolevels=1000
" No need for a vi backup file
set nobackup
" Colors!!
set t_Co=256
" Compatibility
set nocompatible
set formatprg=par
" Syntastic!!
let g:syntastic_enable_signs=1
let g:syntastic_auto_loclist=1
let g:syntastic_quiet_warnings=0
" For soft wrapping text
command! -nargs=* Wrap set wrap linebreak nolist
set showbreak=…
" Sandro spacing preferences here
set number
set expandtab
set autoindent
set smartindent
set softtabstop=4
set shiftwidth=4
set shiftround
" Sandro key mapping here
map <F2> :NERDTreeToggle<CR>
"allow backspacing over everything in insert mode
set backspace=indent,eol,start
set showmode "show current mode down the bottom
"Setting the status line...
set statusline=%f "tail of the filename
"display a warning if the file format isn't Unix
set statusline+=%#warningmsg#
set statusline+=%{&ff!='unix'?'['.&ff.']':''}
set statusline+=%*
"display a warning if file encoding isn't UTf-8
set statusline+=%#warningmsg#
set statusline+=%{(&fenc!='utf-8'&&&fenc!='')?'['.&fenc.']':''}
set statusline+=%*
set statusline+=%h "help file flag
set statusline+=%y "filetype
set statusline+=%r "read only flag
set statusline+=%m "modified flag
"Syntastic!!
" set statusline+=%#warningmsg#
" set statusline+=%{SyntasticStatuslineFlag()}
" set statusline+=%*
" Auto completion options
set wildmode=list:longest "Change tab completion to be like Bash's
set wildignore=*.o,*.obj,*~,*.swp,*.pyc "Files to ignore on auto complete
"display tabs and trailing spaces
set list
" Use the same symbols as TextMate for tabstops and EOLs
set listchars=tab:▸\•,extends:»,precedes:«,trail:•
let g:pydiction_location='~/.vim/after/ftplugin/pydiction/complete-dict'
set sm
set ai
let java_highlight_all=1
let java_highlight_functions="style"
let java_allow_cpp_keywords=1
set tags=~/.tags
set complete=.,w,b,u,t,i
command W w !sudo tee % > /dev/null
" IMPORTANT: win32 users will need to have 'shell slash' set so that latex
" can be called correctly.
"set shell slash
" IMPORTANT: grep will sometimes skip displaying the file name if you
" search in a singe file. This will confuse Latex-Suite. Set your grep
" program to always generate a file-name.
"set grepprg=grep\ -nH\ $*
" OPTIONAL: Starting with Vim 7, the filetype of empty .tex files defaults to
" 'plaintex' instead of 'tex', which results in vim-latex not being loaded.
" The following changes the default filetype back to 'tex':
" let g:tex_flavor='latex'
filetype on " enables filetype detection
filetype plugin on " enables filetype specific plug-ins
syntax on
filetype indent on " OPTIONAL: This enables automatic indentation as you type.
" VIM 7.3 features here...
if v:version >= 703
set relativenumber
set undofile
endif
Use :let g:colors_name to see the name of the colourscheme that has been loaded, the value should be 'sorcerer', if it's not then something has gone seriously wrong
Type :hi Operator, you 'xxx' part should be coloured and you should see guifg=<color> in the output.
Put a new line at the top of your .vimrc containing just the word "finish", this will stop vim processing your .vimrc. Using :colors default and :syntax on should be enough to get syntax highlighting turned on. If this works then just move the finish line down through your .vimrc until you find the section that is breaking syntax highlighting.
On windows, gVim uses a file called _vimrc, so check for that as well.
When you type :version in gvim do you see +syntax listed in your features list?
Try comparing that to your regular Vim version. Maybe your gvim build didn't include the syntax highlighting feature.
The issue was fixed once I finally figured out how to get gvim 7.3. Then the syntax highlighting magically came.
Building on Thien's response, I also had the same experience (set syntax=on fails, the menu options succeed but only until Vim is restarted).
The menu option apparently triggers :syn=on, and adding that to _vimrc does enable syntax highlighting persistently where set syntax=on did not. I'll leave it to someone with more experience to explain the difference between those two.
set syntax=xxx was not working for me in gvim 7.3 on Windows XP although it did for vim in cygwin. To get syntax highlighting I had to go to Menu > Syntax > Show filetypes in menu > select syntax. I guess the menu command and the vim commands don't do the same thing with gvim on Windows.