Skip to content

Commit

Permalink
Merge branch 'cmdline-navigation'
Browse files Browse the repository at this point in the history
Add Ctrl-Y key to command-line mode.  It activates fast navigation that
allows entering deep paths by a series of searches for individual path
components.

Add Ctrl-N/P keys to command-line navigation to move view cursor up/down.

Add Arrows/Home/End/Page Up/Page Down keys to command-line navigation to
move view cursor.

Add :amap, :anoremap and :aunmap commands to configure mappings in
navigation mode.

Thanks to Henrik Holst (a.k.a. hholst80) and dmocek.

Provide basic instructions in the documentation on how mappings work.

Thanks to dmocek.

Add Ctrl-O key to command-line navigation that goes to parent directory.
  • Loading branch information
xaizek committed Jan 14, 2023
2 parents db250df + 84f9dc1 commit 544e70f
Show file tree
Hide file tree
Showing 31 changed files with 1,086 additions and 216 deletions.
18 changes: 18 additions & 0 deletions ChangeLog
Expand Up @@ -33,11 +33,29 @@
additional places to look for plugins. Thanks to 高浩亮 (a.k.a.
haolian9).

Added Ctrl-Y key to command-line mode. It activates fast navigation that
allows entering deep paths by a series of searches for individual path
components. Thanks to Henrik Holst (a.k.a. hholst80) and dmocek.

Added Ctrl-O key to command-line navigation that goes to parent directory.

Added Ctrl-N/P keys to command-line navigation to move view cursor up/down.
Thanks to Henrik Holst (a.k.a. hholst80) and dmocek.

Added Arrows/Home/End/Page Up/Page Down keys to command-line navigation to
move view cursor. Thanks to Henrik Holst (a.k.a. hholst80) and dmocek.

Added :amap, :anoremap and :aunmap commands to configure mappings in
navigation mode. Thanks to Henrik Holst (a.k.a. hholst80) and dmocek.

Reduced amount of memory consumed by `:compare groupids`.

Made `:compare bycontents` not bother reading content of files which have
unique size.

Provide basic instructions in the documentation on how mappings work.
Thanks to dmocek.

Fixed segfault on trying to use pipe from Lua after its parent VifmJob
object was garbage-collected. Thanks to PRESFIL.

Expand Down
2 changes: 2 additions & 0 deletions THANKS
Expand Up @@ -75,6 +75,7 @@ DieSpinne
dikiy
Diogo Lemos (dmlemos)
Dmitry Frank (dimonomid)
dmocek
eco0414
Egor Gumenyuk (boo1ean)
einhander
Expand Down Expand Up @@ -105,6 +106,7 @@ Hans Kristian Otnes Berge
Hans Petter Jansson (hpjansson)
heelsleeh
Hendrik Jaeger (henk)
Henrik Holst (hholst80)
hofheinz
hutou
infinitewhileloop
Expand Down
92 changes: 88 additions & 4 deletions data/man/vifm.1
@@ -1,4 +1,4 @@
.TH VIFM 1 "10 January 2022" "vifm 0.12.1"
.TH VIFM 1 "14 January 2022" "vifm 0.12.1"
.\" ---------------------------------------------------------------------------
.SH NAME
.\" ---------------------------------------------------------------------------
Expand Down Expand Up @@ -1158,6 +1158,59 @@ insert result of evaluating an expression. Expression is to be entered
via nested command-line prompt (where this key does nothing). Expansion of an
erroneous expression is empty.
.\" ---------------------------------------------------------------------------
.SH Fast navigation
.\" ---------------------------------------------------------------------------
In order to streamline navigation through directory tree, you can enter a
special form of command-line mode from search or local filter prompt. Once
activated, pressing Enter opens currently selected directory and clears the
prompt in anticipation of the next component of the path. If entry under the
cursor is a file, it is opened and the mode is finished.

This behaviour is embedded in a command-line mode, but doesn't update input
histories nor expands abbreviations and redefines some of the mode's mappings
for the purpose of faster navigation through the file system rather than
command-line editing. When on, prompt gets "nav" prefix.

