xaizek / vifm (License: GPLv2+) (since 2018-12-07)
Vifm is a file manager with curses interface, which provides Vi[m]-like environment for managing objects within file systems, extended with some useful ideas from mutt.
Commit 8fbe8c687d731acd7040fda8050ec6b17bf04c77

Add 'wildmode' for completing longest prefix.
Thanks to James Dietrich and niklassc at Vifm Q2A site. See
https://q2a.vifm.info/1361/is-there-a-way-to-change-the-wildmode-in-vifm
for the latter.
Author: xaizek
Author date (UTC): 2026-11-09 14:38
Committer name: xaizek
Committer date (UTC): 2026-11-09 15:25
Parent(s): c44a73911869b5fc3d9dc823649d711dfae69d3c
Signing key: 99DC5E4DB05F6BE2
Tree: 298d3420b71f0d1c9b3536c263ed72572d67901b
File Lines added Lines deleted
ChangeLog 3 0
TODO 0 1
data/man/vifm.1 13 1
data/vim/doc/app/vifm-app.txt 13 1
data/vim/syntax/vifm.vim 3 2
src/cfg/config.c 1 0
src/cfg/config.h 3 0
src/cfg/info.c 2 0
src/modes/cmdline.c 1 0
src/opt_handlers.c 63 0
src/tags.c 2 0
tests/misc/cmdline_completion.c 16 0
tests/misc/options.c 22 0
tests/test-data/syntax-highlight/syntax.vifm 1 0
File ChangeLog changed (mode: 100644) (index 3e33e74fa..bbb6d4e2c)
76 76 Added "[A]ppend all" conflict resolution option, which appends tails Added "[A]ppend all" conflict resolution option, which appends tails
77 77 of all conflicting regular files without asking again. Patch by rr-. of all conflicting regular files without asking again. Patch by rr-.
78 78
79 Added 'wildmode' option to allow completing the longest prefix. Thanks to
80 James Dietrich and niklassc at Vifm Q2A site.
81
79 82 Updated utf8proc to v2.12.0. Updated utf8proc to v2.12.0.
80 83
81 84 Made documentation on which :commands can have comments a bit more Made documentation on which :commands can have comments a bit more
File TODO changed (mode: 100644) (index 678dfa9ad..509fe16ad)
... ... Possible things to add:
87 87 * Like gv but to select just pasted files (gp?). * Like gv but to select just pasted files (gp?).
88 88 * g~<selector> and g?. * g~<selector> and g?.
89 89 * Add trashes bang to list empty trashes or all of them. * Add trashes bang to list empty trashes or all of them.
90 * 'wildmode' option.
91 90 * Try to make it work in monochrome terminal. * Try to make it work in monochrome terminal.
92 91 * Support of command line arguments like ~/some.ssh/server/path (for FUSE). * Support of command line arguments like ~/some.ssh/server/path (for FUSE).
93 92 * Treat `:filter pattern` as `:filter \<pattern\>`. * Treat `:filter pattern` as `:filter \<pattern\>`.
File data/man/vifm.1 changed (mode: 100644) (index 19e5cb304..301faa275)
1 .TH VIFM 1 "29 October 2026" "vifm 0.15"
1 .TH VIFM 1 "9 November 2026" "vifm 0.15"
2 2 .\" --------------------------------------------------------------------------- .\" ---------------------------------------------------------------------------
3 3 .SH NAME .SH NAME
4 4 .\" --------------------------------------------------------------------------- .\" ---------------------------------------------------------------------------
 
