Skip to content

Commit de84971

Browse files
authored
Merge pull request #2308 from h-east/update-cmdline
Update cmdline.{txt,jax}
2 parents d19be8a + 15005a2 commit de84971

File tree

2 files changed

+167
-6
lines changed

2 files changed

+167
-6
lines changed

doc/cmdline.jax

Lines changed: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*cmdline.txt* For Vim バージョン 9.1. Last change: 2025 Aug 08
1+
*cmdline.txt* For Vim バージョン 9.1. Last change: 2025 Sep 10
22

33

44
VIMリファレンスマニュアル by Bram Moolenaar
@@ -19,6 +19,7 @@
1919
5. Exコマンドラインのフラグ |ex-flags|
2020
6. Exコマンド用の特別な文字 |cmdline-special|
2121
7. コマンドラインウィンドウ |cmdline-window|
22+
8. コマンドラインの自動補完 |cmdline-autocompletion|
2223

2324
==============================================================================
2425
1. コマンドラインの編集 *cmdline-editing*
@@ -385,6 +386,9 @@ CTRL-] 文字を挿入することなく短縮入力を展開する。
385386
マッチするヘルプ項目の個数には上限がある(現在のところは 300)。非常に多くのマッ
386387
チがあったとき、遅くなるのを避けるためである。
387388

389+
(<Tab> 等のキーを押さずに) 入力時に自動補完を行う場合、
390+
|cmdline-autocompletion| を参照。
391+
388392
補完に使えるコマンドは以下の通り。
389393

390394
*c_CTRL-D*
@@ -448,8 +452,6 @@ CTRL-T 'incsearch' が設定され "/" や "?" にパターンを入力して
448452
ある。以前のバージョンでは <Esc> が使われていた)。パターンがファイル名に対して
449453
適用されるときは標準の |wildcards| が使用できる。
450454

451-
|wildtrigger()| も参照。
452-
453455
'wildchar' または CTRL-N を繰り返すとマッチしたものの始めから終わりまでを循環
454456
して、最終的には入力されたものに戻る。最初のマッチが望むものでないなら、入力し
455457
たものにまっすぐに戻るために <S-Tab> または CTRL-P を使うことができる。
@@ -1284,4 +1286,82 @@ Note: これは |file-pattern| なので、"?" をエスケープする必要が
12841286
@ 関数 |input()| に対して入力する文字列
12851287
- コマンド |:insert||:append| に対して入力する文字列
12861288

