summaryrefslogtreecommitdiffstatshomepage
path: root/src/nvim/cursor.c
AgeCommit message (Collapse)AuthorFiles
2026-04-21fix(move): avoid integer overflow with large 'scrolloff' (#39251)zeertzjq1
2026-04-04vim-patch:9.2.0289: 'linebreak' may lead to wrong Visual block highlighting ↵zeertzjq1
(#38749) Problem: 'linebreak' may lead to wrong Visual block highlighting when end char occupies multiple cells (after 7.4.467). Solution: Exclude 'linebreak' from the ending column instead of setting 'virtualedit' temporarily (zeertzjq). fixes: vim/vim#19898 closes: vim/vim#19900 https://github.com/vim/vim/commit/23be1889d1a1212445ca8bb9cd378484d3755f79
2025-12-20docs: misc, lspJustin M. Keyes1
2025-10-08vim-patch:9.1.1836: 'culopt' "screenline" not redrawn with line("w0") and :retabzeertzjq1
Problem: 'cursorlineopt' "screenline" isn't redrawn when moving cursor and then using line("w0") and :retab that does nothing. Solution: Call redraw_for_cursorcolumn() when setting a valid w_virtcol (zeertzjq). closes: vim/vim#18506 https://github.com/vim/vim/commit/a0849143614e687a305b6195dd8724840786e372
2025-08-14refactor(build): remove INCLUDE_GENERATED_DECLARATIONS guardsbfredl1
These are not needed after #35129 but making uncrustify still play nice with them was a bit tricky. Unfortunately `uncrustify --update-config-with-doc` breaks strings with backslashes. This issue has been reported upstream, and in the meanwhile auto-update on every single run has been disabled.
2025-08-03vim-patch:9.1.1590: cannot perform autocompletion (#35141)zeertzjq1
Problem: cannot perform autocompletion Solution: Add the 'autocomplete' option value (Girish Palya) This change introduces the 'autocomplete' ('ac') boolean option to enable automatic popup menu completion during insert mode. When enabled, Vim shows a completion menu as you type, similar to pressing |i\_CTRL-N| manually. The items are collected from sources defined in the 'complete' option. To ensure responsiveness, this feature uses a time-sliced strategy: - Sources earlier in the 'complete' list are given more time. - If a source exceeds its allocated timeout, it is interrupted. - The next source is then started with a reduced timeout (exponentially decayed). - A small minimum ensures every source still gets a brief chance to contribute. The feature is fully compatible with other |i_CTRL-X| completion modes, which can temporarily suspend automatic completion when triggered. See :help 'autocomplete' and :help ins-autocompletion for more details. To try it out, use :set ac You should see a popup menu appear automatically with suggestions. This works seamlessly across: - Large files (multi-gigabyte size) - Massive codebases (:argadd thousands of .c or .h files) - Large dictionaries via the `k` option - Slow or blocking LSP servers or user-defined 'completefunc' Despite potential slowness in sources, the menu remains fast, responsive, and useful. Compatibility: This mode is fully compatible with existing completion methods. You can still invoke any CTRL-X based completion (e.g., CTRL-X CTRL-F for filenames) at any time (CTRL-X temporarily suspends 'autocomplete'). To specifically use i_CTRL-N, dismiss the current popup by pressing CTRL-E first. --- How it works To keep completion snappy under all conditions, autocompletion uses a decaying time-sliced algorithm: - Starts with an initial timeout (80ms). - If a source does not complete within the timeout, it's interrupted and the timeout is halved for the next source. - This continues recursively until a minimum timeout (5ms) is reached. - All sources are given a chance, but slower ones are de-prioritized quickly. Most of the time, matches are computed well within the initial window. --- Implementation details - Completion logic is mostly triggered in `edit.c` and handled in insexpand.c. - Uses existing inc_compl_check_keys() mechanism, so no new polling hooks are needed. - The completion system already checks for user input periodically; it now also checks for timer expiry. --- Design notes - The menu doesn't continuously update after it's shown to prevent visual distraction (due to resizing) and ensure the internal list stays synchronized with the displayed menu. - The 'complete' option determines priority—sources listed earlier get more time. - The exponential time-decay mechanism prevents indefinite collection, contributing to low CPU usage and a minimal memory footprint. - Timeout values are intentionally not configurable—this system is optimized to "just work" out of the box. If autocompletion feels slow, it typically indicates a deeper performance bottleneck (e.g., a slow custom function not using `complete_check()`) rather than a configuration issue. --- Performance Based on testing, the total roundtrip time for completion is generally under 200ms. For common usage, it often responds in under 50ms on an average laptop, which falls within the "feels instantaneous" category (sub-100ms) for perceived user experience. | Upper Bound (ms) | Perceived UX |----------------- |------------- | <100 ms | Excellent; instantaneous | <200 ms | Good; snappy | >300 ms | Noticeable lag | >500 ms | Sluggish/Broken --- Why this belongs in core: - Minimal and focused implementation, tightly integrated with existing Insert-mode completion logic. - Zero reliance on autocommands and external scripting. - Makes full use of Vim’s highly composable 'complete' infrastructure while avoiding the complexity of plugin-based solutions. - Gives users C native autocompletion with excellent responsiveness and no configuration overhead. - Adds a key UX functionality in a simple, performant, and Vim-like way. closes: vim/vim#17812 https://github.com/vim/vim/commit/af9a7a04f18693eee4400dd134135527f4e8cd5f Co-authored-by: Girish Palya <girishji@gmail.com>
2025-04-28refactor(ui): separate types for allocated grids and viewportsbfredl1
2025-02-13vim-patch:9.1.1108: 'smoothscroll' gets stuck with 'listchars' "eol" (#32434)zeertzjq1
Problem: 'smoothscroll' gets stuck with 'listchars' "eol". Solution: Count size of 'listchars' "eol" in line size when scrolling. (zeertzjq) related: neovim/neovim#32405 closes: vim/vim#16627 https://github.com/vim/vim/commit/2c47ab8fcd7188fa87053c757ea86b0d846c06c1
2024-12-23refactor: iwyu #31637Justin M. Keyes1
Result of `make iwyu` (after some "fixups").
2024-12-17feat(terminal)!: cursor shape and blink (#31562)Gregory Anders1
When a terminal application running inside the terminal emulator sets the cursor shape or blink status of the cursor, update the cursor in the parent terminal to match. This removes the "virtual cursor" that has been in use by the terminal emulator since the beginning. The original rationale for using the virtual cursor was to avoid having to support additional UI methods to change the cursor color for other (non-TUI) UIs, instead relying on the TermCursor and TermCursorNC highlight groups. The TermCursor highlight group is now used in the default 'guicursor' value, which has a new entry for Terminal mode. However, the TermCursorNC highlight group is no longer supported: since terminal windows now use the real cursor, when the window is not focused there is no cursor displayed in the window at all, so there is nothing to highlight. Users can still use the StatusLineTermNC highlight group to differentiate non-focused terminal windows. BREAKING CHANGE: The TermCursorNC highlight group is no longer supported.
2024-11-23refactor(options): autogenerate valid values and flag enums for options (#31089)Famiu Haque1
Problem: Option metadata like list of valid values for an option and option flags are not listed in the `options.lua` file and are instead manually defined in C, which means option metadata is split between several places. Solution: Put metadata such as list of valid values for an option and option flags in `options.lua`, and autogenerate the corresponding C variables and enums. Supersedes #28659 Co-authored-by: glepnir <glephunter@gmail.com>
2024-07-30refactor: collapse statements in single assignmentsLewis Russell1
Problem: Variables are often assigned multiple places in common patterns. Solution: Replace these common patterns with different patterns that reduce the number of assignments. Use `MAX` and `MIN`: ```c if (x < y) { x = y; } // --> x = MAX(x, y); ``` ```c if (x > y) { x = y; } // --> x = MIN(x, y); ``` Use ternary: ```c int a; if (cond) { a = b; } els { a = c; } // --> int a = cond ? b : c; ```
2024-05-15docs: misc (#28609)dundargoc1
Closes https://github.com/neovim/neovim/issues/28484. Closes https://github.com/neovim/neovim/issues/28719. Co-authored-by: Chris <crwebb85@gmail.com> Co-authored-by: Gregory Anders <greg@gpanders.com> Co-authored-by: Jake B <16889000+jakethedev@users.noreply.github.com> Co-authored-by: Jonathan Raines <jonathan.s.raines@gmail.com> Co-authored-by: Yi Ming <ofseed@foxmail.com> Co-authored-by: Zane Dufour <zane@znd4.me> Co-authored-by: zeertzjq <zeertzjq@outlook.com>
2024-03-14vim-patch:9.1.0172: More code can use ml_get_buf_len() instead of STRLEN()zeertzjq1
Problem: More code can use ml_get_buf_len() instead of STRLEN(). Solution: Change more STRLEN() calls to ml_get_buf_len(). Also do not set ml_line_textlen in ml_replace_len() if "has_props" is set, because "len_arg" also includes the size of text properties in that case. (zeertzjq) closes: vim/vim#14183 https://github.com/vim/vim/commit/94b7c3233ef534acc669b3083ed1fe59cf3a090b
2024-03-13fix(api/buffer): fix handling of viewport of non-current bufferbfredl1
A lot of functions in move.c only worked for curwin, alternatively took a `wp` arg but still only work if that happens to be curwin. Refactor those that are needed for update_topline(wp) to work for any window. fixes #27723 fixes #27720
2024-03-10vim-patch:9.1.0138: too many STRLEN calls when getting a memline (#27799)zeertzjq1
Problem: too many STRLEN calls when getting a memline Solution: Optimize calls to STRLEN(), add a few functions in memline.c that return the byte length instead of relying on STRLEN() (John Marriott) closes: vim/vim#14052 https://github.com/vim/vim/commit/02d7a6c6cfceb3faf9c98fcb7c458760cd50d269 Cherry-pick line break changes from patch 8.1.0226. Cherry-pick ml_line_len from patch 8.1.0579. Cherry-pick test_comments.vim change from patch 9.1.0153. Co-authored-by: John Marriott <basilisk@internode.on.net>
2024-01-25refactor: IWYU (#27186)zeertzjq1
2024-01-22refactor: use "csarg" for CharsizeArg variables (#27123)zeertzjq1
2024-01-22perf: reuse fast character size calculation algorithm from getvcol()VanaIgr1
2024-01-11refactor(IWYU): fix headersdundargoc1
Remove `export` pramgas from defs headers as it causes IWYU to believe that the definitions from the defs headers comes from main header, which is not what we really want.
2023-12-30refactor: follow style guidedundargoc1
2023-12-21refactor: run IWYU on entire repodundargoc1
Reference: https://github.com/neovim/neovim/issues/6371.
2023-12-20refactor: eliminate cyclic includesdundargoc1
2023-11-28refactor: fix headers with IWYUdundargoc1
2023-11-27build(IWYU): fix includes for undo_defs.hdundargoc1
2023-11-17vim-patch:9.0.2107: [security]: FPE in adjust_plines_for_skipcol (#26082)zeertzjq1
Problem: [security]: FPE in adjust_plines_for_skipcol Solution: don't divide by zero, return zero Prevent a floating point exception when calculating w_skipcol (which can happen with a small window when the number option is set and cpo+=n). Add a test to verify https://github.com/vim/vim/commit/cb0b99f0672d8446585d26e998343dceca17d1ce Co-authored-by: Christian Brabandt <cb@256bit.org>
2023-11-12build: remove PVSdundargoc1
We already have an extensive suite of static analysis tools we use, which causes a fair bit of redundancy as we get duplicate warnings. PVS is also prone to give false warnings which creates a lot of work to identify and disable.
2023-09-30refactor: reorganize option header files (#25437)zeertzjq1
- Move vimoption_T to option.h - option_defs.h is for option-related types - option_vars.h corresponds to Vim's option.h - option_defs.h and option_vars.h don't include each other
2023-09-30build(iwyu): add a few more _defs.h mappings (#25435)zeertzjq1
2023-08-27vim-patch:9.0.1792: problem with gj/gk/gM and virtual text (#24898)zeertzjq1
Problem: Normal mode "gM", "gj", "gk" commands behave incorrectly with virtual text. Solution: Use linetabsize() instead of linetabsize_str(). closes: vim/vim#12909 https://github.com/vim/vim/commit/d809c0a90387a23aed21ba37d0b65332fb5dafe7
2023-08-26refactor(change): do API changes to buffer without curbuf switchbfredl1
Most of the messy things when changing a non-current buffer is not about the buffer, it is about windows. In particular, it is about `curwin`. When editing a non-current buffer which is displayed in some other window in the current tabpage, one such window will be "borrowed" as the curwin. But this means if two or more non-current windows displayed the buffers, one of them will be treated differenty. this is not desirable. In particular, with nvim_buf_set_text, cursor _column_ position was only corrected for one single window. Two new tests are added: the test with just one non-current window passes, but the one with two didn't. Two corresponding such tests were also added for nvim_buf_set_lines. This already worked correctly on master, but make sure this is well-tested for future refactors. Also, nvim_create_buf no longer invokes autocmds just because you happened to use `scratch=true`. No option value was changed, therefore OptionSet must not be fired.
2023-08-24refactor(memline): distinguish mutating uses of ml_get_buf()bfredl1
ml_get_buf() takes a third parameters to indicate whether the caller wants to mutate the memline data in place. However the vast majority of the call sites is using this function just to specify a buffer but without any mutation. This makes it harder to grep for the places which actually perform mutation. Solution: Remove the bool param from ml_get_buf(). it now works like ml_get() except for a non-current buffer. Add a new ml_get_buf_mut() function for the mutating use-case, which can be grepped along with the other ml_replace() etc functions which can modify the memline.
2023-08-17refactor: cast to int earlier when using 'so' and 'siso' (#24756)zeertzjq1
2023-05-02vim-patch:9.0.0901: setting w_leftcol and handling side effects is confusingLuuk van Baal1
Problem: Setting w_leftcol and handling side effects is confusing. Solution: Use a function to set w_leftcol() and handle side effects. https://github.com/vim/vim/commit/0c34d562647f029faca40f7733ccfb7b5377672b Co-authored-by: Bram Moolenaar <Bram@vim.org>
2023-05-02vim-patch:9.0.0751: 'scrolloff' does not work well with 'smoothscroll'Luuk van Baal1
Problem: 'scrolloff' does not work well with 'smoothscroll'. Solution: Make positioning the cursor a bit better. Rename functions. https://github.com/vim/vim/commit/c9121f798f49fa71e814912cb186d89c164090c3 Co-authored-by: Bram Moolenaar <Bram@vim.org>
2023-04-26refactor: uncrustifydundargoc1
Notable changes: replace all infinite loops to `while(true)` and remove `int` from `unsigned int`.
2023-02-11refactor: replace char_u with char (#21901)dundargoc1
refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459
2023-01-14refactor: replace char_u with char 21 (#21779)dundargoc1
refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459
2022-11-23fix(options): fix local 'sidescrolloff' doesn't work for mouse (#21162)zeertzjq1
Missing part of Vim patch 8.1.0864.
2022-11-19refactor: replace char_u with charDundar Göc1
Work on https://github.com/neovim/neovim/issues/459
2022-11-15build: allow IWYU to fix includes for all .c filesdundargoc1
Allow Include What You Use to remove unnecessary includes and only include what is necessary. This helps with reducing compilation times and makes it easier to visualise which dependencies are actually required. Work on https://github.com/neovim/neovim/issues/549, but doesn't close it since this only works fully for .c files and not headers.
2022-09-11refactor: replace char_u with charDundar Göc1
Work on https://github.com/neovim/neovim/issues/459
2022-09-06refactor: replace char_u with charDundar Göc1
Work on https://github.com/neovim/neovim/issues/459
2022-09-01refactor: replace char_u with charDundar Göc1
Work on https://github.com/neovim/neovim/issues/459
2022-08-31refactor: replace char_u with charDundar Göc1
Work on https://github.com/neovim/neovim/issues/459
2022-08-29refactor(plines): use a struct for chartabsize statebfredl1
This is a refactor extracted from vim-patch 9.0.0067: cannot show virtual text The logic for inline virtual text is going to be different in nvim than text property based text in vim, but this refactor is still useful, as calculation of displayed linesize is going to be stateful in a similar way.
2022-08-23vim-patch:9.0.0206: redraw flags are not named specifically (#19913)zeertzjq1
Problem: Redraw flags are not named specifically. Solution: Prefix "UPD_" to the flags, for UPDate_screen(). https://github.com/vim/vim/commit/a4d158b3c839e96ed98ff87c7b7124ff4518c4ff
2022-08-19vim-patch:8.1.2057: the screen.c file is much too bigLewis Russell1
Problem: The screen.c file is much too big. Solution: Split it in three parts. (Yegappan Lakshmanan, closes vim/vim#4943) https://github.com/vim/vim/commit/7528d1f6b5422750eb778dfb550cfd0b0e540964 This is an approximation vim-patch 8.1.2057. Applying the patch directly isn't feasible since our version of screen.c has diverged too much, however we still introduce drawscreen.c and drawline.c: - screen.c is now a much smaller file used for low level screen functions - drawline.c contains everything needed for win_line() - drawscreen.c contains everything needed for update_screen() Co-authored-by: zeertzjq <zeertzjq@outlook.com>
2022-05-17vim-patch:8.2.4969: changing text in Visual mode may cause invalid memory accesszeertzjq1
Problem: Changing text in Visual mode may cause invalid memory access. Solution: Check the Visual position after making a change. https://github.com/vim/vim/commit/7ce5b2b590256ce53d6af28c1d203fb3bc1d2d97
2022-05-10vim-patch:8.2.4911: the mode #defines are not clearly named (#18499)zeertzjq1
Problem: The mode #defines are not clearly named. Solution: Prepend MODE_. Renumber them to put the mapped modes first. https://github.com/vim/vim/commit/249591057b4840785c50e41dd850efb8a8faf435 A hunk from the patch depends on patch 8.2.4861, which hasn't been ported yet, but that should be easy to notice.