mirror of
https://github.com/vim/vim.git
synced 2025-08-31 20:53:42 -04:00
runtime(doc): include some vim9 script examples in the help
closes: #14848 Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
parent
f3dd6f617c
commit
bad9577b9a
@ -2015,6 +2015,7 @@ $quote eval.txt /*$quote*
|
|||||||
52.3 usr_52.txt /*52.3*
|
52.3 usr_52.txt /*52.3*
|
||||||
52.4 usr_52.txt /*52.4*
|
52.4 usr_52.txt /*52.4*
|
||||||
52.5 usr_52.txt /*52.5*
|
52.5 usr_52.txt /*52.5*
|
||||||
|
52.6 usr_52.txt /*52.6*
|
||||||
8g8 various.txt /*8g8*
|
8g8 various.txt /*8g8*
|
||||||
90.1 usr_90.txt /*90.1*
|
90.1 usr_90.txt /*90.1*
|
||||||
90.2 usr_90.txt /*90.2*
|
90.2 usr_90.txt /*90.2*
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
*usr_52.txt* For Vim version 9.1. Last change: 2024 May 16
|
*usr_52.txt* For Vim version 9.1. Last change: 2024 May 31
|
||||||
|
|
||||||
VIM USER MANUAL - by Bram Moolenaar
|
VIM USER MANUAL - by Bram Moolenaar
|
||||||
|
|
||||||
@ -13,6 +13,7 @@ smaller parts.
|
|||||||
|52.3| Autoloading without import/export
|
|52.3| Autoloading without import/export
|
||||||
|52.4| Other mechanisms to use
|
|52.4| Other mechanisms to use
|
||||||
|52.5| Using a Vim9 script from legacy script
|
|52.5| Using a Vim9 script from legacy script
|
||||||
|
|52.6| Vim9 script examples: comment package, highlight-yank plugin
|
||||||
|
|
||||||
Next chapter: |usr_90.txt| Installing Vim
|
Next chapter: |usr_90.txt| Installing Vim
|
||||||
Previous chapter: |usr_51.txt| Create a plugin
|
Previous chapter: |usr_51.txt| Create a plugin
|
||||||
@ -336,6 +337,46 @@ will have to make sure to use a unique name for these global items. Example: >
|
|||||||
call g:NicePluginTest()
|
call g:NicePluginTest()
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
|
*52.6* Vim9 script examples: comment package, highlight-yank plugin
|
||||||
|
|
||||||
|
COMMENT PACKAGE
|
||||||
|
|
||||||
|
Vim comes with a comment plugin, written in Vim9 script |comment-install|.
|
||||||
|
Have a look at the package located at $VIMRUNTIME/pack/dist/opt/comment/
|
||||||
|
|
||||||
|
HIGHLIGHT YANK PLUGIN
|
||||||
|
|
||||||
|
Here is an example for highlighting the yanked region. It makes use of the
|
||||||
|
|getregionpos()| function, available since Vim 9.1.0446.
|
||||||
|
|
||||||
|
Copy the following example into a new file and place it into your plugin directory
|
||||||
|
and it will be active next time you start Vim |add-plugin|: >
|
||||||
|
|
||||||
|
vim9script
|
||||||
|
|
||||||
|
def HighlightedYank(hlgroup = 'IncSearch', duration = 300, in_visual = true)
|
||||||
|
if v:event.operator ==? 'y'
|
||||||
|
if !in_visual && visualmode() != null_string
|
||||||
|
visualmode(1)
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
var [beg, end] = [getpos("'["), getpos("']")]
|
||||||
|
var type = v:event.regtype ?? 'v'
|
||||||
|
var pos = getregionpos(beg, end, {type: type})
|
||||||
|
var end_offset = (type == 'V' || v:event.inclusive) ? 1 : 0
|
||||||
|
var m = matchaddpos(hlgroup, pos->mapnew((_, v) => {
|
||||||
|
var col_beg = v[0][2] + v[0][3]
|
||||||
|
var col_end = v[1][2] + v[1][3] + end_offset
|
||||||
|
return [v[0][1], col_beg, col_end - col_beg]
|
||||||
|
}))
|
||||||
|
var winid = win_getid()
|
||||||
|
timer_start(duration, (_) => m->matchdelete(winid))
|
||||||
|
endif
|
||||||
|
enddef
|
||||||
|
|
||||||
|
autocmd TextYankPost * HighlightedYank()
|
||||||
|
<
|
||||||
|
==============================================================================
|
||||||
|
|
||||||
Next chapter: |usr_90.txt| Installing Vim
|
Next chapter: |usr_90.txt| Installing Vim
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
*vim9.txt* For Vim version 9.1. Last change: 2024 Apr 13
|
*vim9.txt* For Vim version 9.1. Last change: 2024 May 31
|
||||||
|
|
||||||
|
|
||||||
VIM REFERENCE MANUAL by Bram Moolenaar
|
VIM REFERENCE MANUAL by Bram Moolenaar
|
||||||
@ -67,6 +67,7 @@ rewrite old scripts, they keep working as before. You may want to use a few
|
|||||||
Note that {cmd} cannot use local variables, since it is parsed
|
Note that {cmd} cannot use local variables, since it is parsed
|
||||||
with legacy expression syntax.
|
with legacy expression syntax.
|
||||||
|
|
||||||
|
See some examples of Vim9 script at |52.6|.
|
||||||
==============================================================================
|
==============================================================================
|
||||||
|
|
||||||
2. Differences from legacy Vim script *vim9-differences*
|
2. Differences from legacy Vim script *vim9-differences*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user