... ... default: false
5835 5835 Controls whether possible matches of completion will be shown above the command Controls whether possible matches of completion will be shown above the command
5836 5836 line. line.
5837 5837 .TP .TP
5838 .BI "'wildmode' 'wim'"
5839 type: string list
5840 .br
5841 default: "full"
5842 .br
5843 Selects how completion is performed. Possible values:
5844 - full - each match is completed in turn (in effect if the option is empty)
5845 - longest - the longest common prefix of all matches is inserted
5846
5847 The option is of the string list type to match Vim, but so far behaves as an
5848 enumeration with the last value taking precedence.
5849 .TP
5838 5850 .BI 'wildstyle' .BI 'wildstyle'
5839 5851 type: enumeration type: enumeration
5840 5852 .br .br
File data/vim/doc/app/vifm-app.txt changed (mode: 100644) (index e0dccccf5..da4bf5399)
1 *vifm-app.txt* For Vifm version 0.15 Last change: 2026 October 29
1 *vifm-app.txt* For Vifm version 0.15 Last change: 2026 November 9
2 2
3 3 Email for bugs and suggestions: <xaizek@posteo.net> Email for bugs and suggestions: <xaizek@posteo.net>
4 4
 
... ... default: false
4943 4943 Controls whether possible matches of completion will be shown above the Controls whether possible matches of completion will be shown above the
4944 4944 command line. command line.
4945 4945
4946 *vifm-'wildmode'* *vifm-'wim'*
4947 wildmode wim
4948 type: string list
4949 default: "full"
4950
4951 Selects how completion is performed. Possible values:
4952 - full - each match is completed in turn (in effect if the option is empty)
4953 - longest - the longest common prefix of all matches is inserted
4954
4955 The option is of the string list type to match Vim, but so far behaves as an
4956 enumeration with the last value taking precedence.
4957
4946 4958 *vifm-'wildstyle'* *vifm-'wildstyle'*
4947 4959 wildstyle wildstyle
4948 4960 type: enumeration type: enumeration
File data/vim/syntax/vifm.vim changed (mode: 100644) (index 8a2dbdbbd..c43797ffe)
1 1 " vifm syntax file " vifm syntax file
2 2 " Maintainer: xaizek <xaizek@posteo.net> " Maintainer: xaizek <xaizek@posteo.net>
3 " Last Change: October 1, 2026
3 " Last Change: November 9, 2026
4 4 " Inspired By: Vim syntax file by Dr. Charles E. Campbell, Jr. " Inspired By: Vim syntax file by Dr. Charles E. Campbell, Jr.
5 5
6 6 if exists('b:current_syntax') if exists('b:current_syntax')
 
