From eb9b93b5e025386ec9431c9d35a4a073d6946d1d Mon Sep 17 00:00:00 2001 From: matveyt <35012635+matveyt@users.noreply.github.com> Date: Sun, 17 Jul 2022 14:14:04 +0300 Subject: feat(defaults): mouse=nvi #19290 Problem: Since right-click can now show a popup menu, we can provide messaging to guide users who expect 'mouse' to be disabled by default. So 'mouse' can now be enabled by default. Solution: Do it. Closes #15521 --- runtime/doc/gui.txt | 13 +++++++++++++ runtime/doc/options.txt | 6 +++--- runtime/doc/starting.txt | 2 +- runtime/doc/vim_diff.txt | 26 ++++++++++++++++++++++++++ runtime/lua/vim/_editor.lua | 38 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 81 insertions(+), 4 deletions(-) (limited to 'runtime') diff --git a/runtime/doc/gui.txt b/runtime/doc/gui.txt index 5badd954d9..776ff228d6 100644 --- a/runtime/doc/gui.txt +++ b/runtime/doc/gui.txt @@ -441,6 +441,19 @@ You can define the special menu "PopUp". This is the menu that is displayed when the right mouse button is pressed, if 'mousemodel' is set to popup or popup_setpos. +The default "PopUp" menu is: > + aunmenu PopUp + vnoremenu PopUp.Cut "+x + vnoremenu PopUp.Copy "+y + anoremenu PopUp.Paste "+gP + vnoremenu PopUp.Paste "+P + vnoremenu PopUp.Delete "_x + nnoremenu PopUp.Select\ All> ggVG + vnoremenu PopUp.Select\ All> gg0oG$ + inoremenu PopUp.Select\ All VG + anoremenu PopUp.-1- + anoremenu PopUp.How-to\ disable\ mouse help disable-mouse +< Showing What Menus Are Mapped To *showing-menus* diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index 74ba353e0a..0f1c2051a6 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -4086,7 +4086,7 @@ A jump table for the options with a short description can be found at |Q_op|. listing continues until finished. *'mouse'* -'mouse' string (default "") +'mouse' string (default "nvi") global Enables mouse support. For example, to enable the mouse in Normal mode @@ -4158,7 +4158,7 @@ A jump table for the options with a short description can be found at |Q_op|. The mouse pointer is restored when the mouse is moved. *'mousemodel'* *'mousem'* -'mousemodel' 'mousem' string (default "extend") +'mousemodel' 'mousem' string (default "popup_setpos") global Sets the model to use for the mouse. The name mostly specifies what the right mouse button is used for: @@ -4184,7 +4184,7 @@ A jump table for the options with a short description can be found at |Q_op|. middle click paste paste In the "popup" model the right mouse button produces a pop-up menu. - You need to define this first, see |popup-menu|. + Nvim creates a default |popup-menu| but you can redefine it. Note that you can further refine the meaning of buttons with mappings. See |mouse-overview|. But mappings are NOT used for modeless selection. diff --git a/runtime/doc/starting.txt b/runtime/doc/starting.txt index 108a47c522..d57a85423c 100644 --- a/runtime/doc/starting.txt +++ b/runtime/doc/starting.txt @@ -407,7 +407,7 @@ accordingly, proceeding as follows: Nvim started with |--embed| waits for the UI to connect before proceeding to load user configuration. -4. Setup |default-mappings| and |default-autocmds|. +4. Setup |default-mappings| and |default-autocmds|. Create |popup-menu|. 5. Enable filetype and indent plugins. This does the same as the command: > diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt index bacf160206..a74149d050 100644 --- a/runtime/doc/vim_diff.txt +++ b/runtime/doc/vim_diff.txt @@ -52,6 +52,8 @@ centralized reference of the differences. - 'langremap' is disabled - 'laststatus' defaults to 2 (statusline is always shown) - 'listchars' defaults to "tab:> ,trail:-,nbsp:+" +- 'mouse' defaults to "nvi" +- 'mousemodel' defaults to "popup_setpos" - 'nrformats' defaults to "bin,hex" - 'ruler' is enabled - 'sessionoptions' includes "unix,slash", excludes "options" @@ -78,6 +80,30 @@ centralized reference of the differences. - |g:vimsyn_embed| defaults to "l" to enable Lua highlighting +Default Mouse ~ + *default-mouse* *disable-mouse* +By default the mouse is enabled. The right button click opens |popup-menu| +with standard actions, such as "Cut", "Copy" and "Paste". + +If you don't like this you can add to your |config| any of the following: + +- ignore mouse completely > + set mouse= +< +- no |popup-menu| but the right button extends selection > + set mousemodel=extend +> +- pressing ALT+LeftMouse releases mouse until main cursor moves > + nnoremap + \ set mouse= + \ echo 'mouse OFF until next cursor-move' + \ autocmd CursorMoved * ++once set mouse& + \ echo 'mouse ON' +< +Also, mouse is not in use in |command-mode| or at |more-prompt|. So if you +need to copy/paste with your terminal then just pressing ':' makes Nvim to +release the mouse cursor temporarily. + Default Mappings ~ *default-mappings* Nvim creates the following default mappings at |startup|. You can disable any diff --git a/runtime/lua/vim/_editor.lua b/runtime/lua/vim/_editor.lua index 7febad6ef6..c4cc151bca 100644 --- a/runtime/lua/vim/_editor.lua +++ b/runtime/lua/vim/_editor.lua @@ -810,6 +810,44 @@ function vim.deprecate(name, alternative, version, plugin, backtrace) end end +--- Create builtin mappings (incl. menus). +--- Called once on startup. +function vim._init_default_mappings() + -- mappings + + --@private + local function map(mode, lhs, rhs) + vim.api.nvim_set_keymap(mode, lhs, rhs, { noremap = true, desc = 'Nvim builtin' }) + end + + map('n', 'Y', 'y$') + -- Use normal! to prevent inserting raw when using i_. #17473 + map('n', '', 'nohlsearchdiffupdatenormal! ') + map('i', '', 'u') + map('i', '', 'u') + map('x', '*', 'y/\\V"') + map('x', '#', 'y?\\V"') + -- Use : instead of so that ranges are supported. #19365 + map('n', '&', ':&&') + + -- menus + + -- TODO VimScript, no l10n + vim.cmd([[ + aunmenu * + vnoremenu PopUp.Cut "+x + vnoremenu PopUp.Copy "+y + anoremenu PopUp.Paste "+gP + vnoremenu PopUp.Paste "+P + vnoremenu PopUp.Delete "_x + nnoremenu PopUp.Select\ All ggVG + vnoremenu PopUp.Select\ All gg0oG$ + inoremenu PopUp.Select\ All VG + anoremenu PopUp.-1- + anoremenu PopUp.How-to\ disable\ mouse help disable-mouse + ]]) +end + require('vim._meta') return vim -- cgit