diff --git a/README.md b/README.md index faa6c5f..32dda98 100644 --- a/README.md +++ b/README.md @@ -428,10 +428,10 @@ Mapping | Action `` | Cursor one character right `/` | Move cursor to the end of line `/` | Move cursor to the beginning of line -`` | Delete characters between cursor and beginning of line -`` | Delete word before the cursor `/` | Cursor one WORD left `/` | Cursor one WORD right +`` | Delete characters between cursor and beginning of line +`` | Delete word before the cursor `/` | Recall history previous `/` | Recall history next `` | Insert word under cursor (``) into prompt @@ -439,6 +439,30 @@ Mapping | Action `` | Insert line under cursor into prompt `` {register} | Insert the contents of a numbered or named register. Between typing CTRL-R and the second character '"' will be displayed to indicate that you are expected to enter the name of a register. +To enable emacs-style editing in the prompt window, set the option `emacsKeys` to `true` as follows: + +```vim +scope#popup#OptionsSet({emacsKeys: true}) +``` + +or, + +```vim +import autoload 'scope/popup.vim' as sp +sp.OptionsSet({emacsKeys: true}) +``` + +When emacs-style editing is enabled, following keybinding take effect: + +Mapping | Action +--------|------- +`/` | Cursor one character left +`/` | Cursor one character right +`/` | Move cursor to the end of line +`/` | Move cursor to the beginning of line +`//` | Cursor one WORD left +`//` | Cursor one WORD right + # Requirements - Vim version 9.1 or higher diff --git a/autoload/scope/popup.vim b/autoload/scope/popup.vim index 221f26d..b1ce1f0 100644 --- a/autoload/scope/popup.vim +++ b/autoload/scope/popup.vim @@ -14,6 +14,7 @@ export var options = { maxwidth: -1, promptchar: '>', # cursorchar: '█', + emacsKeys: false, } export def OptionsSet(opt: dict) @@ -159,7 +160,7 @@ export class FilterMenu # close the popup window for when popup window is empty id->popup_close(-1) endif - elseif key == "\" || key == "\" + elseif key == "\" || key == "\" || (options.emacsKeys && key == "\") if this.idp->getmatches()->indexof((_, v) => v.group == 'ScopeMenuVirtualText') != -1 # virtual text present. grep using virtual text. this.prompt = this.idp->getwininfo()[0].bufnr->getbufline(1)[0]->slice(2) @@ -168,7 +169,7 @@ export class FilterMenu [this.items_dict, this.filtered_items] = GetFilteredItemsFn(this.items_dict, this.prompt) this._SetPopupContent() else - if key == "\" + if key == "\" || (options.emacsKeys && key == "\") if this.cursorpos < (3 + this.prompt->strcharlen()) this.cursorpos = this.cursorpos + 1 this._CursorSet() @@ -177,12 +178,12 @@ export class FilterMenu win_execute(id, 'normal! ' .. "\") endif endif - elseif key == "\" + elseif key == "\" || (options.emacsKeys && key == "\") if this.cursorpos > 3 this.cursorpos = this.cursorpos - 1 this._CursorSet() endif - elseif key == "\" || key == "\" + elseif key == "\" || key == "\" || (options.emacsKeys && key == "\") if this.cursorpos < (3 + this.prompt->strcharlen()) var pos = this.cursorpos - 3 var byteidx = this.prompt->stridx(' ', this.prompt->byteidx(pos) + 1) @@ -193,7 +194,7 @@ export class FilterMenu endif this._CursorSet() endif - elseif key == "\" || key == "\" + elseif key == "\" || key == "\" || (options.emacsKeys && key == "\") if this.cursorpos > 3 var pos = this.cursorpos - 3 if pos > 1 && this.prompt[pos - 1] == ' ' && this.prompt[pos - 2] == ' ' @@ -206,7 +207,7 @@ export class FilterMenu endif elseif key == "\" win_execute(id, 'normal! ' .. "\") - elseif key == "\" || key == "\" + elseif key == "\" || (!options.emacsKeys && key == "\") || (options.emacsKeys && key == "\") if this.cursorpos > 3 this.cursorpos = 3 this._CursorSet()