You can enable this behaviour on search by default via a mapping like:
.EX
nnoremap / /<c-y>
.EE
.TP
.BI Ctrl-Y
enter navigation mode. Works only for search and local filter started
from a normal mode and only when 'incsearch' is set ('wrapscan' is also nice to
have set for search).
.TP
.BI Ctrl-Y
return to a regular command-line mode.
.TP
.BI "Enter, Right"
either enter a directory under the cursor without leaving the mode and clear
the prompt or leave the mode and open a file under the cursor.
.TP
.BI "Ctrl-O, Left"
go to parent directory.
.TP
.BI "Ctrl-N, Down"
move view cursor down.
.TP
.BI "Ctrl-P, Up"
move view cursor up.
.TP
.BI "Page Down"
scroll view down.
.TP
.BI "Page Up"
scroll view up.
.TP
.BI Home
move view cursor to the first item.
.TP
.BI End
move view cursor to the last item.
.\" ---------------------------------------------------------------------------
.SH Pasting special values
.\" ---------------------------------------------------------------------------
The shortcuts listed below insert specified values into current cursor
Expand Down Expand Up @@ -1340,6 +1393,8 @@ line. If you want to use '|' in an argument, precede it with '\\'.
These commands see '|' as part of their arguments even when it's escaped:

:[range]!
:amap
:anoremap
:autocmd
:cabbrev
:cmap
Expand Down Expand Up @@ -3196,7 +3251,10 @@ map lhs key sequence to rhs in normal and visual modes.
map lhs key sequence to rhs in command line mode.

.TP
.BI " :cmap :dmap :mmap :nmap :qmap :vmap"
.BI " :amap :cmap :dmap :mmap :nmap :qmap :vmap"
.TP
.BI ":amap lhs rhs"
map lhs to rhs in navigation mode.
.TP
.BI ":cm[ap] lhs rhs"
map lhs to rhs in command line mode.
Expand All @@ -3219,6 +3277,9 @@ map lhs to rhs in visual mode.
.TP
.BI " :*map"
.TP
.BI :amap
list all maps in navigation mode.
.TP
.BI :cm[ap]
list all maps in command line mode.
.TP
Expand All @@ -3239,6 +3300,9 @@ list all maps in visual mode.
.TP
.BI " :*map beginning"
.TP
.BI ":amap beginning"
list all maps in navigation mode that start with the beginning.
.TP
.BI ":cm[ap] beginning"
list all maps in command line mode that start with the beginning.
.TP
Expand Down Expand Up @@ -3267,7 +3331,11 @@ user mappings in rhs.
map the key sequence lhs to rhs for command line mode, but don't expand user
mappings in rhs.
.TP
.BI " :cnoremap :dnoremap :mnoremap :nnoremap :qnoremap :vnoremap"
.BI " :anoremap :cnoremap :dnoremap :mnoremap :nnoremap :qnoremap :vnoremap"
.TP
.BI ":anoremap lhs rhs"
map the key sequence lhs to rhs for navigation mode, but don't expand user
mappings in rhs.
.TP
.BI ":cno[remap] lhs rhs"
map the key sequence lhs to rhs for command line mode, but don't expand user
Expand Down Expand Up @@ -3301,7 +3369,10 @@ remove user mapping of lhs from normal and visual modes.
.BI ":unm[ap]! lhs"
remove user mapping of lhs from command line mode.
.TP
.BI " :cunmap :dunmap :munmap :nunmap :qunmap :vunmap"
.BI " :aunmap :cunmap :dunmap :munmap :nunmap :qunmap :vunmap"
.TP
.BI ":aunmap lhs"
remove user mapping of lhs from navigation mode.
.TP
.BI ":cu[nmap] lhs"
remove user mapping of lhs from command line mode.
Expand Down Expand Up @@ -5366,6 +5437,19 @@ Searches wrap around end of the list.
.\" ---------------------------------------------------------------------------
.SH Mappings
.\" ---------------------------------------------------------------------------
A user mapping like `nnoremap lhs rhs` defines a substitution of the
left-hand-side (LHS) with the right-hand-side (RHS) in the input stream. A
regular mapping (without "nore" in :command's name) expands recognized
sequences in the RHS, while "*noremap" mapping always interprets RHS as if no
user mappings were defined and each key has its builtin meaning. In most cases
you want to use noremap variant and if your RHS includes LHS, only noremap
variant will work because recursion in a mapping is not allowed.

In order to define a mapping determine in which mode you want to activate it
and use an appropriate "*noremap" :command (e.g., :nnoremap for a
normal mode mapping). RHS doesn't have to limit itself to the mode in which
the mapping was started and can span multiple modes.

.B Map arguments

LHS of mappings can be preceded by arguments which take the form of special
Expand Down
74 changes: 73 additions & 1 deletion data/vim/doc/app/vifm-app.txt
@@ -1,4 +1,4 @@
*vifm-app.txt* For Vifm version 0.12.1 Last change: 2023 Jan 10
*vifm-app.txt* For Vifm version 0.12.1 Last change: 2023 Jan 14

Email for bugs and suggestions: <xaizek@posteo.net>

Expand Down Expand Up @@ -50,6 +50,7 @@ Tag name structure:
Menu or dialog command vifm-m_ :help vifm-m_zh
Command-line command vifm-: :help vifm-:quit
Command-line editing vifm-c_ :help vifm-c_CTRL-H
Command-line navigation vifm-a_ :help vifm-a_CTRL-Y
Vifm command argument vifm-- :help vifm--f
Option vifm-' :help vifm-'wrap'

Expand Down Expand Up @@ -1031,6 +1032,51 @@ Ctrl-R = *vifm-c_CTRL-R_=*
via nested command-line prompt (where this key does nothing). Expansion
of an erroneous expression is empty.

Fast navigation~

In order to streamline navigation through directory tree, you can enter a
special form of command-line mode from search or local filter prompt. Once
activated, pressing Enter opens currently selected directory and clears the
prompt in anticipation of the next component of the path. If entry under the
cursor is a file, it is opened and the mode is finished.

This behaviour is embedded in a command-line mode, but doesn't update input
histories nor expands abbreviations and redefines some of the mode's mappings
for the purpose of faster navigation through the file system rather than
command-line editing. When on, prompt gets "nav" prefix.

You can enable this behaviour on search by default via a mapping like: >
nnoremap / /<c-y>
Ctrl-Y *vifm-c_CTRL-Y*
enter navigation mode. Works only for search and local filter started
from a normal mode and only when |vifm-'incsearch'| is set
(|vifm-'wrapscan'| is also nice to have set for search).

Ctrl-Y *vifm-a_CTRL-Y*
return to a regular command-line mode.

Enter, Right *vifm-a_Enter* *vifm-a_Right*
either enter a directory under the cursor without leaving the mode and
clear the prompt or leave the mode and open a file under the cursor.
Ctrl-O, Left *vifm-a_CTRL-O* *vifm-a_Left*
go to parent directory.

Ctrl-N, Down *vifm-a_CTRL-N* *vifm-a_Down*
move view cursor down.
Ctrl-P, Up *vifm-a_CTRL-P* *vifm-a_Up*
move view cursor up.

Page Down *vifm-a_PageDown*
scroll view down.
Page Up *vifm-a_PageUp*
scroll view up.

Home *vifm-a_Home*
move view cursor to the first item.
End *vifm-a_End*
move view cursor to the last item.

Pasting special values~

The shortcuts listed below insert specified values into current cursor
Expand Down Expand Up @@ -1188,6 +1234,8 @@ line. If you want to use '|' in an argument, precede it with '\'.
These commands see '|' as part of their arguments even when it's escaped:

:[range]!
:amap
:anoremap
:autocmd
:cabbrev
:cmap
Expand Down Expand Up @@ -2669,26 +2717,31 @@ yet supported) and might be changed in future releases, or get an alias.
:map! lhs rhs
map lhs key sequence to rhs in command line mode.

