robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. Keyesdocs: misc, remove some old help tags #40214446b9d8c55

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