dev_vimpatch.txt 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. *dev_vimpatch.txt* Nvim
  2. NVIM REFERENCE MANUAL
  3. Merging patches from Vim *dev-vimpatch*
  4. Nvim was forked from Vim 7.4.160; it is kept up-to-date with relevant Vim
  5. patches in order to avoid duplicate work. Run `vim-patch.sh`
  6. https://github.com/neovim/neovim/blob/master/scripts/vim-patch.sh to see the
  7. status of Vim patches:
  8. >bash
  9. ./scripts/vim-patch.sh -l
  10. <
  11. Everyone is welcome to |dev-vimpatch-pull-requests| for relevant Vim
  12. patches, but some types of patches are |dev-vimpatch-not-applicable|.
  13. See |dev-vimpatch-quickstart| to get started immediately.
  14. Type |gO| to see the table of contents.
  15. ==============================================================================
  16. QUICKSTART *dev-vimpatch-quickstart*
  17. 1. Pull the Nvim source:
  18. >bash
  19. git clone https://github.com/neovim/neovim.git
  20. <
  21. 2. Run `./scripts/vim-patch.sh -l` to see the list of missing Vim patches.
  22. 3. Choose a patch from the list (usually the oldest one), e.g. `8.0.0123`.
  23. - Check for open vim-patch PRs
  24. https://github.com/neovim/neovim/pulls?q=is%3Apr+is%3Aopen+label%3Avim-patch.
  25. 4. Run `./scripts/vim-patch.sh -p 8.0.0123`
  26. 5. Follow the instructions given by the script.
  27. NOTES ~
  28. - It's strongly recommended to work on the oldest missing patch, because
  29. later patches might depend on the changes.
  30. - Use `git log --grep` or `git log -G` to search the Nvim/Vim source history
  31. (even deleted code). E.g. to find `reset_option_was_set`: >bash
  32. git log -p -G reset_option_was_set
  33. <
  34. - Pass `git log` options like `--grep` and `-G` to `./scripts/vim-patch.sh -L`
  35. to filter unmerged Vim patches E.g. to find `+quickfix` patches: >bash
  36. ./scripts/vim-patch.sh -L --grep quickfix -- src
  37. <
  38. ==============================================================================
  39. PULL REQUESTS *dev-vimpatch-pull-requests*
  40. Note: vim-patch.sh automates these steps for you. Use it!
  41. - Install `gh` (https://cli.github.com/) if you want to use `vim-patch.sh` to
  42. create PRs automatically
  43. - The pull request title should include `vim-patch:8.x.xxxx` (no whitespace)
  44. - The commit message
  45. https://github.com/neovim/neovim/commit/4ccf1125ff569eccfc34abc4ad794044c5ab7455
  46. should include:
  47. - A token indicating the Vim patch number, formatted as follows:
  48. `vim-patch:8.0.0123` (no whitespace)
  49. - A URL pointing to the Vim commit:
  50. https://github.com/vim/vim/commit/c8020ee825b9d9196b1329c0e097424576fc9b3a
  51. - The original Vim commit message, including author
  52. Reviewers: hint for reviewing `runtime/` patches
  53. https://github.com/neovim/neovim/pull/1744#issuecomment-68202876
  54. ==============================================================================
  55. NA (NOT APPLICABLE) PATCHES *dev-vimpatch-not-applicable*
  56. Many Vim patches are not applicable to Nvim. If you find NA patches, visit an
  57. open "version.c: update" pull request
  58. https://github.com/neovim/neovim/pulls?q=is%3Apr+author%3Aapp%2Fgithub-actions+version.c+is%3Aopen
  59. and mention the NA patches in a comment (please edit/update one comment,
  60. rather than adding a new comment for each patch).
  61. If there are no open `version.c: update` pull requests, include NA patches in
  62. a commit message in the following format:
  63. >
  64. vim-patch:<version-or-commit>
  65. vim-patch:<version-or-commit>
  66. ...
  67. <
  68. where `<version-or-commit>` is a valid Vim version (like `8.0.0123`) or
  69. commit-id (SHA). Each patch is on a separate line.
  70. It is preferred to include NA patches by squashing it in applicable Vim
  71. patches, especially if the Vim patches are related. First line of the commit
  72. message should be from the applicable Vim patch.
  73. >
  74. ./scripts/vim-patch -p <na-patch>
  75. ./scripts/vim-patch -p <na-patch>
  76. ...
  77. ./scripts/vim-patch -P <patch>
  78. git rebase -i master
  79. <
  80. Example:
  81. https://github.com/neovim/neovim/commit/00f60c2ce78fc1280e93d5a36bc7b2267d5f4ac6
  82. TYPES OF "NOT APPLICABLE" VIM PATCHES ~
  83. - Vim9script features, and anything related to `:scriptversion`. (Nvim
  84. supports Vimscript version 1 only.) Be aware that patches labelled `Vim9:`
  85. may still contain applicable fixes to other parts of the codebase, so these
  86. patch need to be checked individually.
  87. - Updates to `testdir/Makefile` are usually NA because the Makefile implicitly
  88. finds
  89. https://github.com/neovim/neovim/commit/8a677f8a4bff6005fa39f090c14e970c3dfdbe6e#diff-b3c6ad6680a25a1b42095879e3a87104R52
  90. all `test_*.vim` files.
  91. - Compiler warning fixes: Nvim strives to have no warnings at all, and has a
  92. very different build system from Vim.
  93. - Note: Coverity fixes in Vim are relevant to Nvim.
  94. - `*.proto` changes: Nvim autogenerates function prototypes
  95. - `#ifdef` tweaking: For example, Vim decided to enable `FEAT_VISUAL` for all
  96. platforms - but Nvim already does that. Adding new `FEAT_` guards also isn't
  97. relevant to Nvim.
  98. - Legacy system support: Fixes for legacy systems such as Amiga, OS/2 Xenix,
  99. Mac OS 9, Windows older than XP SP2, are not needed because they are not
  100. supported by Nvim.
  101. - NA files: `src/Make_*`, `src/testdir/Make__*`
  102. - `if_*.c` changes: `if_python.c` et. al. were removed.
  103. - `term.c` changes: the Nvim TUI uses `libtermkey` to read terminal sequences;
  104. Vim's `term.c` was removed.
  105. - `job` patches: incompatible API and implementation
  106. - NA files: `src/channel_*`, `src/job_*`, `src/testdir/test_channel_*`,
  107. `src/testdir/test_job_*`
  108. - `:terminal` patches that modify NA files: incompatible API and
  109. implementation
  110. - NA files: `src/terminal_*`, `src/testdir/test_terminal_*`
  111. - `defaults.vim` patches
  112. - Most GUI-related changes: Nvim GUIs are implemented external to the core C
  113. codebase.
  114. - NA files: `src/gui_*`, `src/gvim_*`, `src/GvimExt/*`, `src/testdir/test_gui*`
  115. - `balloon` changes: Nvim does not support balloon feature
  116. - NA files: `src/beval_*`, `src/testdir/test_balloon_*`
  117. - Screendump tests from `test_popupwin.vim`, `test_popupwin_textprop.vim`:
  118. https://github.com/neovim/neovim/pull/12741#issuecomment-704677141
  119. - json changes: incompatible API https://github.com/neovim/neovim/pull/4131
  120. - NA files: `src/json*`, `src/testdir/test_json.vim`
  121. - `test_restricted.vim` restricted mode is removed in
  122. https://github.com/neovim/neovim/pull/11996
  123. - Many tests in `test_prompt_buffer.vim` require incompatible Vim features
  124. such as `channel`; they should still be included, but skipped
  125. - non-runtime documentation: Moved to https://neovim.io/doc/,
  126. - NA files: `Filelist`, `README`, `INSTALL`,
  127. - Anything else might be relevant; err on the side of caution, and post an
  128. issue if you aren't sure.
  129. ==============================================================================
  130. VERSION.C *dev-vimpatch-version.c*
  131. The list of Vim patches in `src/nvim/version.c` is automatically updated
  132. https://github.com/neovim/neovim/pull/7780 based on the presence of
  133. `vim-patch:xxx` tokens in the Nvim git log.
  134. - Don't update `src/nvim/version.c` yourself.
  135. - `scripts/vim-patch.sh -p` intentionally omits `version.c` to avoid merge
  136. conflicts and save time when porting a patch.
  137. - The automation script (`scripts/vimpatch.lua`) only recognizes tokens like
  138. `vim-patch:8.0.1206`, not `vim-patch:<hash>`.
  139. ==============================================================================
  140. CODE DIFFERENCES *dev-vimpatch-code-differences*
  141. The following functions have been removed or deprecated in favor of newer
  142. alternatives. See `memory.c`
  143. https://github.com/neovim/neovim/blob/master/src/nvim/memory.c for more
  144. information.
  145. >
  146. -----------------------------------------------------------------------
  147. Deprecated or removed Replacement
  148. -----------------------------------------------------------------------
  149. vim_free xfree
  150. VIM_CLEAR(&foo) XFREE_CLEAR(foo)
  151. malloc alloc lalloc lalloc_id ALLOC_ONE xmalloc
  152. calloc lalloc_clear xcalloc
  153. realloc vim_realloc xrealloc
  154. mch_memmove memmove
  155. vim_memset copy_chars copy_spaces memset
  156. vim_strbyte strchr
  157. vim_strncpy strncpy xstrlcpy/xmemcpyz
  158. vim_strcat strncat xstrlcat
  159. VIM_ISWHITE ascii_iswhite
  160. IS_WHITE_OR_NUL ascii_iswhite_or_nul
  161. vim_isalpha mb_isalpha
  162. vim_isNormalIDc ascii_isident
  163. vim_islower vim_isupper mb_islower mb_isupper
  164. vim_tolower vim_toupper mb_tolower mb_toupper
  165. mb_ptr2len utfc_ptr2len
  166. mb_ptr2len_len utfc_ptr2len_len
  167. mb_char2len utf_char2len
  168. mb_char2bytes utf_char2bytes
  169. mb_ptr2cells utf_ptr2cells
  170. mb_ptr2cells_len utf_ptr2cells_len
  171. mb_char2cells utf_char2cells
  172. mb_off2cells utf_off2cells
  173. mb_ptr2char utf_ptr2char
  174. mb_head_off utf_head_off
  175. mb_tail_off utf_cp_bounds
  176. mb_strnicmp2 utf_strnicmp
  177. MB_STRNICMP2 utf_strnicmp
  178. mb_lefthalve grid_lefthalve
  179. mb_fix_col grid_fix_col
  180. utf_off2cells grid_off2cells
  181. ml_get_curline get_cursor_line_ptr
  182. ml_get_cursor get_cursor_pos_ptr
  183. ml_get_curline_len get_cursor_line_len
  184. ml_get_cursor_len get_cursor_pos_len
  185. screen_char ui_line
  186. screen_line grid_put_linebuf
  187. screen_* (most functions) grid_*
  188. update_prepare, update_finish #9484 removed; use update_screen only
  189. ARRAY_LENGTH ARRAY_SIZE
  190. vim_strsave_escape_csi vim_strsave_escape_ks
  191. vim_unescape_csi vim_unescape_ks
  192. gettail path_tail
  193. mch_isFullName path_is_absolute
  194. script_do_profile profile_init
  195. -----------------------------------------------------------------------
  196. <
  197. Make sure to note the difference between `utf_` and `utfc_` when replacing
  198. `mb_` functions. Also indirect call syntax `(*mb_ptr2len)(...)` should be
  199. replaced with an ordinary function call `utfc_ptr2len(...)`.
  200. >
  201. -----------------------------------------------------------------------
  202. Data type Format (Vim source) Portable format (Nvim source)
  203. ------------ ----------------------- ----------------------------------
  204. long long "%lld" "%" PRId64
  205. size_t "%ld" "%zu"
  206. linenr_T "%ld" "%" PRIdLINENR
  207. -----------------------------------------------------------------------
  208. <
  209. - See also: https://github.com/neovim/neovim/pull/1729#discussion_r22423779
  210. - Vim's `ga_init2` was renamed to `ga_init` and the original `ga_init` is
  211. gone.
  212. - "Old style" Vim tests (`src/testdir/*.in`) should be converted to Lua tests
  213. (see #1286 https://github.com/neovim/neovim/issues/1286 and #1328
  214. https://github.com/neovim/neovim/pull/1328). See Checklist for migrating
  215. legacy tests
  216. https://github.com/neovim/neovim/blob/master/test/README.md#checklist-for-migrating-legacy-tests.
  217. - However, please do not convert "new style" Vim tests
  218. (`src/testdir/*.vim`) to Lua. The "new style" Vim tests are faster than
  219. the old ones, and converting them takes time and effort better spent
  220. elsewhere. Just copy them to `test/old/testdir/*.vim`.
  221. - Conditions that check `enc_utf8` or `has_mbyte` are obsolete (only the
  222. "true" case is applicable).
  223. - `enc_utf8` and `has_mbyte` macros were removed in
  224. https://github.com/neovim/neovim/pull/13293
  225. - Check for `CSI` in typeahead buffer is only necessary in Vim with
  226. `FEAT_GUI`. `CSI` does not have a special meaning in typeahead buffer in
  227. Nvim. (also see https://github.com/neovim/neovim/pull/16936)
  228. ==============================================================================
  229. LIST MANAGEMENT *dev-vimpatch-list-management*
  230. Management of lists (types `list_T` and `listitem_T` from vim) was changed in
  231. https://github.com/neovim/neovim/pull/7708/. There is a lint against the "old"
  232. usage, but here are the most important changes.
  233. Declarations for the table
  234. - `list_T list`: a list
  235. - `listitem_T li`: an item of `list`
  236. - `int val` a value for `lv_copyID`
  237. >
  238. --------------------------------------------------------------------------------------
  239. Old New Comment
  240. ------------------------------- ------------------------------------------------------
  241. list->lv_first tv_list_first(list)
  242. list->lv_last tv_list_last(list)
  243. li->li_next TV_LIST_ITEM_NEXT(list, li) To be avoided if possible, must use list which li belongs to.
  244. li->li_prev TV_LIST_ITEM_PREV(list, li) To be avoided if possible, must use list which li belongs to.
  245. Suggestion by @ZyX-l: Use TV_LIST_ITER or indexing instead of the previous two calls.
  246. list->lv_len tv_list_len(list)
  247. list->lv_lock tv_list_locked(list)
  248. &li->li_tv TV_LIST_ITEM_TV(li)
  249. list->lv_refcount++ tv_list_ref(list)
  250. val = list->lv_copyID val = tv_list_copyid(list)
  251. list->lv_copyID = val tv_list_set_copyid(list, val)
  252. for (li = list->lv_first; TV_LIST_ITER_CONST(list, li, Use TV_LIST_ITER(...) if you need to
  253. li != NULL && another_cond; { if (another_cond) {break;} code}) modify list items (note: assigning copyID is also modification and this happens
  254. li = li->li_next) code always when recursively traversing a list).
  255. --------------------------------------------------------------------------------------
  256. <
  257. For more details and some more advanced usage, see `typval.h` and `typval.c`.
  258. ==============================================================================
  259. DOCUMENTATION DIFFERENCES *dev-vimpatch-documentation*
  260. The following should be removed from all imported documentation, and not be
  261. used in new documentation:
  262. - `{Only when compiled with ...}`: the vast majority of features have been
  263. made non-optional (see https://github.com/neovim/neovim/wiki/Introduction)
  264. ==============================================================================
  265. FILETYPE DETECTION *dev-vimpatch-filetype*
  266. Nvim's filetype detection behavior matches Vim, but is implemented as part of
  267. |vim.filetype| (see `$VIMRUNTIME/lua/vim/filetype.lua`). The logic is encoded in
  268. three tables, listed in order of precedence (the first match is returned):
  269. 1. `filename` for literal full path or basename lookup;
  270. 2. `pattern` for matching filenames or paths against |lua-patterns|, optimized
  271. for fast lookup;
  272. 3. `extension` for literal extension lookup.
  273. Logic that requires checking file contents or buffer variables is implemented
  274. in `$VIMRUNTIME/lua/vim/filetype/detect.lua`.
  275. When porting filetype patches from Vim, keep the following in mind:
  276. Prefer explicit filenames or extensions over patterns, especially for case
  277. insensitive matches (see https://github.com/neovim/neovim/pull/29800): >
  278. "*[mM]akefile" regex -> "makefile", "Makefile" filenames
  279. "*.js\c" regex -> "js", "jS", "Js", "jS" extensions
  280. Pattern matching has several differences:
  281. - It is done using explicit Lua patterns without implicit anchoring instead
  282. of Vim regexes: >
  283. "*/debian/changelog" -> "/debian/changelog$"
  284. "*/bind/db.*" -> "/bind/db%."
  285. <
  286. - Filetype patterns are grouped by their parent pattern to improve matching
  287. performance: If the parent pattern does not match, skip testing all child
  288. patterns. Note that unlike leaf patterns, parent patterns do not have
  289. special matching behaviour if they contain a `/`.
  290. When adding a new filetype with pattern matching, consider the following:
  291. - If there is already a group with appropriate parent pattern, use it.
  292. - If there can be a fast and specific enough pattern to group at least 3
  293. filetype patterns, add it as a separate grouped entry.
  294. New parent patterns should be
  295. - fast: rule of thumb is that it should be a short explicit string
  296. (i.e. no quantifiers or character sets);
  297. - specific: rules of thumb, in order:
  298. - full directory name (e.g., `"/etc/"`, `"/log/"`);
  299. - part of a rare enough directory name (e.g., `"/conf"`, `"git/"`);
  300. - string rarely used in real full paths (e.g., `"nginx"`).
  301. Example:
  302. - Filetype pattern: `".*/etc/a2ps/.*%.cfg"`
  303. - Good parents: `"/etc/"` or `"%.cfg$"`
  304. - Bad parents: `"%."` (fast but not specific) or `"/a2ps/.*%."` (specific
  305. but slow)
  306. When modifying an existing regular pattern, make sure that it still fits its
  307. group.
  308. vim:tw=78:ts=8:noet:ft=help:norl: