Neovim: Difference between revisions
Line 406: | Line 406: | ||
hi! MatchParen gui=NONE,bold cterm=NONE,bold guifg=#dc322f ctermfg=1 guibg=#eee8d5 ctermbg=7 |
hi! MatchParen gui=NONE,bold cterm=NONE,bold guifg=#dc322f ctermfg=1 guibg=#eee8d5 ctermbg=7 |
||
</source> |
</source> |
||
=== Slow navigation / edition in "big" files (>1000 lines) === |
|||
The culprit is plugin '''vim-gitgutter'''. To identify the culprit, we run the vim profiler [https://stackoverflow.com/questions/12213597/how-to-see-which-plugins-are-making-vim-slow]: |
|||
<source lang="vim"> |
|||
:profile start profile.log |
|||
:profile func * |
|||
:profile file * |
|||
" At this point do slow actions |
|||
:profile pause |
|||
:noautocmd qall! |
|||
</source> |
|||
Looking in the log, we see that |
|||
* <code>gitgutter#async#handle_diff_job_nvim</code> took 5.7s on 18 calls, |
|||
* <code>gitgutter#sign#remove_signs</code> took 2.65s on 12 calls, |
|||
* <code>gitgutter#sign#upsert_new_gitgutter_signs</code> took 2.7s on 12 calls, |
|||
* <code>gitgutter#sign#update_signs</code> took 5.51s on 12 calls, |
|||
* <code>gitgutter#handle_diff()</code> took 5.7s on 12 calls, |
|||
More information on how to profile ''gitgutter'': https://github.com/airblade/vim-gitgutter/wiki/How-to-profile-vim-gitgutter. |
|||
Related issue: |
|||
* [https://github.com/airblade/vim-gitgutter/issues/335 #335]. |
|||
* [https://github.com/airblade/vim-gitgutter/issues/184 #184]. |
|||
== To Do == |
== To Do == |
Revision as of 15:03, 20 November 2017
This page only deals with major differences between Neovim and Vim. See Vim page for general Vim-related information.
References
Dotfiles examples
- http://nerditya.com/code/guide-to-neovim/
- new — http://coderoncode.com/tools/2017/04/16/vim-the-perfect-ide.html
Install
See the guide Installing Neovim.
On Ubuntu, we install from Neovim repository, tracking HEAD
:
sudo add-apt-repository ppa:neovim-ppa/unstable
sudo apt-get update
sudo apt-get install neovim
Default ini files are located at ~/.config/nvim/init.vim. To import Vim settings (FAQ :help nvim-from-vim)
mkdir ~/.config
ln -s ~/.vim ~/.config/nvim
ln -s ~/.vimrc ~/.config/nvim/init.vim
Configure nvim as default vim alternative:
sudo update-alternatives --install /usr/bin/vi vi /usr/bin/nvim 60
sudo update-alternatives --config vi
sudo update-alternatives --install /usr/bin/vim vim /usr/bin/nvim 60
sudo update-alternatives --config vim
sudo update-alternatives --install /usr/bin/editor editor /usr/bin/nvim 60
sudo update-alternatives --config editor
Install Ruby gems for Ruby support:
sudo apt install ruby-dev
sudo gem install neovim
Install Python package for Python support:
sudo pip install neovim
Build on debian
- Download latest git and debian folder [1]:
git clone https://github.com/neovim/neovim.git wget http://http.debian.net/debian/pool/main/n/neovim/neovim_0.2.0-3.debian.tar.xz cd neovim tar xvf ../neovim_0.2.0-3.debian.tar.xz
- Patch debian folder. First disable the tests:
--- a/debian/rules
+++ b/debian/rules
@@ -52,5 +52,3 @@ debian/fakehome:
override_dh_auto_test-indep:
override_dh_auto_test-arch: debian/passwd debian/fakehome
- mv -f test/functional/ex_cmds/global_spec.lua debian/
- env "HOME=$(CURDIR)/debian/fakehome" LD_PRELOAD=libnss_wrapper.so "NSS_WRAPPER_PASSWD=$(CURDIR)/debian/passwd" "NSS_WRAPPER_GROUP=$(CURDIR)/debian/group" make $(UNITTEST) $(FUNCTIONALTEST) oldtest VERBOSE=1 USE_BUNDLED_DEPS=OFF
- Then disable
--fail-missing
:
--- a/debian/rules
+++ b/debian/rules
override_dh_install:
- dh_install --fail-missing
+ dh_install
This is a temporary fix for error:
dh_install --fail-missing dh_install: usr/share/applications/nvim.desktop exists in debian/tmp but is not installed to anywhere dh_install: usr/share/pixmaps/nvim.png exists in debian/tmp but is not installed to anywhere dh_install: missing files, aborting
- Install some dependencies (should use the apt )
# sudo apt-get buildeps neovim/stretch
# OR sudo apt-get buildeps neovim/sid
sudo apt install debhelper=10.2.5
sudo apt install -t stretch luajit
sudo apt install -t sid lua-nvim
- Then build:
debchange --newversion 0.2.0debian1-git20170619123516 --distribution unstable "Latest version"
dpkg-buildpackage -rfakeroot -b -d
- Then install both neovim and neovim-runtime package.
Fixes / workarounds
- Broken vertical mode (see below for fix).
NeoVim GUI
For now, there are no official GUI for Neovim (like gvim
). Potential candidates are (see also Neovim related projects):
- neovim-qt
- NyaoVim (an advanced Electron UI based client)
- ONI (another Electron UI based client)
- Use a customized terminal (like Gnome-Terminal)
Criteria for a good GUI:
- Be fast (fast refresh, no jitter in scrolling).
- Drop-in compatible with gvim / vim.
- True color and italic support.
- Blinking cursor (mandatory) and block/caret mode (optional).
- Blinking cursor is necessary when using
incsearch
plugin (or we miss some hightlights).
Terminator + neovim
The best and simplest solution. We use terminator as a gui.
Create the script ngvim:
#! /bin/bash
# Redirect stderr to silent error on keyboard binding failure
2> /dev/null exec /usr/bin/terminator -m --p nvim -i /usr/local/icons/neovim.png -u -x nvim "$@"
This script:
- Sets terminal icon to neovim's.
- Tell terminator to wait until application exits (equivalent to
gvim -f
) - Tell terminator not to use Dbus (such that to always appear above current windows).
The advantage of this script is that we use the same back-end as the terminal, and hence we will have the same experience (same features, same bugs).
NyaoVim / ONI
These are Electron-based GUI, under heavy development. They seem to offer rich GUI features (Markdown preview with NyaoVim, rich auto-completion with ONI).
Revisit when:
- Support C/C++ language for auto-completion.
neovim-qt
Build from source. Bindings seem old, so we rebuild them:
mkdir build
cd build
cmake ..
make bindings
cmake --build .
- Issues
- Cursor not blinking! Using QT API
app.setCursorFlashTime(1000);
does not help. - Message Unknown Neovim function "Array vim_get_api_info()". Due to missing/additional bindings. If necessary, we can mute this message in src/function.cpp.
Custom terminal - Gnome-Terminal
The best I could do so far is to create a script gnvim
that uses gnome-terminal as window, sets title to NeoVim, and sets icon using xseticon.
To install gnvim
:
- Build and install xseticon.
- Copy neovim icon to /usr/local/icons/neovim.png. For instance, there is an icon in neovim-qt.git:
git clone https://github.com/equalsraf/neovim-qt.git
sudo mkdir -p /usr/local/icons
sudo cp neovim-qt/third-party/neovim.png /usr/local/icons
- Create file gnvim, and make it executable:
#! /bin/bash
# We add a sleep 1 because of race condition between xseticon and echo
gnome-terminal --geometry 132x50 --hide-menubar -x bash -c "echo -ne '\033]0;NeoVim\007'; ((sleep 1; xseticon -name NeoVim /usr/local/icons/neovim.png)&); exec nvim $*"
- To add NeoVim GUI as a desktop application, create the file ~/.local/share/applications/neovim.desktop:
#!/usr/bin/env xdg-open
[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Exec=/home/peetersm/bin/ngvim
Name=NeoVim
Comment=The future of Vim
Icon=/usr/local/icons/neovim.png
Then
chmod a+x ~/.local/share/applications/neovim.desktop
Neovim Gnome-Terminal wrapper
Small wrapper in Python, but it only sets the icon in unity bar, not task switcher.
Tips
Use :term
for Read–eval–print loop (REPL)
This can be easily done using a new buffer (C-w v) and a terminal (:term
), and then
- Use
watch
:
watch 'make this && less that'
- Use
entr
:
echo myfile myotherfile | entr make this
Neovim features
Just a couple of things I should not forget exist.
- Powerful terminal emulation.
- Incremental substitution (
set inccommand=split
) (see here).
Troubleshooting
Troubleshooting tips
- Try reproducing without config file:
nvim -u NORC
. - Try disabling all plugings. This is more easily done when using a plugin manager (for instance, with vim-plug, comment out
Plug
lines.
Known GOOD version
On debian:
- neovim_0.2.0debian1-git20170619123516_all.deb
On ubuntu:
- neovim_0.2.0ubuntu1+git201707091951+3517+26~ubuntu16.04.1_amd64.deb
- neovim_0.2.0ubuntu1+git201705081829+3414+24~ubuntu16.04.1_amd64.deb
- neovim_0.1.7ubuntu1+git201704230032+3359+23~ubuntu16.04.1_amd64.deb
- neovim_0.1.7ubuntu1+git201703230754+3253+23~ubuntu16.04.1_amd64.deb
- neovim_0.1.7ubuntu1+git201703122001+3207+23~ubuntu16.04.1_amd64.deb
- neovim_0.1.5ubuntu1+git201612110104+2963+22~ubuntu16.04.1_amd64.deb
Known BROKEN version
- deb
- Strange characters appearing when scrolling down in C code (like
38:2:42:161:152m
)
- neovim_0.2.0ubuntu1+git201706190001+3482+26~ubuntu16.04.1_amd64.deb
Fix broken vertical mode
Due to bad TERM
or COLORTERM
env variables #6816 and #6802
- Currently I have:
# On gnome-terminal:
echo $TERM / $COLORTERM
# xterm-256color /
# On terminator:
echo $TERM / $COLORTERM
# xterm-256color / truecolor
The fix is to either unset TERM, or set it to gnome-256color
, or set COLORTERM to gnome-terminal
.
- Gnome-Terminal
To fix on Gnome-terminal [2]:
dconf write '/org/gnome/terminal/legacy/profiles:/:b1dcc9dd-5262-4d8d-a863-c897e6d979b9/custom-command' "'env COLORTERM=gnome-terminal /bin/bash'"
dconf write '/org/gnome/terminal/legacy/profiles:/:b1dcc9dd-5262-4d8d-a863-c897e6d979b9/use-custom-command' "true"
# Verify:
dconf dump /org/gnome/terminal/legacy/profiles:/
Changing TERM
breaks too many application, so we change instead COLORTERM
.
- Terminator
We can apply the same trick. Or we can patch terminatorlib/config.py:
- 'colorterm' : 'truecolor',
+ 'term' : 'gnome-terminal',
Changing TERM
breaks too many application, so we change instead COLORTERM
.
- Midnight commander
Changing TERM impacts Midnight Commander. Force xterm mode with mc -x
.
This is no longer needed if we keep TERM
as is.
True color and italic support
See xterm.
Regarding terminal support:
Meta/Alt-key mappings choke (when typed too fast)
See bug #2454.
The solution is too actually install the plugin vim-sensible, contrary to what says :CheckHealth
.
This plugins set ttimeoutlen
to 100
, which is sufficient to have alt-key mappings to act correctly in TUI.
- Update
- Now vim-sensible disables
ttimeout
when it detects neovim :-(. See vim-sensible/#141.
nvim-qt issues
- No blinking cursor in nvim-qt
Adding call to QApplication::setCursorFlashTime()
in main.cpp does not help. See issue #208.
- No support for option 'S' and '-c'
See #224.
Cursor (sometimes) stops blinking
Neovim hard-codes cursor shape and mode. This is tracked in tickets #5740, #5556. See also [Cursor stops blinking #3257], and #4867.
The solution is to use :set guicursor
:
:set guicursor=n-v-c:block,i-ci-ve:ver25,r-cr:hor20,o:hor50, \
n-v-c:blinkwait700-blinkoff400-blinkon250, \
sm:block-blinkwait175-blinkoff150-blinkon175
Undefined variable: self
See issue #5763.
Last known good version without this bug for me: neovim_0.1.5ubuntu1+git201612110104+2963+22~ubuntu16.04.1_amd64.deb.
Bug fixed, but must update all plugins (:PlugUpdate
) and vim-plug itself (with :PlugUpgrade
).
incsearch plugin broken
See issue #125.
Shift-enter not working in TUI
This requires a terminal that can configure CSI (like iTerm2). Maybe [pangoterm] is another option.
See also:
Neovim not resizing correctly in Terminator on split
See bug 6156.
"E724: unable to correctly dump variable with self-referencing container" when using incsearch
See bug 5902. My fork on GitHub contains a workaround.
- FIXED in latest incsearch release.
YouCompleteMe semantic engine causes spurious buffer scrolling
Typind a dot .
in CPP code causes spurious buffer scrolling. Edited line usually ends up at the bottom of the editing window, which is inconvenient.
This happens in NeoVim, but not in gvim. Also the semantic engine was not actually running.
To fix, disable semantic completion:
let g:ycm_filetype_specific_completion_to_disable = {
\ 'cpp': 1,
\ 'gitcommit': 1
\}
Strange ESC sequence characters appearing when scrolling
Strange characters appearing when scrolling down in C code (like 38:2:42:161:152m
).
Occurred in version:
0.2.0ubuntu1+git201709190613+3649+26~ubuntu16.04.1
.
Github:
- Issue #7381.
To reproduce the problem:
- create file tmp.c with
for((j=0;j<128;j++)); do echo "{ $(for((i=0;i<17;i++)); do echo -n '0x00, '; done) }"; done > tmp2.c
- Edit the file again. Bug will occur on display.
The minimum .vimrc to reproduce:
call plug#begin('~/.vim/plugged')
Plug 'xeyownt/vim-colors-solarized'
call plug#end()
if has('nvim')
set termguicolors
endif
colorscheme solarized
It also requires using my fork of vim-colors-solarized (commit 6d72acc).
Another minimum .vimrc to reproduce:
call plug#begin('~/.vim/plugged')
Plug 'Icymind/NeoSolarized'
call plug#end()
if has('nvim')
set termguicolors
endif
colorscheme NeoSolarized
hi! MatchParen gui=NONE,underline,bold cterm=NONE,underline,bold guifg=#dc322f ctermfg=1 guibg=#eee8d5 ctermbg=7
Alternatively, remove the last line, and patch NeoSolarized with:
-exe "hi! MatchParen" .s:fmt_bold .s:fg_red .s:bg_base01
+exe "hi! MatchParen" .s:fmt_undb .s:fg_red .s:bg_base02
The bug does not occur when patching with:
-exe "hi! MatchParen" .s:fmt_bold .s:fg_red .s:bg_base01
+exe "hi! MatchParen" .s:fmt_bold .s:fg_red .s:bg_base02
This corresponds to executing line line
hi! MatchParen gui=NONE,bold cterm=NONE,bold guifg=#dc322f ctermfg=1 guibg=#eee8d5 ctermbg=7
The culprit is plugin vim-gitgutter. To identify the culprit, we run the vim profiler [3]:
:profile start profile.log
:profile func *
:profile file *
" At this point do slow actions
:profile pause
:noautocmd qall!
Looking in the log, we see that
gitgutter#async#handle_diff_job_nvim
took 5.7s on 18 calls,gitgutter#sign#remove_signs
took 2.65s on 12 calls,gitgutter#sign#upsert_new_gitgutter_signs
took 2.7s on 12 calls,gitgutter#sign#update_signs
took 5.51s on 12 calls,gitgutter#handle_diff()
took 5.7s on 12 calls,
More information on how to profile gitgutter: https://github.com/airblade/vim-gitgutter/wiki/How-to-profile-vim-gitgutter. Related issue:
To Do
- Find a good TUI or GUI
- Test advanced linters plugins like neomake and syntactics.