5 no warnings 'qw'; # you know what you doing
6 no warnings 'uninitialized'; # save some useless checks for more legible code
11 if (exists $get{ascii}) {
12 $ascii = $get{ascii} ne '0'; # manual override
13 } elsif (defined $ENV{HTTP_ACCEPT_CHARSET}) {
15 for (split q{,}, $ENV{HTTP_ACCEPT_CHARSET}) {
16 $ascii = 0, last if $_ eq '*' or m{utf-?8}i;
20 my $charset = $ascii ? 'us-ascii' : 'utf-8';
21 my $ctype = "text/html; charset=$charset";
22 $header{content_type} = $ctype;
24 :><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
25 "http://www.w3.org/TR/html4/loose.dtd">
29 <title>vi cheat sheet</title>
30 <meta http-equiv="content-type" content="<:= $ctype :>">
31 <link rel="stylesheet" type="text/css" media="all" href="base.css">
32 <!--[if lte IE 6]><style> .help dl.legend dt {margin:0 0 1px} </style><![endif]-->
33 <!--[if lte IE 7]><style> .help dl.legend dd {float:none} </style><![endif]--><:
34 my %styles = map {$_ => $_} qw(dark circus mono terse);
35 our $style = exists $get{style} && $styles{$get{style}} || 'light';
36 printf(qq{\n<link rel="%s" type="text/css" media="all" href="%s" title="%s">},
37 $_ eq $style ? 'stylesheet' : 'alternate stylesheet', "$_.css", $_
40 our $showkeys = exists $get{keys} && $get{keys} ne '0';
41 print "\n<style> .no {visibility:hidden} </style>" unless $showkeys;
42 print "\n<style> .no, .alias {opacity:.5} </style>"
43 if $showkeys and $get{keys} eq 'ghost';
47 function setmode(classname) {
48 // set style for each #rows>li>ul>li to display:none unless it matches classname
49 var showclass = classname ? ' '+classname+'(?!\\w)' : '^$';
50 var parentskip = /^keys/;
51 var row = document.getElementById('rows').firstChild;
53 if (row.tagName == 'LI' && row.firstChild.tagName == 'UL'
54 && !row.firstChild.className.match(parentskip)) {
55 var el = row.firstChild.firstChild;
57 if (el.tagName == 'LI') {
58 el.style.display = el.className.match(showclass) ? 'block' : 'none';
60 } while (el = el.nextSibling);
62 } while (row = row.nextSibling);
64 // update H2 to reflect the first part of a currently active (but hidden) H3
65 var h3s = document.getElementsByTagName('H3');
66 for (var i = 0; i < h3s.length; i++) {
67 if (h3s[i].parentNode.style.display != 'block') continue;
68 document.getElementsByTagName('H2')[0].innerHTML = h3s[i].firstChild.data;
75 <h1>vi/vim cheat sheet</h1>
77 <h2>normal mode (default)</h2>
82 <ul class="keys omni">
83 <li class="mo" onclick="setmode()"><b>Esc</b> normal mode
84 <!-- not as static anymore, but never bothered; just see ^[ -->
90 arg => $ascii ? '.' : '·', # described as 'dot'
91 motion => $ascii ? '|' : '↕',
92 alias => $ascii ? 'see: ' : '»',
93 up => $ascii ? 'up' : '▲',
94 right => $ascii ? 'right' : '▶',
95 down => $ascii ? 'down' : '▼',
96 left => $ascii ? 'left' : '◀',
97 sep => $ascii ? '*' : '•',
98 _ => exists $get{ascii} && !$ascii ? "\x{200b}" : '<wbr>',
99 # use the correct ZWNJ only when unicode is forced on
100 # default to use unofficial html for best support
103 my %keys = do 'vim-cmds.inc.pl';
105 my @casedesc = qw(ctrl shift);
106 my @rowdesc = qw(numeric top home bottom);
107 my %keyrows = do 'vim-keys.inc.pl';
110 my ($key, %tree) = @_;
111 $key =~ s/(\S*?)(\^?\S)($|\s.*)/$2/;
113 return [] unless defined $keys{$mode}{$key};
114 return $keys{$mode}{$key} if ref $keys{$mode}{$key};
115 return if $tree{$key}++; # endless loop failsafe
116 return keyunalias($keys{$mode}{$key}, %tree);
129 my ($mode, $key, $keyinfo) = @_;
131 $keyinfo = [ $sign{alias}.$keyinfo, keyunalias($keyinfo)->[1] . ' alias' ]
132 if defined $keyinfo and not ref $keyinfo; # alias
133 my ($desc, $flags, $mnem) = @$keyinfo if defined $keyinfo;
134 defined $desc or $flags = $key eq '^0' ? 'ni' : 'no';
136 my $keytxt = $mode . Entity($key) if $key ne '^0';
137 $keytxt .= $sign{arg} while $flags =~ s/ ?\barg\b//; # argument
138 $keytxt .= "<small>$sign{motion}</small>" if $flags =~ s/ ?\bargm\b//; # motion argument
139 $keytxt =~ s{\^(?=.)}{<small>^</small>}; # element around ctrl-identifier
140 my $onclick = $flags =~ s/ ?\bmode(\S*)// && defined $keys{$1} && sprintf(
141 ' onclick="setmode(%s)"',
142 $1 eq '' ? '' : sprintf(q{'mode%s'}, escapeclass($1))
144 my $keyhint = defined($mnem) && qq{ title="$mnem"};
146 print qq{\t\t<li class="$flags"$onclick><b$keyhint>$keytxt</b>};
147 print ' ', $desc if defined $desc;
151 our $map = defined $keyrows{$get{map}} ? $get{map} : 'qwerty';
152 my $keyrows = $keyrows{$map};
154 for (my $row = 0; $row <= $#$keyrows; $row++) {
155 my $keyrow = $keyrows->[$row];
156 print qq{<li class="row row$row"><ul>\n};
157 while (my ($mode, $modekeys) = each %keys) {
158 for (my $case = 0; $case <= $#$keyrow; $case++) {
159 my $keycase = $keyrow->[$case];
162 printf(qq{\t<li%s><h3>%s</h3>\n}, # XXX insert here to fix msie<=6
163 $mode ne '' && sprintf(
164 ' class="%s"', 'mode mode' . escapeclass($mode)
166 sprintf('%s<small>: %s</small>',
167 $modekeys->{desc} || "mode $mode",
168 "$rowdesc[$row] row $casedesc[$case]"
171 my $modeclass = 'keys';
172 $modeclass .= ' lead' if defined $modekeys->{lead}; # leading command key shown
173 $modeclass .= " $casedesc[$case]" if defined $casedesc[$case];
174 print qq{\t\t<ul class="$modeclass">\n};
175 print_key($modekeys->{lead}, $_, $modekeys->{$_}) for @$keycase;
176 print qq{\t\t</ul>\n};
190 <dl class="legend legend-types">
192 <dd>Info command: shows/does something without altering anything.
193 <dt class="pm">motion
194 <dd>Moves the cursor, or defines the range for an operator (<:= $sign{motion} :>).
195 <dt class="po">positioning
196 <dd>Other movement (jumps, window (re)positioning).
197 <dt class="co">command
198 <dd>Direct action command.
199 <dt class="mi">ins mode
200 <dd>Enters Insert or Replace mode.
202 <dd>Enters a different mode.
203 <dt class="mv">vis mode
204 <dd>Enters Visual or Select mode.
205 <dt class="me">key cmd
206 <dd>Additional key commands (click for overview).
211 <dl class="legend legend-options">
212 <dt>key<:= $sign{arg} :>
213 <dd>Commands with a dot need a char argument afterwards.
214 <dt>key<:= $sign{motion} :>
215 <dd>Requires a motion afterwards, operates between cursor and destination.
217 <dd>Not in original Vi (assessment incomplete).
218 <dt class="vim7">vim7
219 <dd>New in vim version 7.x.
222 <ul class="legend legend-set">
223 <li>keyboard <strong>map</strong> is
224 <:= $get{map} ? 'set to ' : '' :><em><:= $map :></em>
225 <li><strong>ascii</strong> mode is
226 <:= exists $get{ascii} && 'forced ' :><em><:=
227 $ascii ? 'on' : 'off' :></em>
228 <li><strong>keys</strong> are
229 <em><:= $showkeys ? 'always shown' : 'hidden if unassigned' :></em><:=
230 exists $get{keys} || ' by default' :>
231 <li>default <strong>style</strong> is
232 <:= defined $get{style} && 'set to ' :><em><:= $style :></em>
238 <a href="http://vi.shiar.net/">vi.<strong>shiar.net</strong></a>
239 <a href="git://dev.shiar.net/vi-cheat"><:= "v$VERSION" :></a>
240 created by Shiar <:= $sign{sep} :>
241 <a title="Licensed under the GNU Affero General Public License, version 3"
242 href="http://www.fsf.org/licensing/licenses/agpl-3.0.html">AGPLv3</a> <:= $sign{sep} :>
244 use Time::Format qw(time_format);
245 print time_format('yyyy-mm-dd', (stat 'vim-cmds.inc.pl')[9]);