% "Builtin normal mode keys of Vifm" cheatsheet
%
% Copyright (C) 2025 xaizek.
% Made available under the terms of Apache 2.0 license.
%
% Note that LaTeX knowledge of the author is extermely limited and the code
% below is probably of quite low quality.

\documentclass[landscape]{article}

\usepackage[latin1]{inputenc}
\usepackage{tikz}

\usepackage{color}
\usepackage{colortbl}
\usepackage{fontawesome}
\usepackage{setspace}

\usepackage[paperwidth=21.75cm, paperheight=15.25cm] {geometry}
\geometry{top=2mm,bottom=0mm,left=-3mm,right=0mm}

\usepackage[oldsyntax]{stackengine}
\newcommand\makeblock[3]{\parbox[t]{#1}{\textbf{#2}\\[2pt]#3}}
\Sstackgap=1.5ex

\setlength{\tabcolsep}{0.2em}

% disable page numbers
\pagestyle{empty}

\newlength\unit
\newlength\sep
\newlength\base

\setlength{\unit}{0.20cm}
\setlength{\sep}{0.10cm}
\setlength{\base}{4\unit}

% switch for controlling keyboard size
\def\shortkeyboard{\true}

\definecolor{util}{gray}{0.5}
\definecolor{note}{RGB}{75,75,205}
\definecolor{keyname}{RGB}{225,75,75}

\newcommand{\s}[1]{{\color{util}#1}}

\newcommand{\note}[1]{{\color{note}(#1)}}

\newcommand{\shortcut}[1]{\texttt{#1}}

\newcommand{\keyname}[1]{{\color{keyname}\textbf{\footnotesize#1}}}
\newcommand{\keydesc}[1]{
    \begin{spacing}{0.75}
        \sffamily\scriptsize#1
    \end{spacing}
}

\def\fkeyd#1#2 {
    \draw ++(\X,\Y)       rectangle +(\base,\base)
           +(0,0.85\base) node[text width=10cm,text height=1,anchor=north west] {\keyname{#1}\vspace{3px}\keydesc{#2}};
    \setlength{\X}{\X + \base + \sep}
}
\def\unusedfkey#1#2 { % the second argument is just to allow spaces before the first one
    \fill[very nearly transparent,gray]
         ++(\X,\Y) rectangle +(\base,\base);
    \draw[nearly transparent,gray]
         +(\X,\Y+0.85*\base) node[text width=10cm,text height=1,anchor=north west] {\keyname{#1}};
    \setlength{\X}{\X + \base + \sep}
}

\def\longfkeyd(#1)#2#3 {
    \draw ++(\X,\Y)       rectangle +(#1,1\base)
           +(0,0.65\base) node[text width=10cm,text height=1,text ragged,anchor=north west] {\keyname{#2}\vspace{3px}\keydesc{#3}};
    \setlength{\X}{\X + #1 + \sep}
}
\def\unusedlongfkey(#1)#2#3 { % the third argument is just to allow spaces before the second one
    \fill[very nearly transparent,gray]
         ++(\X,\Y) rectangle +(#1,\base);
    \draw[nearly transparent,gray]
         +(\X+0.1\base,\Y+0.5\base) node[text width=2,text height=1] {\keyname{#2}};
    \setlength{\X}{\X + #1 + \sep}
}

\def\keyd#1#2,#3#4 {
    \draw ++(\X,\Y) rectangle +(\base,\base)
          ++(0.1\base,0.6\base)   node[text width=1,text height=1,anchor=south] {\keyname{#1}}
           +(0.15\base,0.45\base) node[text width=1.4cm,text height=1,text ragged,anchor=north west] {\keydesc{#2}}
           +(0.0,-0.5\base)       node[text width=1,text height=1,anchor=south] {\keyname{#3}}
           +(0.15\base,0)         node[text width=1.4cm,text height=1,text ragged,anchor=north west] {\keydesc{#4}};

    \draw [densely dotted] ++(\X,\Y+0.5\base) -- +(\base,0);
    \setlength{\X}{\X + \base + \sep}
}
\def\unusedkey#1,#2 {
    \fill[very nearly transparent,gray]
         ++(\X,\Y) rectangle +(\base,\base);
    \draw[nearly transparent,gray]
         (\X+0.1\base,\Y+0.6\base) node[text width=1,text height=1,anchor=south] {\keyname{#1}}
         +(0.0,-0.5\base)          node[text width=1,text height=1,anchor=south] {\keyname{#2}};

    \draw[nearly transparent,densely dotted]
         ++(\X,\Y+0.5\base) -- +(\base,0);
    \setlength{\X}{\X + \base + \sep}
}
\def\unusedlongkey(#1)#2,#3 {
    \fill[very nearly transparent,gray]
         ++(\X,\Y) rectangle +(#1,\base);
    \draw[nearly transparent,gray]
          (\X+0.1\base,\Y+0.5\base) node[text width=2,text height=1,anchor=south] {\keyname{#2}}
         +(0.0,-0.5\base)           node[text width=2,text height=1,anchor=south] {\keyname{#3}};

    \draw[nearly transparent,densely dotted] ++(\X,\Y+0.5\base) -- +(#1,0);
    \setlength{\X}{\X + #1 + \sep}
}

\begin{document}

\begin{tikzpicture}[scale=1.6]
    \tikzstyle{every path}=[draw]

    \pgfsetcornersarced{\pgfpoint{1mm}{1mm}}

    \newlength\X
    \newlength\Y

    \Y=0\unit

    \draw (0\unit,\Y + 0.9\unit)
          node[text width=\textwidth,text height=10,text centered,anchor=west]
          {\LARGE \scshape Builtin normal mode keys of Vifm};

    \setlength{\Y}{\Y - \base - \unit + \sep}
    % numeric row
    \X=0\unit
    \fkeyd          {Esc}{cancel/\\reset\\selection}
    \keyd           !{make\\:range},1{}
    \unusedkey      @,2
    \unusedkey      \#,3
    \keyd           {\textdollar}{last\\column},4{}
    \keyd           \%{go to\\\%pos},5{}
    \keyd           \^{first\\column},6{}
    \unusedkey      \&,7
    \unusedkey      *,8
    \keyd           ({prev\\group},9{}
    \keyd           ){next\\group},0{first\\column}
    \unusedkey      \_,{\textendash}
    \keyd           +{},={local\\filter}
    \unusedlongfkey (2\base)  {Backspace}
\ifx \shortkeyboard \defined
    \setlength{\X}{\X + 0.5\base - \sep}
    \unusedfkey     {Insert}
    \fkeyd          {Home}{\shortcut{gg}}
    \fkeyd          {Page\\Up}{\shortcut{<c-b>}}
\fi

    \setlength{\Y}{\Y - \base - \sep}
    % upper row
    \X=0\unit
    \longfkeyd      (2\base - \unit) {Tab}{switch pane}
    \keyd           Q{},q{\note{1}}
    \unusedkey      W,w
    \keyd           E{},e{explore\\file}
    \keyd           R,r{\note{2}}
    \keyd           T{},t{toggle\\select}
    \keyd           Y{yank\\file(s)},y{\note{4}}
    \keyd           U{},u{undo}
    \keyd           I{},i{forced\\open}
    \unusedkey      O,o
    \keyd           P{move\\here},p{copy\\here}
    \keyd           \{{prev\\file/dir},[{\note{6}}
    \keyd           \}{next\\file/dir},]{\note{6}}
    \unusedlongkey  (\base + \unit) {\textbar},{\textbackslash}
\ifx \shortkeyboard \defined
    \setlength{\X}{\X + 0.5\base - \sep}
    \unusedfkey     {Delete}
    \fkeyd          {End}{\shortcut{G}}
    \fkeyd          {Page\\Down}{\shortcut{<c-f>}}
\fi

    \setlength{\Y}{\Y - \base - \sep}
    % home row
    \X=0\unit
    \unusedlongfkey (2\base) {Caps~Lock}
    \keyd           A{},a{\note{2,3}}
    \unusedkey      S,s
    \keyd           D{\note{11}},d{\note{11}}
    \keyd           F{to char\\fwd},f{to char\\back}
    \keyd           G{go to\\last},g{\note{7}}
    \keyd           H{to view\\top},h{parent/\\left}
    \keyd           J{},j{item\\below}
    \keyd           K{},k{item\\above}
    \keyd           L{to view\\bottom},l{open/\\right}
    \keyd           :{cmdline\\mode},;{char\\fwd}
    \keyd           "{use\\register},'{visit\\mark}
    \longfkeyd      (2\base + \sep) {Enter}{open current file(s)}

    \setlength{\Y}{\Y - \base - \sep}
    % lower row
    \X=0\unit
    \longfkeyd      (2\base + 2\sep) {Shift}{\note{5}}
    \keyd           Z{\note{10}},z{\note{8}}
    \unusedkey      X,x
    \keyd           C{clone\\file(s)},c{\note{12}}
    \keyd           V{\note{3}},v{\note{3}}
    \unusedkey      B,b
    \keyd           N{prev\\match},n{next\\match}
    \keyd           M{to view\\middle},m{set\\mark}
    \keyd           {\textless}{},,{char\\back}
    \keyd           {\textgreater}{},.{repeat\\:cmd}
    \keyd           ?{search\\back},/{search\\fwd}
    \longfkeyd      (3\base) {Shift}{\note{5}}
\ifx \shortkeyboard \defined
    \setlength{\X}{\X + 0.5\base - \sep + \base + \sep}
    \fkeyd          {$\uparrow$}{\shortcut{k}}
\fi

    \setlength{\Y}{\Y - \base - \sep}
    % space row
    \X=0\unit
    \longfkeyd      (1.5\base + \sep) {Ctrl}{\note{9}}
    \unusedlongfkey (\base)           {\faLinux}
    \unusedlongfkey (\base + \sep)    {Alt}
    \longfkeyd      (7\base)          {Space}{switch pane}
    \unusedlongfkey (\base + \sep)    {Alt}
    \unusedlongfkey (\base)           {\faLinux}
    \unusedlongfkey (\base + 2\sep)   {Menu}
    \longfkeyd      (1.5\base + \sep) {Ctrl}{\note{9}}
\ifx \shortkeyboard \defined
    \setlength{\X}{\X + 0.5\base - \sep}
    \fkeyd          {$\leftarrow$}{\shortcut{h}}
    \fkeyd          {$\downarrow$}{\shortcut{j}}
    \fkeyd          {$\leftarrow$}{\shortcut{l}}
\fi

\end{tikzpicture}

\def\blockA{
    \makeblock{4.1cm}{\note{1} external editing}{
        \begin{tabular}{lll}
            \shortcut{q:} & -- & edit : command\\
            \shortcut{q=\ q/\ q?} & -- & edit pattern\\
        \end{tabular}
    }
}
\def\blockB{
    \makeblock{4.1cm}{\note{2} symbolic links}{
        \begin{tabular}{lll}
            \shortcut{al\s/rl} & -- & absolute/relative link\\
        \end{tabular}
    }
}
\def\blockC{
    \makeblock{4.1cm}{\note{3} visual mode}{
        \begin{tabular}{lll}
            \shortcut{v\s/V} & -- & enter visual mode\\
            \shortcut{av} & -- & visual amend\\
        \end{tabular}
    }
}
\def\blockD{
    \makeblock{4.1cm}{\note{4} yanking}{
        \begin{tabular}{lll}
            \shortcut{y\s(\{motion\}\s|y\s)} & -- & yank file(s)\\
        \end{tabular}
    }
}
\def\blockE{
    \makeblock{4.1cm}{\note{5} with shift}{
        \begin{tabular}{lll}
            \shortcut{<s-tab>} & -- & switch to view pane\\
        \end{tabular}
    }
}
\def\blockF{
    \makeblock{4cm}{\note{12} changing}{
        \begin{tabular}{lll}
            \shortcut{cw} & -- & rename file(s)\\
            \shortcut{cW} & -- & rename root of current file\\
            \shortcut{cl} & -- & change symlink target\\
            \shortcut{cg} & -- & change group (*nix)\\
            \shortcut{co} & -- & change owner (*nix)\\
            \shortcut{cp} & -- & change file perms/attrs\\
        \end{tabular}
    }
}
\def\blockG{
    \makeblock{4cm}{\note{11} d* and D*}{
        \begin{tabular}{lll}
            \shortcut{d\s(\{motion\}\s|d\s)} & -- & delete file(s)\\
            \shortcut{D\s(\{motion\}\s|D\s)} & -- & perm. deletion\\
        \end{tabular}
        \begin{tabular}{lll}
            \shortcut{do\s/dp} & -- & obtain/put file(s) in diff\\
        \end{tabular}
    }
}
\def\blockH{
    \makeblock{6cm}{\note{7} g*}{
        \begin{tabular}{lll}
            \shortcut{ga\s/gA} & -- & (re)calculate size\\
            \shortcut{gt\s/gT} & -- & next/previous tab\\
        \end{tabular}
        \begin{tabular}{lll}
            \vspace{-9pt}\\
            \shortcut{gf} & -- & navigate to link target\\
            \shortcut{gf\s/gF} & -- & navigate to link target (one/all levels)\\
            \shortcut{gg} & -- & go to the first item\\
            \shortcut{gs} & -- & restore/make selection\\
            \shortcut{gv} & -- & restore visual mode\\
            \shortcut{gr} & -- & run with rights elevation (Win)\\
        \end{tabular}
        \begin{tabular}{lll}
            \vspace{-9pt}\\
            \shortcut{gU\s(\{motion\}\s|U\s|gU\s|gg\s)} & -- & to uppercase\\
            \shortcut{gu\s(\{motion\}\s|u\s|gu\s|gg\s)} & -- & to lowercase\\
        \end{tabular}
        \begin{tabular}{lll}
            \vspace{-9pt}\\
            \shortcut{gh\s/gj\s/gk\s/gl} & -- & 'lsview' \shortcut{h\s/j\s/k\s/l} analogs\\
        \end{tabular}
    }
}
\def\blockI{
    \makeblock{6cm}{\note{8} Z*, z*}{
        \begin{tabular}{lll}
            \shortcut{zj/zk} & -- & go to next/prev tree sibling\\
        \end{tabular}
        \begin{tabular}{lll}
            \vspace{-9pt}\\
            \shortcut{zx} & -- & fold tree node\\
            \shortcut{zM} & -- & apply filename filters only\\
            \shortcut{zO} & -- & remove filename filters (except local one)\\
            \shortcut{zR} & -- & filter no files\\
            \shortcut{zd} & -- & exclude custom view entry\\
            \shortcut{zf} & -- & add current file to filter\\
            \shortcut{zr} & -- & clear local filter\\
        \end{tabular}
        \begin{tabular}{lll}
            \vspace{-9pt}\\
            \hspace{6pt}\shortcut{zm\s/zo\s/za} & -- & hide/show/toggle dot files\\
            \hspace{6pt}\shortcut{zt\s/zz\s/zb} & -- & put cursor to the top/center/bottom\\
        \end{tabular}
    }
}
\def\blockK{
    \makeblock{6cm}{\note{9} with control}{
        \begin{tabular}{llllll}
            \shortcut{<c-u\s/d>} & -- & scroll half-page up/down\\
            \shortcut{<c-y\s/e>} & -- & scroll line up/down\\
            \shortcut{<c-b\s/f>} & -- & scroll page up/down\\
            \shortcut{<c-i\s/o>} & -- & history forward/backward\\
            \shortcut{<c-p\s/n>} & -- & go to item above/below\\
            \shortcut{<c-a\s/x>} & -- & inc/dec number in names\\
        \end{tabular}
        \begin{tabular}{lll}
            \vspace{-9pt}\\
            \shortcut{<c-g>} & -- & display file info\\
            \shortcut{<c-l>} & -- & redraw screen\\
            \shortcut{<c-r>} & -- & redo operation\\
            \shortcut{<c-c>} & -- & reset selection and highlight (=\shortcut{<esc>})\\
            \shortcut{<c-i>} & -- & switch pane (=\shortcut{<tab>})\\
        \end{tabular}
        \begin{tabular}{lll}
            \vspace{-9pt}\\
            \shortcut{<c-w>\s(\_\s||\s)} & -- & maximize pane size\\
            \shortcut{<c-w>H\s/J\s/K\s/L} & -- & move pane to the left/bottom/top/right\\
            \shortcut{<c-w>b\s/t} & -- & go to bottom-right/top-left pane\\
            \shortcut{<c-w>h\s/j\s/k\s/l} & -- & go to left/bottom/top/right pane\\
            \shortcut{<c-w>s\s/v\s/o} & -- & horizontal/vertical/only layout\\
        \end{tabular}
        \begin{tabular}{llllll}
            \vspace{-9pt}\\
            \shortcut{<c-w>w\s/p}       & -- & go to other pane   &\hspace{3px} \shortcut{<c-w>x} & -- & exchange panes      \\
            \shortcut{<c-w>\s(+\s|>\s)} & -- & increase pane size &\hspace{3px} \shortcut{<c-w>z} & -- & exit all view modes \\
            \shortcut{<c-w>\s(-\s|<\s)} & -- & decrease pane size &\hspace{3px} \shortcut{<c-w>=} & -- & size panes equally  \\
        \end{tabular}
    }
}
\def\blockL{
    \makeblock{6cm}{\note{10} Z*}{
        \begin{tabular}{lll}
            \shortcut{ZZ\s/ZQ} & -- & exit with/without saving state\\
        \end{tabular}
    }
}
\def\blockJ{
    \makeblock{4.1cm}{\note{6} [ and ] (upper case wraps)}{
        \begin{tabular}{lll}
            \shortcut{]c\s/[c} & -- & next/prev diff change\\
            \shortcut{]d\s/[d} & -- & next/prev dir\\
            \shortcut{[z\s/]z} & -- & first/last tree sibling\\
        \end{tabular}
        \begin{tabular}{lll}
            \shortcut{]s\s/[s\s/]S\s/]S} & -- & next/prev selected\\
            \shortcut{]r\s/[r\s/]R\s/[R} & -- & next/prev parent dir\\
        \end{tabular}
    }
}

\vspace{-2ex}
\scriptsize
\Shortunderstack{ {\protect\blockA} {\protect\blockB} {\protect\blockC}
                  {\protect\blockD} {\protect\blockE} {\protect\blockJ} }
\Shortunderstack{ {\protect\blockH} {\protect\blockI} }
\Shortunderstack{ {\protect\blockK} {\protect\blockL} }
\Shortunderstack{ {\protect\blockG} {\protect\blockF}
                  {
                    \begin{tabular}{r}
                        \vspace{60pt}\\
                        \hspace{40pt}\scriptsize \s{for Vifm v0.14}\\
                        \hspace{40pt}\scriptsize \s{(\today)}\\
                    \end{tabular}
                  } }

\end{document}
