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 ^@ NUL ^a SOH ^b STX ^c ETX ^d EOT ^e ENQ ^f ACK ^g BEL
130 ^h BS ^i tab ^j LF ^k VT ^l FF ^m CR ^n SO ^o SI
131 ^p DLE ^q DC1 ^r DC2 ^s DC3 ^t DC4 ^u NAK ^v SYN ^w ETB
132 ^x CAN ^y EM ^z SUB ^[ ESC ^\ FS ^] GS ^^ RS ^_ US
137 my ($mode, $key, $keyinfo) = @_;
139 $keyinfo = [ $sign{alias}.$keyinfo, keyunalias($keyinfo)->[1] . ' alias' ]
140 if defined $keyinfo and not ref $keyinfo; # alias
141 my ($desc, $flags, $mnem) = @$keyinfo if defined $keyinfo;
142 defined $desc or $flags = $key eq '^0' ? 'ni' : 'no';
144 # $key = $keytrans{$key} if defined $keytrans{$key};
145 my $keytxt = $mode . Entity($key) if $key ne '^0';
146 $keytxt .= $sign{arg} while $flags =~ s/ ?\barg\b//; # argument
147 $keytxt .= "<small>$sign{motion}</small>" if $flags =~ s/ ?\bargm\b//; # motion argument
148 $keytxt =~ s{\^(?=.)}{<small>^</small>}; # element around ctrl-identifier
149 my $onclick = $flags =~ s/ ?\bmode(\S*)// && defined $keys{$1} && sprintf(
150 ' onclick="setmode(%s)"',
151 $1 eq '' ? '' : sprintf(q{'mode%s'}, escapeclass($1))
153 $onclick .= sprintf(q{ onclick="document.location='%s'"}, $1)
154 if $flags =~ s/ ?\blink(\S*)//;
155 my $keyhint = defined($mnem) && qq{ title="$mnem"};
157 print qq{\t\t<li class="$flags"$onclick><b$keyhint>$keytxt</b>};
158 print ' ', $desc if defined $desc;
162 our $map = defined $keyrows{$get{map}} ? $get{map} : 'qwerty';
163 my $keyrows = $keyrows{$map};
165 for (my $row = 0; $row <= $#$keyrows; $row++) {
166 my $keyrow = $keyrows->[$row];
167 print qq{<li class="row row$row"><ul>\n};
168 while (my ($mode, $modekeys) = each %keys) {
169 for (my $case = 0; $case <= $#$keyrow; $case++) {
170 my $keycase = $keyrow->[$case];
173 printf "\t<li%s>", $mode ne '' && sprintf(
174 ' class="%s"', 'mode mode' . escapeclass($mode)
176 printf("<h3>%s<small>: %s</small></h3>\n", # XXX insert here to fix msie<=6
177 $modekeys->{desc} || "mode $mode",
178 "$rowdesc[$row] row $casedesc[$case]"
180 my $caseclass = 'keys';
181 $caseclass .= ' lead' if defined $modekeys->{lead}; # leading command key shown
182 $caseclass .= " $casedesc[$case]" if defined $casedesc[$case];
183 print qq{\t\t<ul class="$caseclass">\n};
184 print_key($modekeys->{lead}, $_, $modekeys->{$_}) for @$keycase;
185 print qq{\t\t</ul>\n};
199 <dl class="legend legend-types">
201 <dd>Info command: shows/does something without altering anything.
202 <dt class="pm">motion
203 <dd>Moves the cursor, or defines the range for an operator (<:= $sign{motion} :>).
204 <dt class="po">positioning
205 <dd>Other movement (jumps, window (re)positioning).
206 <dt class="co">command
207 <dd>Direct action command.
208 <dt class="mi">ins mode
209 <dd>Enters Insert or Replace mode.
211 <dd>Enters a different mode.
212 <dt class="mv">vis mode
213 <dd>Enters Visual or Select mode.
214 <dt class="me">key cmd
215 <dd>Additional key commands (click for overview).
220 <dl class="legend legend-options">
221 <dt>key<:= $sign{arg} :>
222 <dd>Commands with a dot need a char argument afterwards.
223 <dt>key<:= $sign{motion} :>
224 <dd>Requires a motion afterwards, operates between cursor and destination.
226 <dd>Not in original Vi (assessment incomplete).
227 <dt class="vim7">vim7
228 <dd>New in vim version 7.x.
231 <ul class="legend legend-set">
232 <li>keyboard <strong>map</strong> is
233 <:= $get{map} ? 'set to ' : '' :><em><:= $map :></em>
234 <li><strong>ascii</strong> mode is
235 <:= exists $get{ascii} && 'forced ' :><em><:=
236 $ascii ? 'on' : 'off' :></em>
237 <li><strong>keys</strong> are
238 <em><:= $showkeys ? 'always shown' : 'hidden if unassigned' :></em><:=
239 !exists $get{keys} && ' by default' :>
240 <li>default <strong>style</strong> is
241 <:= defined $get{style} && 'set to ' :><em><:= $style :></em>
247 <a href="http://vi.shiar.net/">vi.<strong>shiar.net</strong></a>
248 <a href="git://dev.shiar.net/vi-cheat"><:= "v$VERSION" :></a>
249 created by Shiar <:= $sign{sep} :>
250 <a title="Licensed under the GNU Affero General Public License, version 3"
251 href="http://www.fsf.org/licensing/licenses/agpl-3.0.html">AGPLv3</a> <:= $sign{sep} :>
253 use Time::Format qw(time_format);
254 print time_format('yyyy-mm-dd', (stat 'vim-cmds.inc.pl')[9]);