Skip to content

Commit

Permalink
Disable context menu by default, add documentation.
Browse files Browse the repository at this point in the history
Users can opt-in to a right-click menu in their ginit.vim file.

Normal Mode:
nnoremap <silent><RightMouse> :call GuiShowContextMenu()<CR>

Insert Mode:
inoremap <silent><RightMouse> <Esc>:call GuiShowContextMenu()<CR>
" <Esc> or <C-O> is required, so the command runs in Normal Mode.
" <Esc> will exit, and <C-O> will remain in Insert Mode.

Visual Modea;
vnoremap <silent><RightMouse> :call GuiShowContextMenu()<CR>gv
" gv causes the selection to persist after the event. The call to
" GuiShowContextMenu wipes the selection, and gv restores it.
  • Loading branch information
jgehrig authored and equalsraf committed May 15, 2019
1 parent 09a3344 commit 663f2b7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
8 changes: 8 additions & 0 deletions src/gui/runtime/doc/nvim_gui_shim.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ This can be used to check for a specific GUI in ginit.vim, e.g.
This is a wrapper around |nvim_get_chan_info()|.

*GuiShowContextMenu()*
Displays a Cut-Copy-Paste context menu at the current cursor position. This
menu can be mapped to right click events in ginit.vim, e.g.
>
nnoremap <silent><RightMouse> :call GuiShowContextMenu()<CR>
inoremap <silent><RightMouse> <Esc>:call GuiShowContextMenu()<CR>
vnoremap <silent><RightMouse> :call GuiShowContextMenu()<CR>gv
==============================================================================
4. Internals

Expand Down
7 changes: 1 addition & 6 deletions src/gui/runtime/plugin/nvim_gui_shim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,6 @@ noremap <script> <Plug>GuiTreeviewToggle :call <SID>TreeViewToggle()
anoremenu <script> Gui.Treeview.Toggle :call <SID>TreeViewShowToggle()

" Show Right-Click ContextMenu
function s:GuiShowContextMenu() range
function GuiShowContextMenu() range
call rpcnotify(0, 'Gui', 'ShowContextMenu')
endfunction

command! -range GuiShowContextMenu call s:GuiShowContextMenu()
nnoremap <silent><RightMouse> :GuiShowContextMenu<CR>
inoremap <silent><RightMouse> :GuiShowContextMenu<CR>
vnoremap <silent><RightMouse> :GuiShowContextMenu<CR>gv

0 comments on commit 663f2b7

Please sign in to comment.