*vifm-:amap*
*vifm-:cmap* *vifm-:cm*
*vifm-:dmap* *vifm-:dm*
*vifm-:mmap* *vifm-:mm*
*vifm-:nmap* *vifm-:nm*
*vifm-:qmap* *vifm-:qm*
*vifm-:vmap* *vifm-:vm*
:amap lhs rhs - map lhs to rhs in navigation mode.
:cm[ap] lhs rhs - map lhs to rhs in command line mode.
:dm[ap] lhs rhs - map lhs to rhs in dialog modes.
:mm[ap] lhs rhs - map lhs to rhs in menu mode.
:nm[ap] lhs rhs - map lhs to rhs in normal mode.
:qm[ap] lhs rhs - map lhs to rhs in view mode.
:vm[ap] lhs rhs - map lhs to rhs in visual mode.

:amap - list all maps of navigation mode.
:cm[ap] - list all maps of command line mode.
:dm[ap] - list all maps of dialog modes.
:mm[ap] - list all maps of menu mode.
:nm[ap] - list all maps of normal mode.
:qm[ap] - list all maps of view mode.
:vm[ap] - list all maps of visual mode.

:amap beginning
list all maps of navigation mode that start with the beginning.
:cm[ap] beginning
list all maps of command line mode that start with the beginning.
:dm[ap] beginning
Expand All @@ -2710,12 +2763,16 @@ yet supported) and might be changed in future releases, or get an alias.
map the key sequence lhs to rhs for command line mode, but don't expand
user mappings in rhs.

