README.md | 2 ++ nnn.1 | 2 ++ nnn.c | 15 +++++++++++++++ diff --git a/README.md b/README.md index 9dfff77249db53471b2d1f20d130be7e82ca3635..1e4cae8f34379f34b89dd9a94f32baac07a16f04 100644 --- a/README.md +++ b/README.md @@ -276,6 +276,8 @@ #### Navigate-as-you-type mode In this mode directories are opened in filter mode, allowing continuous navigation. Works best with the **arrow keys**. +In case of only one match and it's a directory, `nnn` auto selects the directory and enters it in this mode. + #### File indicators The following indicators are used in the detail view: diff --git a/nnn.1 b/nnn.1 index 0c71ebd95f41eef319cbcbe21535ef17aca30f93..fba08f2fa9b7b8de69262b060936dc9c278af137 100644 --- a/nnn.1 +++ b/nnn.1 @@ -206,6 +206,8 @@ is invoked as root or the environment variable \fBNNN_SHOW_HIDDEN\fR is set the default filter will also match hidden files. .Pp In the \fInavigate-as-you-type\fR mode directories are opened in filter mode, allowing continuous navigation. Works best with the \fBarrow keys\fR. +.br +In case of only one match and it's a directory, `nnn` auto selects the directory and enters it in this mode. .Sh MULTI-COPY MODE The absolute path of a single file can be copied to clipboard by pressing \fI^K\fR if NNN_COPIER is set (see ENVIRONMENT section below). diff --git a/nnn.c b/nnn.c index 179a804ee15f148465702e66df4ce5c42e6acc5e..5975040480df1bde6e5829e5a792a8f847aa22de 100644 --- a/nnn.c +++ b/nnn.c @@ -1161,6 +1161,21 @@ wcstombs(ln, wln, REGEX_MAX); ndents = total; if (matches(pln) == -1) continue; + + /* If the only match is a dir, auto-select and cd into it */ + if (cfg.filtermode && ndents == 1 && S_ISDIR(dents[0].mode)) { + *ch = KEY_ENTER; + cur = 0; + goto end; + } + + /* + * redraw() should be above the auto-select optimization, for + * the case where there's an issue with dir auto-select, say, + * due to a permission problem. The transition is jumpy in + * case of such an error. However, we optimize for successful + * cases where the dir has permissions. This skips a redraw(). + */ redraw(path); printprompt(ln); }