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
2
2
3
3
4
4
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -20,6 +20,7 @@ Basic command line editing is explained in chapter 20 of the user manual
20
20
5. Ex command-line flags | ex-flags |
21
21
6. Ex special characters | cmdline-special |
22
22
7. Command-line window | cmdline-window |
23
+ 8. Command-line autocompletion | cmdline-autocompletion |
23
24
24
25
==============================================================================
25
26
1. Command-line editing *cmdline-editing*
@@ -406,6 +407,9 @@ word before the cursor. This is available for:
406
407
The number of help item matches is limited (currently to 300) to avoid a long
407
408
delay when there are very many matches.
408
409
410
+ For automatic completion as you type (without pressing a key like <Tab> ),
411
+ see | cmdline-autocompletion | .
412
+
409
413
These are the commands that can be used:
410
414
411
415
*c_CTRL-D*
@@ -479,8 +483,6 @@ When repeating 'wildchar' or CTRL-N you cycle through the matches, eventually
479
483
ending up back to what was typed. If the first match is not what you wanted,
480
484
you can use <S-Tab> or CTRL-P to go straight back to what you typed.
481
485
482
- See also | wildtrigger() | .
483
-
484
486
The 'wildmenu' option can be set to show the matches just above the command
485
487
line.
486
488
@@ -1340,4 +1342,83 @@ The character used for the pattern indicates the type of command-line:
1340
1342
@ string for | input() |
1341
1343
- text for | :insert | or | :append |
1342
1344
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
+
1343
1424
vim:tw=78:ts=8:noet:ft=help:norl:
0 commit comments