Skip to main content
Module

x/denops_std/function/mod.ts>setreg

📚 Standard module for denops.vim
Go to Latest
function setreg
import { setreg } from "https://deno.land/x/denops_std@v6.4.0/function/mod.ts";

Set the register {regname} to {value}. If {regname} is "" or "@", the unnamed register '"' is used. The {regname} argument is a string. In Vim9-script {regname} must be one character.

{value} may be any value returned by getreg() or getreginfo(), including a List or Dict. If {options} contains "a" or {regname} is upper case, then the value is appended.

{options} can also contain a register type specification: "c" or "v" characterwise mode "l" or "V" linewise mode "b" or "<CTRL-V>" blockwise-visual mode If a number immediately follows "b" or "<CTRL-V>" then this is used as the width of the selection - if it is not specified then the width of the block is set to the number of characters in the longest line (counting a <Tab> as 1 character).

If {options} contains no register settings, then the default is to use character mode unless {value} ends in a <NL> for string {value} and linewise mode for list {value}. Blockwise mode is never selected automatically. Returns zero for success, non-zero for failure.

Note: you may not use List containing more than one item to set search and expression registers. Lists containing no items act like empty strings.

Examples:

:call setreg(v:register, @*)
:call setreg('*', @%, 'ac')
:call setreg('a', "1\n2\n3", 'b5')
:call setreg('"', { 'points_to': 'a'})

This example shows using the functions to save and restore a register:

:let var_a = getreginfo()
:call setreg('a', var_a)

or:

:let var_a = getreg('a', 1, 1)
:let var_amode = getregtype('a')
    ....
:call setreg('a', var_a, var_amode)

Note: you may not reliably restore register value without using the third argument to getreg() as without it newlines are represented as newlines AND Nul bytes are represented as newlines as well, see NL-used-for-Nul.

You can also change the type of a register by appending nothing:

:call setreg('a', '', 'al')

Can also be used as a method, the base is passed as the second argument:

GetText()->setreg('a')

Parameters

denops: Denops
regname: unknown
value: unknown
optional
options: unknown

Returns

Promise<number>