Skip to content

Commit 257964f

Browse files
committed
Do not map <Esc> for popups in terminal Vim
Fixes: #693
1 parent 5114b5f commit 257964f

File tree

3 files changed

+36
-13
lines changed

3 files changed

+36
-13
lines changed

README.md

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -360,15 +360,16 @@ let g:OmniSharp_popup = 0
360360

361361
Apart from the insert-completion documentation window, all popups are closeable/scrollable using these mappings:
362362

363-
| Action name | Default mapping |
364-
|----------------|-----------------|
365-
| `close` | `<Esc>` |
366-
| `lineDown` | `<C-e>` |
367-
| `lineUp` | `<C-y>` |
368-
| `halfPageDown` | `<C-d>` |
369-
| `halfPageUp` | `<C-u>` |
370-
| `pageDown` | `<C-f>` |
371-
| `pageUp` | `<C-b>` |
363+
| Action name | Default mapping |
364+
|---------------------------|-----------------|
365+
| `close` (Gvim, neovim) | `<Esc>`, `gq` |
366+
| `close` (terminal Vim) \* | `gq` |
367+
| `lineDown` | `<C-e>` |
368+
| `lineUp` | `<C-y>` |
369+
| `halfPageDown` | `<C-d>` |
370+
| `halfPageUp` | `<C-u>` |
371+
| `pageDown` | `<C-f>` |
372+
| `pageUp` | `<C-b>` |
372373

373374
Additionally, the signature-help popup window provides the following mappings for navigating through method signatures and selected parameters:
374375

@@ -391,7 +392,17 @@ let g:OmniSharp_popup_mappings = {
391392
\}
392393
```
393394

394-
Popups can be closed by using the `close` action mapping (`<Esc>` by default), and also by simply navigating to another line.
395+
Popups can be closed by using the `close` action mapping (`gq` or `<Esc>` by default), and also by simply navigating to another line.
396+
397+
\* **NOTE:** Vim in the terminal does _not_ have a default `<Esc>` `close` mapping, because `<Esc>` mappings interfere with escape codes in terminal Vim, meaning that key-codes such as arrow keys and `<PageUp>`/`<PageDown>` do not work as expected.
398+
Therefore, terminal Vim only has the `gq` mapping.
399+
Gvim and neovim handle escape codes differently, so are not affected, and have both `gq` and `<Esc>` as default `close` mappings.
400+
401+
If you are happy with this limitation and prefer to use `<Esc>` anyway, configure it in `g:OmniSharp_popup_mappings`:
402+
403+
```vim
404+
let g:OmniSharp_popup_mappings.close = '<Esc>'
405+
```
395406

396407
### Popup options
397408

autoload/OmniSharp/popup.vim

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,10 @@ function s:Open(what, opts) abort
136136
call OmniSharp#popup#Map(mode, 'pageDown', '<C-f>', '<SID>VimPopupScrollPage(1)')
137137
call OmniSharp#popup#Map(mode, 'pageUp', '<C-b>', '<SID>VimPopupScrollPage(-1)')
138138
endif
139-
call OmniSharp#popup#Map(mode, 'close', '<Esc>', '<SID>CloseLast(1)')
139+
let defaultClose = has('nvim') || has('gui_running') ? ['<Esc>', 'gq'] : 'gq'
140+
call OmniSharp#popup#Map(mode, 'close', defaultClose, '<SID>CloseLast(1)')
140141
if mode !=# 'n'
141-
call OmniSharp#popup#Map('n', 'close', '<Esc>', '<SID>CloseLast(1)')
142+
call OmniSharp#popup#Map('n', 'close', defaultClose, '<SID>CloseLast(1)')
142143
endif
143144
augroup OmniSharp_popup_close
144145
autocmd!

doc/omnisharp-vim.txt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ Default: 1 >
267267
Dictionary of popup action mappings.
268268
Defaults: >
269269
let g:OmniSharp_popup_mappings = {
270-
\ 'close': '<Esc>',
270+
\ 'close': ['<Esc>', 'gq']
271271
\ 'lineDown': '<C-e>',
272272
\ 'lineUp': '<C-y>',
273273
\ 'halfPageDown': '<C-d>',
@@ -285,6 +285,17 @@ Apply multiple mappings by providing a list of mappings instead of a string: >
285285
<
286286
Disable individual mappings by assigning an empty array: >
287287
let g:OmniSharp_popup_mappings = { 'sigNext': [] }
288+
<
289+
Note that Vim in the terminal does not have a default "<Esc>" "close" mapping,
290+
because "<Esc>" mappings interfere with escape codes in terminal Vim, meaning
291+
that key-codes such as arrow keys and "<PageUp>"/"<PageDown>" do not work as
292+
expected. Therefore, terminal Vim only has the "gq" mapping.
293+
Gvim and neovim handle escape codes differently, so are not affected, and have
294+
both "gq" and "<Esc>" as default "close" mappings.
295+
296+
If you are happy with this limitation and prefer to use "<Esc>" anyway,
297+
configure it explicitly in |g:OmniSharp_popup_mappings|: >
298+
let g:OmniSharp_popup_mappings.close = '<Esc>'
288299
<
289300
*g:OmniSharp_popup_options*
290301
Dictionary of popup display options. Note that these are different in Vim and

0 commit comments

Comments
 (0)