-
-<h1>vi/vim cheat sheet</h1>
-
-<h2>normal mode (default)</h2>
-
-<ul id="rows">
-
-<li class="row">
- <ul class="keys omni">
- <li class="mo" onclick="setmode()"><b>Esc</b> normal mode
- <!-- not as static anymore, but never bothered; just see ^[ -->
- </ul>
-</li>
-
-<:
-our %sign = (
- arg => $ascii ? "." : "·", # described as 'dot'
- motion => $ascii ? "|" : "↕",
- alias => $ascii ? "see: " : "»",
- up => $ascii ? "up" : "▲",
- right => $ascii ? "right" : "▶",
- down => $ascii ? "down" : "▼",
- left => $ascii ? "left" : "◀",
- sep => $ascii ? "*" : "•",
- _ => exists $get{ascii} && !$ascii ? "\x{200b}" : "<wbr>",
- # use the correct ZWNJ only when unicode is forced on
- # default to use unofficial html for best support
-);
-
-my %keys = do "vim-cmds.inc.pl";
-
-my @casedesc = qw(ctrl shift);
-my @rowdesc = qw(numeric top home bottom);
-my %keyrows = do "vim-keys.inc.pl";
-
-sub keyunalias {
- my ($key, %tree) = @_;
- $key =~ s/(\S*?)(\^?\S)($|\s.*)/$2/;
- my $mode = $1;
- return [] unless defined $keys{$mode}{$key};
- return $keys{$mode}{$key} if ref $keys{$mode}{$key};
- return if $tree{$key}++; # endless loop failsafe
- return keyunalias($keys{$mode}{$key}, %tree);
-}
-
-sub escapeclass {
- local $_ = shift;
- s/\^/_c/g;
- s/\[/_sbo/g;
- s/\]/_sbc/g;
- s/^$/_/;
- return $_;
-}
-
-our $map = defined $keyrows{$get{map}} ? $get{map} : "qwerty";
-my $keyrows = $keyrows{$map};
-
-for (my $row = 0; $row <= $#$keyrows; $row++) {
- my $keyrow = $keyrows->[$row];
- print qq{<li class="row row$row"><ul>\n};
- while (my ($mode, $modekeys) = each %keys) {
- for (my $case = 0; $case <= $#$keyrow; $case++) {
- my $keycase = $keyrow->[$case];
- @$keycase or next;
-
- printf(qq{\t<li%s><h3>%s</h3>\n}, # XXX insert here to fix msie<=6
- $mode eq '' ? '' : sprintf(
- ' class="%s"', "mode mode" . escapeclass($mode)
- ),
- sprintf('%s<small>: %s</small>',
- $modekeys->{desc} || "mode $mode",
- "$rowdesc[$row] row $casedesc[$case]"
- )
- );
- my $modeclass = "keys";
- $modeclass .= " lead" if defined $modekeys->{lead}; # leading command key shown
- $modeclass .= " $casedesc[$case]" if defined $casedesc[$case];
- print qq{\t\t<ul class="$modeclass">\n};
-
- for my $key (@$keycase) {
- my $keyinfo = $modekeys->{$key};
- $keyinfo = [ $sign{alias}.$keyinfo, keyunalias($keyinfo)->[1] . " alias" ]
- if defined $keyinfo and not ref $keyinfo; # alias
- my ($desc, $flags, $mnem) = @$keyinfo if defined $keyinfo;
- defined $desc or $flags = $key eq '^0' ? "ni" : "no";
-
- my $keytxt = $modekeys->{lead} . Entity($key) if $key ne '^0';
- $keytxt .= $sign{arg} while $flags =~ s/ ?\barg\b//; # argument
- $keytxt .= "<small>$sign{motion}</small>" if $flags =~ s/ ?\bargm\b//; # motion argument
- $keytxt =~ s{\^(?=.)}{<small>^</small>}; # element around ctrl-identifier
- my $onclick = $flags =~ s/ ?\bmode(\S*)// && defined $keys{$1} && sprintf(
- ' onclick="setmode(%s)"',
- $1 eq '' ? '' : sprintf("'mode%s'", escapeclass($1))
- );
- my $keyhint = defined($mnem) && qq{ title="$mnem"};
-
- print qq{\t\t<li class="$flags"$onclick><b$keyhint>$keytxt</b>};
- print ' ', $desc if defined $desc;
- print "\n";
- } # key
-
- print qq{\t\t</ul>\n};
- } # case
-
- } # mode
- print qq{\t</ul>\n};
-} # row
-
-:>
-</ul>
-
-<hr>
-
-<div class="help">
- <div class="left">
- <dl class="legend legend-types">
- <dt class="ci">info
- <dd>Info command: shows/does something without altering anything.
- <dt class="pm">motion
- <dd>Moves the cursor, or defines the range for an operator (<:= $sign{motion} :>).
- <dt class="po">positioning
- <dd>Other movement (jumps, window (re)positioning).
- <dt class="co">command
- <dd>Direct action command.
- <dt class="mi">ins mode
- <dd>Enters Insert or Replace mode.
- <dt class="mo">mode
- <dd>Enters a different mode.
- <dt class="mv">vis mode
- <dd>Enters Visual or Select mode.
- <dt class="me">key cmd
- <dd>Additional key commands (click for overview).
- </dl>
- </div>
-
- <div class="right">
- <dl class="legend legend-options">
- <dt>key<:= $sign{arg} :>
- <dd>Commands with a dot need a char argument afterwards.
- <dt>key<:= $sign{motion} :>
- <dd>Requires a motion afterwards, operates between cursor and destination.
- <dt class="vim">vim
- <dd>Not in original Vi (assessment incomplete).
- <dt class="vim7">vim7
- <dd>New in vim version 7.x.
- </dl>
-
- <ul class="legend legend-set">
- <li>keyboard <strong>map</strong> is
- <:= $get{map} ? "set to " : "" :><em><:= $map :></em>
- <li><strong>ascii</strong> mode is
- <:= exists $get{ascii} ? "forced " : "" :><em><:=
- $ascii ? "on" : "off" :></em>
- <li><strong>keys</strong> are
- <em><:= $showkeys ? "always shown" : "hidden if unassigned" :></em><:=
- exists $get{keys} ? "" : " by default" :>
- <li>default <strong>style</strong> is
- <:= defined $get{style} ? "set to " : "" :><em><:= $style :></em>
- </ul>
- </div>
-</div>
-
-<p class="footer">
- <a href="http://<:= $ENV{SERVER_NAME} :>/vim-cheat">shiar.demon.nl/<b>vim-cheat</b></a>
- <a href="vim-cheat.tar.gz"><:= "v$VERSION" :></a>
- created by Shiar <:= $sign{sep} :> last update <:
- use Time::Format qw(time_format);
- print time_format("yyyy-mm-dd", (stat "vim-cmds.inc.pl")[9]);
- :>
-</p>
-