Skip to content

Update usr_52.{txt,jax} #1557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion doc/usr_52.jax
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*usr_52.txt* For Vim バージョン 9.1. Last change: 2024 May 16
*usr_52.txt* For Vim バージョン 9.1. Last change: 2024 May 31

VIM USER MANUAL - by Bram Moolenaar

Expand All @@ -14,6 +14,7 @@
|52.3| インポート/エクスポートなしのオートロード
|52.4| 他に使えるメカニズム
|52.5| 旧来のスクリプトから Vim9 script を使う
|52.6| Vim9 script サンプル: comment パッケージ, highlight-yank プラグイン

次章: |usr_90.txt| Vim のインストール
前章: |usr_51.txt| プラグインを作る
Expand Down Expand Up @@ -340,6 +341,47 @@ script ではこうしたグローバルのアイテムで確実にユニーク
call g:NicePluginTest()

==============================================================================
*52.6* Vim9 script サンプル: comment パッケージ, highlight-yank プラグイン

☆comment パッケージ

Vim には、Vim9 script で記述されたコメントプラグイン |comment-install| が付属
しています。
Comment on lines +348 to +349
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここも下にある |add-plugin| のところと同じ感じで、タグを後置して「Vim には、Vim9 script で記述されたコメントプラグインが付属しています。|comment-install|」としても良いかな...?と思いました。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

今回はこのままにします。
ただ、指摘の意図も分かるので、原文に変更を依頼します。
typo報告スレにpatch

$VIMRUNTIME/pack/dist/opt/comment/ にあるパッケージを確認してください。

☆highlight-yank プラグイン

ヤンクされた領域をハイライトする例を以下に示します。これは、Vim 9.1.0446 以降
で使用可能な |getregionpos()| 関数を使用します。

以下の例を新しいファイルにコピーしてプラグインディレクトリに配置すると、次回
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()
<
==============================================================================

次章: |usr_90.txt| Vim のインストール

Expand Down
43 changes: 42 additions & 1 deletion en/usr_52.txt
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -13,6 +13,7 @@ smaller parts.
|52.3| Autoloading without import/export
|52.4| Other mechanisms to use
|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
Previous chapter: |usr_51.txt| Create a plugin
Expand Down Expand Up @@ -336,6 +337,46 @@ will have to make sure to use a unique name for these global items. Example: >
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

Expand Down