faq.txt 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. *faq.txt* Nvim
  2. NVIM REFERENCE MANUAL
  3. Frequently asked Questions *faq*
  4. Type |gO| to see the table of contents.
  5. ==============================================================================
  6. General Questions *faq-general*
  7. WHERE SHOULD I PUT MY CONFIG (VIMRC)? ~
  8. See |config|; you can copy (or symlink) your existing vimrc. |nvim-from-vim|
  9. HOW STABLE IS THE DEVELOPMENT (PRE-RELEASE) VERSION? ~
  10. The unstable (pre-release)
  11. https://github.com/neovim/neovim/releases/tag/nightly version of Nvim
  12. ("HEAD", i.e. the `master` branch) is used to aggressively stage new features
  13. and changes. It's usually stable, but will occasionally break your workflow.
  14. We depend on HEAD users to report "blind spots" that were not caught by
  15. automated tests.
  16. Use the stable (release) https://github.com/neovim/neovim/releases/latest
  17. version for a more predictable experience.
  18. CAN I USE LUA-BASED VIM PLUGINS (E.G. NEOCOMPLETE)? ~
  19. No. Starting with Nvim 0.2 PR #4411
  20. https://github.com/neovim/neovim/pull/4411 Lua is built-in, but the legacy
  21. Vim `if_lua` interface is not supported.
  22. HOW CAN I USE "TRUE COLOR" IN THE TERMINAL? ~
  23. Truecolor (24bit colors) are enabled by default if a supporting terminal is
  24. detected. If your terminal is not detected but you are sure it supports
  25. truecolor, add this to your |init.vim|:
  26. >vim
  27. set termguicolors
  28. <
  29. NVIM SHOWS WEIRD SYMBOLS (`�[2 q`) WHEN CHANGING MODES ~
  30. This is a bug in your terminal emulator. It happens because Nvim sends
  31. cursor-shape termcodes by default, if the terminal appears to be
  32. xterm-compatible (`TERM=xterm-256color`).
  33. To workaround the issue, you can:
  34. - Use a different terminal emulator
  35. - Disable 'guicursor' in your Nvim config: >vim
  36. :set guicursor=
  37. " Workaround some broken plugins which set guicursor indiscriminately.
  38. :autocmd OptionSet guicursor noautocmd set guicursor=
  39. <
  40. See also |$TERM| for recommended values of `$TERM`.
  41. HOW TO CHANGE CURSOR SHAPE IN THE TERMINAL? ~
  42. - For Nvim 0.1.7 or older: see the note about `NVIM_TUI_ENABLE_CURSOR_SHAPE` in `man nvim`.
  43. - For Nvim 0.2 or newer: cursor styling is controlled by the 'guicursor' option.
  44. - To _disable_ cursor-styling, set 'guicursor' to empty: >vim
  45. :set guicursor=
  46. " Workaround some broken plugins which set guicursor indiscriminately.
  47. :autocmd OptionSet guicursor noautocmd set guicursor=
  48. <
  49. - If you want a non-blinking cursor, use `blinkon0`. See 'guicursor'.
  50. - 'guicursor' is enabled by default, unless Nvim thinks your terminal doesn't
  51. support it. If you're sure that your terminal supports cursor-shaping, set
  52. 'guicursor' in your |init.vim|, as described in 'guicursor'.
  53. - The Vim terminal options |t_SI| and `t_EI` are ignored, like all other |t_xx| options.
  54. - Old versions of libvte (gnome-terminal, roxterm, terminator, ...) do not
  55. support cursor style control codes. #2537
  56. https://github.com/neovim/neovim/issues/2537
  57. HOW TO CHANGE CURSOR COLOR IN THE TERMINAL? ~
  58. Cursor styling (shape, color, behavior) is controlled by 'guicursor', even in
  59. the terminal. Cursor color (as opposed to shape) only works if
  60. 'termguicolors' is set.
  61. 'guicursor' gives an example, but here's a more complicated example
  62. which sets different colors in insert-mode and normal-mode:
  63. >vim
  64. :set termguicolors
  65. :hi Cursor guifg=green guibg=green
  66. :hi Cursor2 guifg=red guibg=red
  67. :set guicursor=n-v-c:block-Cursor/lCursor,i-ci-ve:ver25-Cursor2/lCursor2,r-cr:hor20,o:hor50
  68. <
  69. CURSOR STYLE ISN'T RESTORED AFTER EXITING OR SUSPENDING AND RESUMING NVIM ~
  70. Terminals do not provide a way to query the cursor style. Use autocommands to
  71. manage the cursor style:
  72. >vim
  73. au VimEnter,VimResume * set guicursor=n-v-c:block,i-ci-ve:ver25,r-cr:hor20,o:hor50
  74. \,a:blinkwait700-blinkoff400-blinkon250-Cursor/lCursor
  75. \,sm:block-blinkwait175-blinkoff150-blinkon175
  76. au VimLeave,VimSuspend * set guicursor=a:block-blinkon0
  77. <
  78. CURSOR SHAPE DOESN'T CHANGE IN TMUX ~
  79. tmux decides that, not Nvim. See |tui-cursor-shape| for a fix.
  80. See #3165 https://github.com/neovim/neovim/pull/3165 for discussion.
  81. CURSOR FLICKER IN TMUX? ~
  82. If cursor `_` appears and disappears very quickly when opening nvim without a
  83. document under tmux, and you set |ctermbg| in `EndOfBuffer` and `Normal`, try
  84. setting these to `NONE`:
  85. >vim
  86. hi EndOfBuffer ctermbg=NONE ctermfg=200 cterm=NONE
  87. hi Normal ctermbg=NONE ctermfg=200 cterm=NONE
  88. <
  89. WHAT HAPPENED TO --remote AND FRIENDS? ~
  90. |--remote| is partly supported. |clientserver|
  91. If you require flags from Vim that are missing in Nvim, you can use
  92. https://github.com/mhinz/neovim-remote instead.
  93. ==============================================================================
  94. Runtime issues *faq-runtime*
  95. COPYING TO X11 PRIMARY SELECTION WITH THE MOUSE DOESN'T WORK ~
  96. `clipboard=autoselect` is not implemented yet
  97. https://github.com/neovim/neovim/issues/2325. You may find this workaround to
  98. be useful:
  99. >vim
  100. vnoremap <LeftRelease> "*ygv
  101. vnoremap <2-LeftRelease> "*ygv
  102. <
  103. MY CTRL-H MAPPING DOESN'T WORK ~
  104. This was fixed in Nvim 0.2. If you are running Nvim 0.1.7 or older,
  105. adjust your terminal's "kbs" (key_backspace) terminfo entry:
  106. >vim
  107. infocmp $TERM | sed 's/kbs=^[hH]/kbs=\\177/' > $TERM.ti
  108. tic $TERM.ti
  109. <
  110. (Feel free to delete the temporary `*.ti` file created after running the above
  111. commands).
  112. <HOME> OR SOME OTHER "SPECIAL" KEY DOESN'T WORK ~
  113. Make sure |$TERM| is set correctly.
  114. - For screen or tmux, `$TERM` should be `screen-256color` (not `xterm-256color`!)
  115. - In other cases if "256" does not appear in the string it's probably wrong.
  116. Try `TERM=xterm-256color`.
  117. :! AND SYSTEM() DO WEIRD THINGS WITH INTERACTIVE PROCESSES ~
  118. Interactive commands are supported by |:terminal| in Nvim. But |:!| and
  119. |system()| do not support interactive commands, primarily because Nvim UIs use
  120. stdio for msgpack communication, but also for performance, reliability, and
  121. consistency across platforms (see
  122. https://vimhelp.org/gui_x11.txt.html#gui-pty).
  123. See also #1496 https://github.com/neovim/neovim/issues/1496 and #8217
  124. https://github.com/neovim/neovim/issues/8217#issuecomment-402152307.
  125. PYTHON SUPPORT ISN'T WORKING ~
  126. Run |:checkhealth| in Nvim for automatic diagnosis.
  127. Other hints:
  128. - The python `neovim` module was renamed to `pynvim` (long ago).
  129. - If you're using pyenv or virtualenv for the `pynvim` module
  130. https://pypi.org/project/pynvim/, you must set `g:python3_host_prog` to
  131. the virtualenv's interpreter path.
  132. - Read |provider-python|.
  133. - Be sure you have the latest version of the `pynvim` Python module: >bash
  134. python -m pip install setuptools
  135. python -m pip install --upgrade pynvim
  136. python3 -m pip install --upgrade pynvim
  137. <
  138. - Try with `nvim -u NORC` to make sure your config (|init.vim|) isn't causing a
  139. problem. If you get `E117: Unknown function`, that means there's a runtime
  140. issue: |faq-runtime|.
  141. :CHECKHEALTH REPORTS E5009: INVALID $VIMRUNTIME ~
  142. This means `health#check()` couldn't load, which suggests that |$VIMRUNTIME|
  143. or 'runtimepath' is broken.
  144. - |$VIMRUNTIME| must point to Nvim's runtime files, not Vim's.
  145. - The |$VIMRUNTIME| directory contents should be readable by the current user.
  146. - Verify that `:echo &runtimepath` contains the $VIMRUNTIME path.
  147. - Check the output of: >vim
  148. :call health#check()
  149. :verbose func health#check
  150. <
  151. NEOVIM CAN'T FIND ITS RUNTIME ~
  152. This is the case if `:help nvim` shows `E149: Sorry, no help for nvim`.
  153. Make sure that |$VIM| and |$VIMRUNTIME| point to Nvim's (as opposed to
  154. Vim's) runtime by checking `:echo $VIM` and `:echo $VIMRUNTIME`. This should
  155. give something like `/usr/share/nvim` resp. `/usr/share/nvim/runtime`.
  156. Also make sure that you don't accidentally overwrite your runtimepath
  157. (`:set runtimepath?`), which includes the above |$VIMRUNTIME| by default (see
  158. 'runtimepath').
  159. NEOVIM IS SLOW ~
  160. Use a fast terminal emulator:
  161. - kitty https://github.com/kovidgoyal/kitty
  162. - alacritty https://github.com/jwilm/alacritty
  163. Use an optimized build:
  164. `:checkhealth nvim` should report one of these "build types":
  165. >
  166. Build type: RelWithDebInfo
  167. Build type: MinSizeRel
  168. Build type: Release
  169. <
  170. If it reports `Build type: Debug` and you're building Nvim from source, see
  171. https://github.com/neovim/neovim/blob/master/BUILD.md.
  172. COLORS AREN'T DISPLAYED CORRECTLY ~
  173. Ensure that |$TERM| is set correctly.
  174. From a shell, run `TERM=xterm-256color nvim`. If colors are displayed
  175. correctly, then export that value of `TERM` in your user profile (usually
  176. `~/.profile`):
  177. >bash
  178. export TERM=xterm-256color
  179. <
  180. If you're using `tmux`, instead add this to your `tmux.conf`:
  181. >bash
  182. set -g default-terminal "tmux-256color"
  183. <
  184. For GNU `screen`, configure your `.screenrc`
  185. <https://wiki.archlinux.org/index.php/GNU_Screen#Use_256_colors>:
  186. >
  187. term screen-256color
  188. <
  189. NOTE: Nvim ignores `t_Co` and other |t_xx| terminal codes.
  190. NEOVIM CAN'T READ UTF-8 CHARACTERS ~
  191. Run the following from the command line:
  192. >bash
  193. locale | grep -E '(LANG|LC_CTYPE|LC_ALL)=(.*\.)?(UTF|utf)-?8'
  194. <
  195. If there's no results, you might not be using a UTF-8 locale. See these issues:
  196. - https://github.com/neovim/neovim/issues/1601
  197. - https://github.com/neovim/neovim/issues/1858
  198. - https://github.com/neovim/neovim/issues/2386
  199. ESC IN TMUX OR GNU SCREEN IS DELAYED ~
  200. This is a common problem
  201. https://www.google.com/?q=tmux%20vim%20escape%20delay in `tmux` / `screen`
  202. (see also https://github.com/tmux/tmux/issues/131#issuecomment-145853211). The
  203. corresponding timeout needs to be tweaked to a low value (10-20ms).
  204. `.tmux.conf`:
  205. >
  206. set -g escape-time 10
  207. # Or for tmux >= 2.6
  208. set -sg escape-time 10
  209. <
  210. `.screenrc`:
  211. >
  212. maptimeout 10
  213. <
  214. "WHY DOESN'T THIS HAPPEN IN VIM?"
  215. It does happen (try `vim -N -u NONE`), but if you hit a key quickly after
  216. ESC then Vim interprets the ESC as ESC instead of ALT (META). You won't
  217. notice the delay unless you closely observe the cursor. The tradeoff is that
  218. Vim won't understand ALT (META) key-chords, so for example `nnoremap <M-a>`
  219. won't work. ALT (META) key-chords always work in Nvim.
  220. See also `:help xterm-cursor-keys` in Vim.
  221. Nvim 0.3 mimics the Vim behavior while still fully supporting ALT mappings. See
  222. |i_ALT|.
  223. ESC IN GNU SCREEN IS LOST WHEN MOUSE MODE IS ENABLED ~
  224. This happens because of a bug in screen https://savannah.gnu.org/bugs/?60196 :
  225. in mouse mode, screen assumes that `ESC` is part of a mouse sequence and will
  226. wait an unlimited time for the rest of the sequence, regardless of
  227. `maptimeout`. Until it's fixed in screen, there's no known workaround for
  228. this other than double-pressing escape, which causes a single escape to be
  229. passed through to Nvim.
  230. CALLING INPUTLIST(), ECHOMSG, ... IN FILETYPE PLUGINS AND AUTOCMD DOES NOT WORK ~
  231. - https://github.com/neovim/neovim/issues/10008
  232. - https://github.com/neovim/neovim/issues/10116
  233. - https://github.com/neovim/neovim/issues/12288
  234. - https://github.com/vim/vim/issues/4379
  235. This is because Nvim sets `shortmess+=F` by default. Vim behaves the same way
  236. with `set shortmes+=F`. There are plans to improve this, but meanwhile as a
  237. workaround, use `set shortmess-=F` or use `unsilent` as follows.
  238. >vim
  239. unsilent let var = inputlist(['1. item1', '2. item2'])
  240. autocmd BufNewFile * unsilent echomsg 'The autocmd has been fired.'
  241. <
  242. G:CLIPBOARD SETTINGS ARE NOT USED. ~
  243. If the clipboard provider is already loaded, you will need to reload it after
  244. configuration. Use the following configuration.
  245. >vim
  246. let g:clipboard = { 'name' : ... }
  247. if exists('g:loaded_clipboard_provider')
  248. unlet g:loaded_clipboard_provider
  249. runtime autoload/provider/clipboard.vim
  250. endif
  251. <
  252. Or, if you want automatic reloading when assigning to |g:clipboard|, set
  253. |init.vim| as follows.
  254. >vim
  255. function! s:clipboard_changed(...) abort
  256. if exists('g:loaded_clipboard_provider')
  257. unlet g:loaded_clipboard_provider
  258. endif
  259. runtime autoload/provider/clipboard.vim
  260. endfunction
  261. if !exists('s:loaded")
  262. call dictwatcheradd(g:, 'clipboard', function('s:clipboard_changed'))
  263. endif
  264. let s:loaded = v:true
  265. <
  266. ==============================================================================
  267. Build issues *faq-build*
  268. GENERAL BUILD ISSUES ~
  269. Run `make distclean && make` to rule out a stale build environment causing the
  270. failure.
  271. SETTINGS IN LOCAL.MK DON'T TAKE EFFECT ~
  272. CMake caches build settings, so you might need to run `rm -r build && make`
  273. after modifying `local.mk`.
  274. CMAKE ERRORS ~
  275. `configure_file Problem configuring file`
  276. This is probably a permissions issue, which can happen if you run `make` as the
  277. root user, then later run an unprivileged `make`. To fix this, run
  278. `rm -rf build` and try again.
  279. GENERATING HELPTAGS FAILED ~
  280. If re-installation fails with "Generating helptags failed", try removing the
  281. previously installed runtime directory (if `CMAKE_INSTALL_PREFIX` is not set
  282. during building, the default is `/usr/local/share/nvim`):
  283. >bash
  284. rm -r /usr/local/share/nvim
  285. <
  286. ==============================================================================
  287. Design *faq-design*
  288. WHY NOT USE JSON FOR RPC? ~
  289. - JSON cannot easily/efficiently handle binary data
  290. - JSON specification is ambiguous: https://seriot.ch/parsing_json.php
  291. WHY EMBED LUA INSTEAD OF X? ~
  292. - Lua is a very small language, ideal for embedding. The biggest advantage of
  293. Python/Ruby/etc is their huge collection of libraries, but that isn't
  294. relevant for Nvim, where Nvim is the "batteries included" library:
  295. introducing another stdlib would be redundant.
  296. - Lua 5.1 is a complete language: the syntax is frozen. This is great for
  297. backwards compatibility.
  298. - Nvim also uses Lua internally as an alternative to C. Extra performance is
  299. useful there, as opposed to a slow language like Python or Vim9script.
  300. - LuaJIT is one of the fastest runtimes on the planet, 10x faster than Python
  301. and "Vim9script" https://vimhelp.org/vim9.txt.html , 100x faster than
  302. Vimscript.
  303. - Python/JS cost more than Lua in terms of size and portability, and there are
  304. already numerous Python/JS-based editors. So Python/JS would make Nvim
  305. bigger and less portable, in exchange for a non-differentiating feature.
  306. See also:
  307. - Why Lua https://web.archive.org/web/20150219224654/https://blog.datamules.com/blog/2012/01/30/why-lua/
  308. - The Design of Lua https://cacm.acm.org/magazines/2018/11/232214-a-look-at-the-design-of-lua/fulltext
  309. - Scripting architecture considerations http://oldblog.antirez.com/post/redis-and-scripting.html
  310. - LuaJIT performance https://julialang.org/benchmarks/
  311. - Discussion of JavaScript vs Lua https://github.com/vim/vim/pull/5198#issuecomment-554693754
  312. - Discussion Python embedding https://lobste.rs/s/pnuak4/mercurial_s_journey_reflections_on#c_zshdwy
  313. WHY LUA 5.1 INSTEAD OF LUA 5.3+? ~
  314. Lua 5.1 is a different language than 5.3. The Lua org makes breaking changes
  315. with every new version, so even if we switched (not upgraded, but switched) to
  316. 5.3 we gain nothing when they create the next new language in 5.4, 5.5, etc.
  317. And we would lose LuaJIT, which is far more valuable than Lua 5.3+.
  318. Lua 5.1 is a complete language. To "upgrade" it, add libraries, not syntax.
  319. Nvim itself already is a pretty good "stdlib" for Lua, and we will continue to
  320. grow and enhance it. Changing the rules of Lua gains nothing in this context.
  321. WILL NEOVIM TRANSLATE VIMSCRIPT TO LUA, INSTEAD OF EXECUTING VIMSCRIPT DIRECTLY? ~
  322. - We are experimenting with vim9jit https://github.com/tjdevries/vim9jit to
  323. transpile Vim9script (Vim9's Vimscript variant) to Lua and have used this to
  324. port Vim9 plugins https://github.com/neovim/neovim/pull/21662 to Nvim Lua.
  325. - We have no plans for transpiling legacy Vimscript.
  326. ARE PLUGIN AUTHORS ENCOURAGED TO PORT THEIR PLUGINS FROM VIMSCRIPT TO LUA? DO YOU PLAN ON SUPPORTING VIMSCRIPT INDEFINITELY? (#1152) ~
  327. We don't anticipate any reason to deprecate Vimscript, which is a valuable DSL
  328. https://en.wikipedia.org/wiki/Domain-specific_language for text-editing tasks.
  329. Maintaining Vimscript compatibility is less costly than a mass migration of
  330. existing Vim plugins.
  331. Porting from Vimscript to Lua just for the heck of it gains nothing. Nvim is
  332. emphatically a fork of Vim in order to leverage the work already spent on
  333. thousands of Vim plugins, while enabling new types of plugins and
  334. integrations.
  335. vim:tw=78:ts=8:noet:ft=help:norl: