aboutsummaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2022-08-21 22:01:00 -0600
committerJosh Rahm <joshuarahm@gmail.com>2022-08-21 22:01:00 -0600
commit5b0e381a261b1450735f4eddac55aeb956c13713 (patch)
treec61f6f14f8b5dc9e2d2f8ed1f78f50179ae3b33a /runtime
parentd5cc161deac2371a39821c94fd2de4f1c41b6eb9 (diff)
downloadrneovim-5b0e381a261b1450735f4eddac55aeb956c13713.tar.gz
rneovim-5b0e381a261b1450735f4eddac55aeb956c13713.tar.bz2
rneovim-5b0e381a261b1450735f4eddac55aeb956c13713.zip
feat(userreg): Add user-defined registers to Neovim.
This change unlocks additional registers for Neovim by allowing a user to define their own behavior for non-builtin registers. This is accopmlished through a new option 'userregfunc' The 'userregfunc' defines the function to call when handling a register for which there is no builtin functionality. The 'userregfunc' function should take 3 arguments: action - Either "yank" or "put" register - The character corresponding to the register content - In the case of action == "yank", the dictionary describing the yanked content, with the following keys: {type} - Either "char", "line" or "block" {lines} - The lines being yanked as a list {width} - The width in case of "block" mode. {additional_data} - Additional data (can be returned in "put" mode) In case of "put" this function should return the content to put. This content can be either: * A dictionary in the same template as content above. * A list of strings. This will be assumed to be "line" mode. * A string. This will be assumed to be "char" mode. An example of a "null" 'userregfunc' that provides an implementation identical to traditional vim registers would be: let s:contents = {} function! MyUserregFunction(action, register, content) abort if a:action == "put" return get(s:contents, a:register, "") else let s:contents[a:register] = a:content endif endfunction set userregfun=MyUserregFunction It is important to note that any valid unicode character can now be a register, including something like @☺. This change also addresses the multibyte parsing issues surrounding let @a = 'xyz' let @🔨 = 'hammer'
Diffstat (limited to 'runtime')
-rw-r--r--runtime/doc/options.txt51
1 files changed, 51 insertions, 0 deletions
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
index 2e0c1f8cc4..22d8d7fe1a 100644
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -6722,6 +6722,57 @@ A jump table for the options with a short description can be found at |Q_op|.
written to disk (see |crash-recovery|). Also used for the
|CursorHold| autocommand event.
+ *'userregfun'* *'urf'*
+'userregfun' 'urf' string (default "")
+ global
+ The option specifies a function to be used to handle any registers
+ that Neovim does not natively handle. This option unlocks all
+ characters to be used as registers by the user.
+
+ The 'userregfun' function is called each time a user register is read
+ from or written to.
+
+ The 'userregfun' function must take the following parameters:
+
+ {action} The action being done on this register (either 'yank'
+ or 'put'
+
+ {register} The string holding the name of the register. This
+ is always a single character, though multi-byte
+ characters are allowed.
+
+ {content} If the action is 'yank' this is the content being
+ yanked into the register. The content is a dictionary
+ with the following items:
+
+ {lines} The lines being yanked, as a list.
+
+ {type} The type of yank, either "line", "char", or
+ "block"
+
+ {width} The width in case of "block" mode.
+
+ {additional_data} Additional data. (can be returned in
+ put mode).
+
+ In case the action is 'put', the 'userregfun' function should return
+ the content to place in that location. The content can either be a
+ string, in which case "char" mode is inferred, or it can return a
+ dictionary of the same template that populates 'content'.
+
+ A very simple example of a 'userregfun' function that behaves exactly
+ like traditional registers would look like: >
+
+ let s:contents = {}
+ function! MyUserregFunction(action, register, content) abort
+ if a:action == "put"
+ return get(s:contents, a:register, "")
+ else
+ let s:contents[a:register] = a:content
+ endif
+ endfunction
+ set userregfun=MyUserregFunction
+<
*'varsofttabstop'* *'vsts'*
'varsofttabstop' 'vsts' string (default "")
local to buffer