*vifm-:anoremap*
*vifm-:cnoremap* *vifm-:cno*
*vifm-:dnoremap* *vifm-:dn*
*vifm-:mnoremap* *vifm-:mn*
*vifm-:nnoremap* *vifm-:nn*
*vifm-:qnoremap* *vifm-:qn*
*vifm-:vnoremap* *vifm-:vn*
:anoremap lhs rhs
map the key sequence lhs to rhs for navigation mode, but don't expand
user mappings in rhs.
:cno[remap] lhs rhs
map the key sequence lhs to rhs for command line mode, but don't expand
user mappings in rhs.
Expand All @@ -2741,12 +2798,14 @@ yet supported) and might be changed in future releases, or get an alias.
:unm[ap]! lhs
remove user mapping of lhs from command line mode.

*vifm-:aunmap*
*vifm-:cunmap* *vifm-:cu*
*vifm-:dunmap* *vifm-:du*
*vifm-:munmap* *vifm-:mu*
*vifm-:nunmap* *vifm-:nun*
*vifm-:qunmap* *vifm-:qun*
*vifm-:vunmap* *vifm-:vu*
:aunmap lhs - remove user mapping of lhs from navigation mode.
:cu[nmap] lhs - remove user mapping of lhs from command line mode.
:du[nmap] lhs - remove user mapping of lhs from dialog modes.
:mu[nmap] lhs - remove user mapping of lhs from menu mode.
Expand Down Expand Up @@ -4534,6 +4593,19 @@ Searches wrap around end of the list.
--------------------------------------------------------------------------------
*vifm-mappings*

A user mapping like `nnoremap lhs rhs` defines a substitution of the
left-hand-side (LHS) with the right-hand-side (RHS) in the input stream. A
regular mapping (without "nore" in :command's name) expands recognized
sequences in the RHS, while "*noremap" mapping always interprets RHS as if no
user mappings were defined and each key has its builtin meaning. In most
cases you want to use noremap variant and if your RHS includes LHS, only
noremap variant will work because recursion in a mapping is not allowed.

In order to define a mapping determine in which mode you want to activate it
and use an appropriate "*noremap" :command (e.g., |vifm-:nnoremap| for a
normal mode mapping). RHS doesn't have to limit itself to the mode in which
the mapping was started and can span multiple modes.

Map arguments~

LHS of mappings can be preceded by arguments which take the form of special
Expand Down
8 changes: 4 additions & 4 deletions data/vim/syntax/vifm.vim
@@ -1,6 +1,6 @@
" vifm syntax file
" Maintainer: xaizek <xaizek@posteo.net>
" Last Change: December 10, 2022
" Last Change: January 14, 2023
" Inspired By: Vim syntax file by Dr. Charles E. Campbell, Jr.

if exists('b:current_syntax')
Expand Down Expand Up @@ -43,9 +43,9 @@ syntax keyword vifmCommandCN contained
syntax keyword vifmPrefixCommands contained windo winrun

" Map commands
syntax keyword vifmMap contained dm[ap] dn[oremap] du[nmap] map mm[ap]
\ mn[oremap] mu[nmap] nm[ap] nn[oremap] no[remap] nun[map] qm[ap] qn[oremap]
\ qun[map] unm[ap] vm[ap] vn[oremap] vu[nmap]
syntax keyword vifmMap contained amap anoremap aunmap dm[ap] dn[oremap] du[nmap]
\ map mm[ap] mn[oremap] mu[nmap] nm[ap] nn[oremap] no[remap] nun[map] qm[ap]
\ qn[oremap] qun[map] unm[ap] vm[ap] vn[oremap] vu[nmap]
\ skipwhite nextgroup=vifmMapArgs
syntax keyword vifmCMapAbbr contained ca[bbrev] cm[ap] cnorea[bbrev] cno[remap]
\ cuna[bbrev] cu[nmap]
Expand Down
2 changes: 2 additions & 0 deletions src/cmd_core.c
Expand Up @@ -1056,6 +1056,8 @@ get_cmd_args_type(const char cmd[])
switch(cmd_id)
{
case COMMAND_CMD_ID:
case COM_AMAP:
case COM_ANOREMAP:
case COM_AUTOCMD:
case COM_EXECUTE:
case COM_CABBR:
Expand Down

0 comments on commit 544e70f

Please sign in to comment.