diff options
author | Yegappan Lakshmanan <yegappan@yahoo.com> | 2021-11-18 22:08:57 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-11-18 22:08:57 +0000 |
commit | 777175b0df8c5ec3cd30d19a2e887e661ac209c8 (patch) | |
tree | 58806429ad4998391464a42f4f4321779642bd2a /runtime | |
parent | 851c7a699ae00bdc14a4db874cf722b7b7393b53 (diff) | |
download | vim-git-777175b0df8c5ec3cd30d19a2e887e661ac209c8.tar.gz |
patch 8.2.3619: cannot use a lambda for 'operatorfunc'v8.2.3619
Problem: Cannot use a lambda for 'operatorfunc'.
Solution: Support using a lambda or partial. (Yegappan Lakshmanan,
closes #8775)
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/doc/map.txt | 14 | ||||
-rw-r--r-- | runtime/doc/options.txt | 20 |
2 files changed, 31 insertions, 3 deletions
diff --git a/runtime/doc/map.txt b/runtime/doc/map.txt index 4b5dd6330..4d23f4a5d 100644 --- a/runtime/doc/map.txt +++ b/runtime/doc/map.txt @@ -1009,6 +1009,20 @@ or `unnamedplus`. The `mode()` function will return the state as it will be after applying the operator. +The `mode()` function will return the state as it will be after applying the +operator. + +Here is an example for using a lambda function to create a normal-mode +operator to add quotes around text in the current line: > + + nnoremap <F4> <Cmd>let &opfunc='{t -> + \ getline(".") + \ ->split("\\zs") + \ ->insert("\"", col("'']")) + \ ->insert("\"", col("''[") - 1) + \ ->join("") + \ ->setline(".")}'<CR>g@ + ============================================================================== 2. Abbreviations *abbreviations* *Abbreviations* diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index a0bbd3bab..b5bccebec 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -371,6 +371,17 @@ Note: In the future more global options can be made global-local. Using ":setlocal" on a global option might work differently then. + *option-value-function* +Some options ('completefunc', 'imactivatefunc', 'imstatusfunc', 'omnifunc', +'operatorfunc', 'quickfixtextfunc' and 'tagfunc') are set to a function name +or a function reference or a lambda function. Examples: +> + set opfunc=MyOpFunc + set opfunc=function("MyOpFunc") + set opfunc=funcref("MyOpFunc") + set opfunc={t\ ->\ MyOpFunc(t)} +< + Setting the filetype :setf[iletype] [FALLBACK] {filetype} *:setf* *:setfiletype* @@ -5623,7 +5634,9 @@ A jump table for the options with a short description can be found at |Q_op|. 'operatorfunc' 'opfunc' string (default: empty) global This option specifies a function to be called by the |g@| operator. - See |:map-operator| for more info and an example. + See |:map-operator| for more info and an example. The value can be + the name of a function, a |lambda| or a |Funcref|. See + |option-value-function| for more information. This option cannot be set from a |modeline| or in the |sandbox|, for security reasons. @@ -6023,8 +6036,9 @@ A jump table for the options with a short description can be found at |Q_op|. customize the information displayed in the quickfix or location window for each entry in the corresponding quickfix or location list. See |quickfix-window-function| for an explanation of how to write the - function and an example. The value can be the name of a function or a - lambda. + function and an example. The value can be the name of a function, a + |lambda| or a |Funcref|. See |option-value-function| for more + information. This option cannot be set from a |modeline| or in the |sandbox|, for security reasons. |