Mercurial > vim
comparison runtime/doc/builtin.txt @ 34451:d06ffca91441 v9.1.0142
patch 9.1.0142: getregion() can be improved
Commit: https://github.com/vim/vim/commit/19b718828d8d5fab52d94c6cdba694641879ab38
Author: Shougo Matsushita <Shougo.Matsu@gmail.com>
Date: Wed Feb 28 22:48:12 2024 +0100
patch 9.1.0142: getregion() can be improved
Problem: getregion() can be improved (after v9.1.120)
Solution: change getregion() implementation to use pos as lists and
one optional {opt} dictionary (Shougo Matsushita)
Note: The following is a breaking change!
Currently, the getregion() function (included as of patch v9.1.120) takes
3 arguments: the first 2 arguments are strings, describing a position,
arg3 is the type string.
However, that is slightly inflexible, there is no way to specify
additional arguments. So let's instead change the function signature to:
getregion(pos1, pos2 [, {Dict}]) where both pos1 and pos2 are lists.
This is slightly cleaner, and gives us the flexibility to specify
additional arguments as key/value pairs to the optional Dict arg.
Now it supports the "type" key to specify the selection type
(characterwise, blockwise or linewise) and now in addition one can also
define the selection type, independently of what the 'selection' option
actually is.
Technically, this is a breaking change, but since the getregion()
Vimscript function is still quite new, this should be fine.
closes: #14090
Co-authored-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Shougo Matsushita <Shougo.Matsu@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Wed, 28 Feb 2024 23:00:03 +0100 |
parents | 2c0b18822510 |
children | 4944acf6b46f |
comparison
equal
deleted
inserted
replaced
34450:4b3ffb6965ec | 34451:d06ffca91441 |
---|---|
1 *builtin.txt* For Vim version 9.1. Last change: 2024 Feb 25 | 1 *builtin.txt* For Vim version 9.1. Last change: 2024 Feb 28 |
2 | 2 |
3 | 3 |
4 VIM REFERENCE MANUAL by Bram Moolenaar | 4 VIM REFERENCE MANUAL by Bram Moolenaar |
5 | 5 |
6 | 6 |
261 getqflist() List list of quickfix items | 261 getqflist() List list of quickfix items |
262 getqflist({what}) Dict get specific quickfix list properties | 262 getqflist({what}) Dict get specific quickfix list properties |
263 getreg([{regname} [, 1 [, {list}]]]) | 263 getreg([{regname} [, 1 [, {list}]]]) |
264 String or List contents of a register | 264 String or List contents of a register |
265 getreginfo([{regname}]) Dict information about a register | 265 getreginfo([{regname}]) Dict information about a register |
266 getregion({pos1}, {pos2}, {type}) | 266 getregion({pos1}, {pos2} [, {opts}]) |
267 List get the text from {pos1} to {pos2} | 267 List get the text from {pos1} to {pos2} |
268 getregtype([{regname}]) String type of a register | 268 getregtype([{regname}]) String type of a register |
269 getscriptinfo([{opts}]) List list of sourced scripts | 269 getscriptinfo([{opts}]) List list of sourced scripts |
270 gettabinfo([{expr}]) List list of tab pages | 270 gettabinfo([{expr}]) List list of tab pages |
271 gettabvar({nr}, {varname} [, {def}]) | 271 gettabvar({nr}, {varname} [, {def}]) |
4269 In |Vim9-script| {regname} must be one character. | 4269 In |Vim9-script| {regname} must be one character. |
4270 | 4270 |
4271 Can also be used as a |method|: > | 4271 Can also be used as a |method|: > |
4272 GetRegname()->getreginfo() | 4272 GetRegname()->getreginfo() |
4273 | 4273 |
4274 getregion({pos1}, {pos2}, {type}) *getregion()* | 4274 getregion({pos1}, {pos2} [, {opts}]) *getregion()* |
4275 Returns the list of strings from {pos1} to {pos2} as if it's | 4275 Returns the list of strings from {pos1} to {pos2} in current |
4276 selected in visual mode of {type}. | 4276 buffer. |
4277 For possible values of {pos1} and {pos2} see |line()|. | 4277 |
4278 {type} is the selection type: | 4278 {pos1} and {pos2} must both be |List|s with four numbers. |
4279 "v" for |characterwise| mode | 4279 See |getpos()| for the format of the list. |
4280 "V" for |linewise| mode | 4280 |
4281 "<CTRL-V>" for |blockwise-visual| mode | 4281 The optional argument {opts} is a Dict and supports the |
4282 following items: | |
4283 | |
4284 type Specify the selection type | |
4285 (default: "v"): | |
4286 "v" for |characterwise| mode | |
4287 "V" for |linewise| mode | |
4288 "<CTRL-V>" for |blockwise-visual| mode | |
4289 | |
4290 exclusive If |true|, use exclusive selection | |
4291 for the end position 'selection'. | |
4292 | |
4282 You can get the last selection type by |visualmode()|. | 4293 You can get the last selection type by |visualmode()|. |
4283 If Visual mode is active, use |mode()| to get the Visual mode | 4294 If Visual mode is active, use |mode()| to get the Visual mode |
4284 (e.g., in a |:vmap|). | 4295 (e.g., in a |:vmap|). |
4285 This function uses the line and column number from the | 4296 This function uses the line and column number from the |
4286 specified position. | 4297 specified position. |
4294 - If 'virtualedit' is enabled and selection is past the end of | 4305 - If 'virtualedit' is enabled and selection is past the end of |
4295 line, resulting lines are filled with blanks. | 4306 line, resulting lines are filled with blanks. |
4296 - If the selection starts or ends in the middle of a multibyte | 4307 - If the selection starts or ends in the middle of a multibyte |
4297 character, it is not included but its selected part is | 4308 character, it is not included but its selected part is |
4298 substituted with spaces. | 4309 substituted with spaces. |
4299 - If {pos1} or {pos2} equals "v" (see |line()|) and it is not in | 4310 - If {pos1} or {pos2} is not current in the buffer, an empty |
4300 |visual-mode|, an empty list is returned. | |
4301 - If {pos1}, {pos2} or {type} is an invalid string, an empty | |
4302 list is returned. | |
4303 - If {pos1} or {pos2} is a mark in different buffer, an empty | |
4304 list is returned. | 4311 list is returned. |
4305 | 4312 |
4306 Examples: > | 4313 Examples: > |
4307 :xnoremap <CR> | 4314 :xnoremap <CR> |
4308 \ <Cmd>echow getregion('v', '.', mode())<CR> | 4315 \ <Cmd>echow getregion( |
4309 < | 4316 \ getpos('v'), getpos('.'), #{ type: mode() })<CR> |
4310 Can also be used as a |method|: > | 4317 < |
4311 '.'->getregion("'a", 'v') | 4318 Can also be used as a |method|: > |
4319 getpos('.')->getregion(getpos("'a")) | |
4312 < | 4320 < |
4313 getregtype([{regname}]) *getregtype()* | 4321 getregtype([{regname}]) *getregtype()* |
4314 The result is a String, which is type of register {regname}. | 4322 The result is a String, which is type of register {regname}. |
4315 The value will be one of: | 4323 The value will be one of: |
4316 "v" for |characterwise| text | 4324 "v" for |characterwise| text |