... ... syntax keyword vifmOption contained aproposprg autocd autochpos caseoptions
172 172 \ suggestoptions syncregs syscalls tablabel tabline tabprefix tabscope \ suggestoptions syncregs syscalls tablabel tabline tabprefix tabscope
173 173 \ tabstop tabsuffix tal timefmt timeoutlen title tm trash trashdir ts \ tabstop tabsuffix tal timefmt timeoutlen title tm trash trashdir ts
174 174 \ tuioptions to uioptions undolevels ul vicmd viewcolumns vifminfo vimhelp \ tuioptions to uioptions undolevels ul vicmd viewcolumns vifminfo vimhelp
175 \ vixcmd wildinc wildmenu wmnu wildstyle wordchars wrap wrapscan ws
175 \ vixcmd wildinc wildmenu wmnu wildmode wim wildstyle wordchars wrap
176 \ wrapscan ws
176 177
177 178 " Disabled boolean options " Disabled boolean options
178 179 syntax keyword vifmOption contained noautocd noautochpos nocf nochaselinks syntax keyword vifmOption contained noautocd noautochpos nocf nochaselinks
File src/cfg/config.c changed (mode: 100644) (index e09d2d076..33740bf6b)
... ... cfg_init(void)
132 132
133 133 cfg.wild_menu = 0; cfg.wild_menu = 0;
134 134 cfg.wild_popup = 0; cfg.wild_popup = 0;
135 cfg.wild_mode_longest = 0;
135 136
136 137 char *error; char *error;
137 138 cfg.wild_inc = matcher_alloc_glob("", &error); cfg.wild_inc = matcher_alloc_glob("", &error);
File src/cfg/config.h changed (mode: 100644) (index 516c99b81..35e115f09)
... ... typedef struct config_t
232 232 int wild_menu; int wild_menu;
233 233 /* Whether wild menu should be a popup instead of a bar. */ /* Whether wild menu should be a popup instead of a bar. */
234 234 int wild_popup; int wild_popup;
235 /* Whether wild menu should be completing the longest prefix instead of full
236 * matches in order. */
237 int wild_mode_longest;
235 238 /* Things (mainly :commands) which match this matcher are to be completed /* Things (mainly :commands) which match this matcher are to be completed
236 239 * automatically. */ * automatically. */
237 240 matcher_t *wild_inc; matcher_t *wild_inc;
File src/cfg/info.c changed (mode: 100644) (index 4a2fcff67..5e1e89c6e)
... ... store_global_options(JSON_Object *root)
2372 2372
2373 2373 append_dstr(options, format_str("%svimhelp", cfg.use_vim_help ? "" : "no")); append_dstr(options, format_str("%svimhelp", cfg.use_vim_help ? "" : "no"));
2374 2374 append_dstr(options, format_str("%swildmenu", cfg.wild_menu ? "" : "no")); append_dstr(options, format_str("%swildmenu", cfg.wild_menu ? "" : "no"));
2375 append_dstr(options, format_str("wildmode=%s",
2376 escape_spaces(vle_opts_get("wildmode", OPT_GLOBAL))));
2375 2377 append_dstr(options, format_str("wildstyle=%s", append_dstr(options, format_str("wildstyle=%s",
2376 2378 cfg.wild_popup ? "popup" : "bar")); cfg.wild_popup ? "popup" : "bar"));
2377 2379 append_dstr(options, format_str("wordchars=%s", append_dstr(options, format_str("wordchars=%s",
File src/modes/cmdline.c changed (mode: 100644) (index 075c6ca2f..6faa3d78c)
... ... line_completion(line_stats_t *stat)
3269 3269 } }
3270 3270
3271 3271 vle_compl_set_reversed(stat->reverse_completion); vle_compl_set_reversed(stat->reverse_completion);
3272 vle_compl_set_longest(cfg.wild_mode_longest);
3272 3273
3273 3274 if(vle_compl_get_count() == 0) if(vle_compl_get_count() == 0)
3274 3275 { {
File src/opt_handlers.c changed (mode: 100644) (index 24d6cf1d5..74b49abe4)
... ... static void init_sortorder(optval_t *val);
111 111 static void init_tuioptions(optval_t *val); static void init_tuioptions(optval_t *val);
112 112 static void init_uioptions(optval_t *val); static void init_uioptions(optval_t *val);
113 113 static void init_wildinc(optval_t *val); static void init_wildinc(optval_t *val);
114 static void init_wildmode(optval_t *val);
114 115 static void init_wordchars(optval_t *val); static void init_wordchars(optval_t *val);
115 116 static void load_options_defaults(void); static void load_options_defaults(void);
116 117 static void add_options(void); static void add_options(void);
 
... ... static void vifminfo_handler(OPT_OP op, optval_t val);
253 254 static void vimhelp_handler(OPT_OP op, optval_t val); static void vimhelp_handler(OPT_OP op, optval_t val);
254 255 static void wildinc_handler(OPT_OP op, optval_t val); static void wildinc_handler(OPT_OP op, optval_t val);
255 256 static void wildmenu_handler(OPT_OP op, optval_t val); static void wildmenu_handler(OPT_OP op, optval_t val);
257 static void wildmode_handler(OPT_OP op, optval_t val);
256 258 static void wildstyle_handler(OPT_OP op, optval_t val); static void wildstyle_handler(OPT_OP op, optval_t val);
257 259 static void wordchars_handler(OPT_OP op, optval_t val); static void wordchars_handler(OPT_OP op, optval_t val);
258 260 static int parse_range(const char range[], int *from, int *to); static int parse_range(const char range[], int *from, int *to);
 
... ... static const char *vifminfo_set[][2] = {
580 582 }; };
581 583 ARRAY_GUARD(vifminfo_set, NUM_VINFO); ARRAY_GUARD(vifminfo_set, NUM_VINFO);
582 584
585 /* Possible values of 'wildmode'. */
586 static const char *wildmode_vals[][2] = {
587 { "full", "complete each match in turn" },
588 { "longest", "complete the shared prefix of all matches" },
589 };
590 /* This is backed up by a boolean option at the moment. */
591 ARRAY_GUARD(wildmode_vals, 2);
592
583 593 /* Possible values of 'wildstyle'. */ /* Possible values of 'wildstyle'. */
584 594 static const char *wildstyle_vals[][2] = { static const char *wildstyle_vals[][2] = {
585 595 { "bar", "single-line bar" }, { "bar", "single-line bar" },
 
... ... options[] = {
939 949 OPT_BOOL, 0, NULL, &wildmenu_handler, NULL, OPT_BOOL, 0, NULL, &wildmenu_handler, NULL,
940 950 { .ref.bool_val = &cfg.wild_menu }, { .ref.bool_val = &cfg.wild_menu },
941 951 }, },
952 { "wildmode", "", "how to perform completion",
953 OPT_STRLIST, ARRAY_LEN(wildmode_vals), wildmode_vals, &wildmode_handler,
954 NULL,
955 { .init = &init_wildmode },
956 },
942 957 { "wildstyle", "", "how to display completion matches", { "wildstyle", "", "how to display completion matches",
943 958 OPT_ENUM, ARRAY_LEN(wildstyle_vals), wildstyle_vals, &wildstyle_handler, OPT_ENUM, ARRAY_LEN(wildstyle_vals), wildstyle_vals, &wildstyle_handler,
944 959 NULL, NULL,
 
... ... init_wildinc(optval_t *val)
1448 1463 val->str_val = (char *)matcher_get_undec(cfg.wild_inc); val->str_val = (char *)matcher_get_undec(cfg.wild_inc);
1449 1464 } }
1450 1465
1466 /* Composes initial value of 'wildmode' from the current configuration. */
1467 static void
1468 init_wildmode(optval_t *val)
1469 {
1470 val->str_val = (cfg.wild_mode_longest ? "longest" : "full");
1471 }
1472
1451 1473 /* Formats 'wordchars' initial value from cfg.word_chars array. */ /* Formats 'wordchars' initial value from cfg.word_chars array. */
1452 1474 static void static void
1453 1475 init_wordchars(optval_t *val) init_wordchars(optval_t *val)
 
... ... wildmenu_handler(OPT_OP op, optval_t val)
4109 4131 cfg.wild_menu = val.bool_val; cfg.wild_menu = val.bool_val;
4110 4132 } }
4111 4133
4134 /* Wild menu mode, which defines how completion is done. */
4135 static void
4136 wildmode_handler(OPT_OP op, optval_t val)
4137 {
4138 char *new_val = strdup(val.str_val);
4139 if(new_val == NULL)
4140 {
4141 /* Not much to do. Try recording an error and exit. */
4142 vle_tb_append_line(vle_err, "Out of memory, when handling 'wildmode'.");
4143 return;
4144 }
4145
4146 int longest = 0;
4147
4148 char *part = new_val, *state = NULL;
4149 while((part = split_and_get(part, ',', &state)) != NULL)
4150 {
4151 if(strcmp(part, "full") == 0)
4152 {
4153 longest = 0;
4154 }
4155 else if(strcmp(part, "longest") == 0)
4156 {
4157 longest = 1;
4158 }
4159 else
4160 {
4161 vle_tb_append_linef(vle_err, "Unknown value for 'wildmode' option: %s",
4162 part);
4163 break;
4164 }
4165 }
4166
4167 free(new_val);
4168
4169 if(part == NULL)
4170 {
4171 cfg.wild_mode_longest = longest;
4172 }
4173 }
4174
4112 4175 /* Wild menu style, which defines how it's presented. */ /* Wild menu style, which defines how it's presented. */
4113 4176 static void static void
4114 4177 wildstyle_handler(OPT_OP op, optval_t val) wildstyle_handler(OPT_OP op, optval_t val)
File src/tags.c changed (mode: 100644) (index 3e05641c1..2757eef97)
... ... const char *tags[] = {
160 160 "vifm-'vixcmd'", "vifm-'vixcmd'",
161 161 "vifm-'wildinc'", "vifm-'wildinc'",
162 162 "vifm-'wildmenu'", "vifm-'wildmenu'",
163 "vifm-'wildmode'",
163 164 "vifm-'wildstyle'", "vifm-'wildstyle'",
165 "vifm-'wim'",
164 166 "vifm-'wmnu'", "vifm-'wmnu'",
165 167 "vifm-'wordchars'", "vifm-'wordchars'",
166 168 "vifm-'wrap'", "vifm-'wrap'",
File tests/misc/cmdline_completion.c changed (mode: 100644) (index 585bebbde..d38a1d1cd)
... ... TEST(percent_completion)
270 270 ASSERT_NEXT_MATCH("%%%%"); ASSERT_NEXT_MATCH("%%%%");
271 271 } }
272 272
273 TEST(longest_completion)
274 {
275 cfg.wild_mode_longest = 1;
276
277 ASSERT_COMPLETION(L"command ", L"command ");
278 ASSERT_NEXT_MATCH("");
279
280 ASSERT_COMPLETION(L"command b", L"command ba");
281 vle_compl_set_reversed(1);
282 ASSERT_NEXT_MATCH("baz");
283 ASSERT_NEXT_MATCH("bar");
284 ASSERT_NEXT_MATCH("b");
285
286 cfg.wild_mode_longest = 0;
287 }
288
273 289 TEST(failure_to_turn_input_into_multibyte_is_handled, IF(not_windows)) TEST(failure_to_turn_input_into_multibyte_is_handled, IF(not_windows))
274 290 { {
275 291 /* On Windows narrow locale doesn't really matter because UTF-8 is used /* On Windows narrow locale doesn't really matter because UTF-8 is used
File tests/misc/options.c changed (mode: 100644) (index 5854d692a..4dd2e76b2)
... ... TEST(fileoptions)
795 795 assert_string_equal(" fileoptions=hidemissing", ui_sb_last()); assert_string_equal(" fileoptions=hidemissing", ui_sb_last());
796 796 } }
797 797
798 TEST(wildmode)
799 {
800 /* Setting. */
801 assert_success(cmds_dispatch1("set wildmode=longest", &lwin, CIT_COMMAND));
802 assert_true(cfg.wild_mode_longest);
803 assert_success(cmds_dispatch1("set wildmode=full", &lwin, CIT_COMMAND));
804 assert_false(cfg.wild_mode_longest);
805 assert_success(cmds_dispatch1("set wildmode=longest", &lwin, CIT_COMMAND));
806 assert_true(cfg.wild_mode_longest);
807
808 /* Clearing. */
809 assert_success(cmds_dispatch1("set wildmode=", &lwin, CIT_COMMAND));
810 assert_false(cfg.wild_mode_longest);
811
812 /* Wrong value is reported, intermediate state is discarded. */
813 ui_sb_msg("");
814 assert_failure(cmds_dispatch1("set wildmode=longest,bad", &lwin,
815 CIT_COMMAND));
816 assert_string_equal("Unknown value for 'wildmode' option: bad", ui_sb_last());
817 assert_false(cfg.wild_mode_longest);
818 }
819
798 820 static void static void
799 821 print_func(const char buf[], int offset, AlignType align, print_func(const char buf[], int offset, AlignType align,
800 822 const char full_column[], const format_info_t *info) const char full_column[], const format_info_t *info)
File tests/test-data/syntax-highlight/syntax.vifm changed (mode: 100644) (index be2b6ea7a..14693de43)
... ... set uioptions
655 655 set extprompt set extprompt
656 656 set keepsel nokeepsel invkeepsel keepsel! set keepsel nokeepsel invkeepsel keepsel!
657 657 set fileoptions set fileoptions
658 set wildmode wim
658 659
659 660 " "echo" and "call" should be highlighted as :command " "echo" and "call" should be highlighted as :command
660 661 " "chooseopt" should be highlighted as builtin function " "chooseopt" should be highlighted as builtin function
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/vifm

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/vifm

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master