1289+
==============================================================================
1290+
8. コマンドラインの自動補完 *cmdline-autocompletion*
1291+
1292+
自動補完は、入力中に検索 (/ または ?) やコマンド入力 (:) の際に自動的に候補の
1293+
ポップアップメニューを表示することで、コマンドラインの操作をより効率的かつ簡単
1294+
にする。
1295+
1296+
基本的な設定: >
1297+
autocmd CmdlineChanged [:\/\?] call wildtrigger()
1298+
set wildmode=noselect:lastused,full
1299+
set wildoptions=pum
1300+
1301+
この設定では、すぐに候補が表示され、<Tab> キーまたは矢印キーを使用して候補間を
1302+
移動できる。
1303+
1304+
<Up>/<Down> による通常のコマンドライン履歴ナビゲーションを維持するには: >
1305+
cnoremap <expr> <Up> wildmenumode() ? "\<C-E>\<Up>" : "\<Up>"
1306+
cnoremap <expr> <Down> wildmenumode() ? "\<C-E>\<Down>" : "\<Down>"
1307+
1308+
オプションは特定のコマンドラインにのみ適用することもできる。例えば、検索時のみ
1309+
ポップアップメニューの高さを低くするには: >
1310+
autocmd CmdlineEnter [\/\?] set pumheight=8
1311+
autocmd CmdlineLeave [\/\?] set pumheight&
1312+
1313+
☆おまけ *fuzzy-file-picker* *live-grep*
1314+
1315+
コマンドラインの自動補完は、高度な用途向けに拡張することもでる。
1316+
例えば、ネイティブの |:find| コマンドを、あいまい検索が可能な対話型ファイルピッ
1317+
カーに変えることができる: >
1318+
1319+
set findfunc=Find
1320+
func Find(arg, _)
1321+
if get(s:, 'filescache', []) == []
1322+
let s:filescache = systemlist(
1323+
\ 'find . -path "*/.git" -prune -o -type f -print')
1324+
endif
1325+
return a:arg == '' ? s:filescache : matchfuzzy(s:filescache, a:arg)
1326+
endfunc
1327+
autocmd CmdlineEnter : let s:filescache = []
1328+
1329+
`:Grep` コマンドは、パターンにマッチする行を検索し、入力すると結果を動的に更新
1330+
する (2 文字後にトリガーされる。note: 次のセクションの `CmdlineLeavePre` 自動
1331+
コマンドが必要である): >
1332+
1333+
command! -nargs=+ -complete=customlist,<SID>Grep
1334+
\ Grep call <SID>VisitFile()
1335+
1336+
func s:Grep(arglead, cmdline, cursorpos)
1337+
let cmd = $'grep -REIHns "{a:arglead}" --exclude-dir=.git
1338+
\ --exclude=".*"'
1339+
return len(a:arglead) > 1 ? systemlist(cmd) : []
1340+
endfunc
1341+
1342+
func s:VisitFile()
1343+
let item = getqflist(#{lines: [s:selected]}).items[0]
1344+
let pos = '[0,\ item.lnum,\ item.col,\ 0]'
1345+
exe $':b +call\ setpos(".",\ {pos}) {item.bufnr}'
1346+
call setbufvar(item.bufnr, '&buflisted', 1)
1347+
endfunc
1348+
1349+
コマンドラインを終了するときに補完リストの最初の項目を自動的に選択し、`:Grep`
1350+
の場合は入力したパターンをコマンドライン履歴に追加する: >
1351+
1352+
autocmd CmdlineLeavePre :
1353+
\ if get(cmdcomplete_info(), 'matches', []) != [] |
1354+
\ let s:info = cmdcomplete_info() |
1355+
\ if getcmdline() =~ '^\s*fin\%[d]\s' && s:info.selected == -1 |
1356+
\ call setcmdline($'find {s:info.matches[0]}') |
1357+
\ endif |
1358+
\ if getcmdline() =~ '^\s*Grep\s' |
1359+
\ let s:selected = s:info.selected != -1
1360+
\ ? s:info.matches[s:info.selected] : s:info.matches[0] |
1361+
\ call setcmdline(s:info.cmdline_orig) |
1362+
\ endif |
1363+
\ endif
1364+
1365+
挿入モードでの自動補完については、|ins-autocompletion| を参照。
1366+
12871367
vim:tw=78:ts=8:noet:ft=help:norl:

en/cmdline.txt

Lines changed: 84 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*cmdline.txt* For Vim version 9.1. Last change: 2025 Aug 08
1+
*cmdline.txt* For Vim version 9.1. Last change: 2025 Sep 10
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -20,6 +20,7 @@ Basic command line editing is explained in chapter 20 of the user manual
2020
5. Ex command-line flags |ex-flags|
2121
6. Ex special characters |cmdline-special|
2222
7. Command-line window |cmdline-window|
23+
8. Command-line autocompletion |cmdline-autocompletion|
2324

2425
==============================================================================
2526
1. Command-line editing *cmdline-editing*
@@ -406,6 +407,9 @@ word before the cursor. This is available for:
406407
The number of help item matches is limited (currently to 300) to avoid a long
407408
delay when there are very many matches.
408409

410+
For automatic completion as you type (without pressing a key like <Tab>),
411+
see |cmdline-autocompletion|.
412+
409413
These are the commands that can be used:
410414

411415
*c_CTRL-D*
@@ -479,8 +483,6 @@ When repeating 'wildchar' or CTRL-N you cycle through the matches, eventually
479483
ending up back to what was typed. If the first match is not what you wanted,
480484
you can use <S-Tab> or CTRL-P to go straight back to what you typed.
481485

482-
See also |wildtrigger()|.
483-
484486
The 'wildmenu' option can be set to show the matches just above the command
485487
line.
486488

@@ -1340,4 +1342,83 @@ The character used for the pattern indicates the type of command-line:
13401342
@ string for |input()|
13411343
- text for |:insert| or |:append|
13421344

1345+
==============================================================================
1346+
8. Command-line autocompletion *cmdline-autocompletion*
1347+
1348+
Autocompletion makes the command-line more efficient and easier to navigate by
1349+
automatically showing a popup menu of suggestions as you type, whether
1350+
searching (/ or ?) or entering commands (:).
1351+
1352+
A basic setup is: >
1353+
autocmd CmdlineChanged [:\/\?] call wildtrigger()
1354+
set wildmode=noselect:lastused,full
1355+
set wildoptions=pum
1356+
1357+
With this configuration, suggestions appear immediately, and you can
1358+
move through them with <Tab> or the arrow keys.
1359+
1360+
To retain normal command-line history navigation with <Up>/<Down>: >
1361+
cnoremap <expr> <Up> wildmenumode() ? "\<C-E>\<Up>" : "\<Up>"
1362+
cnoremap <expr> <Down> wildmenumode() ? "\<C-E>\<Down>" : "\<Down>"
1363+
1364+
Options can also be applied only for specific command-lines. For
1365+
example, to use a shorter popup menu height only during search: >
1366+
autocmd CmdlineEnter [\/\?] set pumheight=8
1367+
autocmd CmdlineLeave [\/\?] set pumheight&
1368+
1369+
EXTRAS *fuzzy-file-picker* *live-grep*
1370+
1371+
Command-line autocompletion can also be extended for advanced uses.
1372+
For example, you can turn the native |:find| command into a fuzzy, interactive
1373+
file picker: >
1374+
1375+
set findfunc=Find
1376+
func Find(arg, _)
1377+
if get(s:, 'filescache', []) == []
1378+
let s:filescache = systemlist(
1379+
\ 'find . -path "*/.git" -prune -o -type f -print')
1380+
endif
1381+
return a:arg == '' ? s:filescache : matchfuzzy(s:filescache, a:arg)
1382+
endfunc
1383+
autocmd CmdlineEnter : let s:filescache = []
1384+
1385+
The `:Grep` command searches for lines matching a pattern and updates the
1386+
results dynamically as you type (triggered after two characters; note: needs
1387+
the `CmdlineLeavePre` autocmd from the next section): >
1388+
1389+
command! -nargs=+ -complete=customlist,<SID>Grep
1390+
\ Grep call <SID>VisitFile()
1391+
1392+
func s:Grep(arglead, cmdline, cursorpos)
1393+
let cmd = $'grep -REIHns "{a:arglead}" --exclude-dir=.git
1394+
\ --exclude=".*"'
1395+
return len(a:arglead) > 1 ? systemlist(cmd) : []
1396+
endfunc
1397+
1398+
func s:VisitFile()
1399+
let item = getqflist(#{lines: [s:selected]}).items[0]
1400+
let pos = '[0,\ item.lnum,\ item.col,\ 0]'
1401+
exe $':b +call\ setpos(".",\ {pos}) {item.bufnr}'
1402+
call setbufvar(item.bufnr, '&buflisted', 1)
1403+
endfunc
1404+
1405+
Automatically select the first item in the completion list when leaving the
1406+
command-line, and for `:Grep`, add the typed pattern to the command-line
1407+
history: >
1408+
1409+
autocmd CmdlineLeavePre :
1410+
\ if get(cmdcomplete_info(), 'matches', []) != [] |
1411+
\ let s:info = cmdcomplete_info() |
1412+
\ if getcmdline() =~ '^\s*fin\%[d]\s' && s:info.selected == -1 |
1413+
\ call setcmdline($'find {s:info.matches[0]}') |
1414+
\ endif |
1415+
\ if getcmdline() =~ '^\s*Grep\s' |
1416+
\ let s:selected = s:info.selected != -1
1417+
\ ? s:info.matches[s:info.selected] : s:info.matches[0] |
1418+
\ call setcmdline(s:info.cmdline_orig) |
1419+
\ endif |
1420+
\ endif
1421+
1422+
For autocompletion in insert mode, see |ins-autocompletion|.
1423+
13431424
vim:tw=78:ts=8:noet:ft=help:norl:

0 commit comments

Comments
 (0)