vim: Don't move cursor when activating window
dblume

dblume commited on 2025-01-27 13:45:34
Showing 2 changed files, with 15 additions and 0 deletions.


https://vim.fandom.com/wiki/How_to_not_move_cursor_when_selecting_window_with_mouse
... ...
@@ -99,6 +99,13 @@ au InsertLeave * hi statusline term=bold,reverse cterm=bold,reverse ctermfg=23 c
99 99
 " See https://neovim.io/doc/user/vim_diff.html#_default-mouse
100 100
 " set mouse=  " neovim defaults to nvi
101 101
 
102
+" Don't move the cursor when activating window (incompatible on PuTTY)
103
+augroup NO_CURSOR_MOVE_ON_FOCUS
104
+  au!
105
+  au FocusLost * let g:oldmouse=&mouse | set mouse=
106
+  au FocusGained * if exists('g:oldmouse') | let &mouse=g:oldmouse | unlet g:oldmouse | endif
107
+augroup END
108
+
102 109
 " Set jump point from before mouse click.
103 110
 nnoremap <LeftMouse> m'<LeftMouse>
104 111
 inoremap <LeftMouse> <Esc>m'<LeftMouse>
... ...
@@ -107,6 +107,14 @@ au InsertEnter * hi statusline guibg=Cyan ctermfg=25 guifg=Black ctermbg=248
107 107
 au InsertLeave * hi statusline term=bold,reverse cterm=bold,reverse ctermfg=23 ctermbg=250 guifg=black guibg=#c2bfa5
108 108
 
109 109
 set mouse=nvi  " Matches neovim's default
110
+
111
+" Don't move the cursor when activating window (incompatible on PuTTY)
112
+augroup NO_CURSOR_MOVE_ON_FOCUS
113
+  au!
114
+  au FocusLost * let g:oldmouse=&mouse | set mouse=
115
+  au FocusGained * if exists('g:oldmouse') | let &mouse=g:oldmouse | unlet g:oldmouse | endif
116
+augroup END
117
+
110 118
 " Set jump point from before mouse click.
111 119
 nnoremap <LeftMouse> m'<LeftMouse>
112 120
 inoremap <LeftMouse> <Esc>m'<LeftMouse>
113 121