5 no warnings "qw"; # you know what you doing
6 no warnings "uninitialized"; # save some useless checks for more legible code
8 # 2006-03-29 ~20:00 started work
9 # 2006-03-30 11:58 html version
10 # 2006-05-20 03:44 perl version
11 # 2007-02-07 07:34 cleaned up
12 # 2007-02-25 04:00 v1.0: git repository
17 if (exists $get{ascii}) {
18 $ascii = $get{ascii} ne "0"; # manual override
19 } elsif (defined $ENV{HTTP_ACCEPT_CHARSET}) {
21 for (split ",", $ENV{HTTP_ACCEPT_CHARSET}) {
22 $ascii = 0, last if $_ eq "*" or m/utf-?8/i;
26 my $charset = $ascii ? "us-ascii" : "utf-8";
27 my $ctype = "text/html; charset=$charset";
28 $header{content_type} = $ctype;
30 :><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
31 "http://www.w3.org/TR/html4/loose.dtd">
35 <title>vi cheat sheet</title>
36 <meta http-equiv="content-type" content="<:= $ctype :>">
37 <link rel="stylesheet" type="text/css" media="all" href="base.css">
38 <!--[if lte IE 6]><style> .help dl.legend dt {margin:0 0 1px} </style><![endif]-->
39 <!--[if lte IE 7]><style> .help dl.legend dd {float:none} </style><![endif]--><:
40 my %styles = map {$_ => $_} qw(dark circus mono);
41 our $style = exists $get{style} && $styles{$get{style}} || "light";
42 printf(qq{\n<link rel="%s" type="text/css" media="all" href="%s" title="%s">},
43 $_ eq $style ? "stylesheet" : "alternate stylesheet", "$_.css", $_
46 our $showkeys = exists $get{keys} && $get{keys} ne "0";
47 print "\n<style> .no {visibility:hidden} </style>" unless $showkeys;
48 print "\n<style> .no, .alias {opacity:.5} </style>"
49 if $showkeys and $get{keys} eq "ghost";
53 function setmode(classname) {
54 // set style for each #rows>li>ul>li to display:none unless it matches classname
55 var showclass = classname ? ' '+classname+'(?!\\w)' : '^$';
56 var parentskip = /^keys/;
57 var row = document.getElementById('rows').firstChild;
59 if (row.tagName == 'LI' && row.firstChild.tagName == 'UL'
60 && !row.firstChild.className.match(parentskip)) {
61 var el = row.firstChild.firstChild;
63 if (el.tagName == 'LI') {
64 el.style.display = el.className.match(showclass) ? 'block' : 'none';
66 } while (el = el.nextSibling);
68 } while (row = row.nextSibling);
70 // update H2 to reflect the first part of a currently active (but hidden) H3
71 var h3s = document.getElementsByTagName('H3');
72 for (var i = 0; i < h3s.length; i++) {
73 if (h3s[i].parentNode.style.display != 'block') continue;
74 document.getElementsByTagName('H2')[0].innerHTML = h3s[i].firstChild.data;
81 <h1>vi/vim cheat sheet</h1>
83 <h2>normal mode (default)</h2>
88 <ul class="keys omni">
89 <li class="mo" onclick="setmode()"><b>Esc</b> normal mode
90 <!-- not as static anymore, but never bothered; just see ^[ -->
96 arg => $ascii ? "." : "·", # described as 'dot'
97 motion => $ascii ? "|" : "↕",
98 alias => $ascii ? "see: " : "»",
99 up => $ascii ? "up" : "▲",
100 right => $ascii ? "right" : "▶",
101 down => $ascii ? "down" : "▼",
102 left => $ascii ? "left" : "◀",
103 sep => $ascii ? "*" : "•",
104 _ => exists $get{ascii} && !$ascii ? "\x{200b}" : "<wbr>",
105 # use the correct ZWNJ only when unicode is forced on
106 # default to use unofficial html for best support
109 my %keys = do "vim-cmds.inc.pl";
111 my @casedesc = qw(ctrl shift);
112 my @rowdesc = qw(numeric top home bottom);
113 my %keyrows = do "vim-keys.inc.pl";
116 my ($key, %tree) = @_;
117 $key =~ s/(\S*?)(\^?\S)($|\s.*)/$2/;
119 return [] unless defined $keys{$mode}{$key};
120 return $keys{$mode}{$key} if ref $keys{$mode}{$key};
121 return if $tree{$key}++; # endless loop failsafe
122 return keyunalias($keys{$mode}{$key}, %tree);
134 our $map = defined $keyrows{$get{map}} ? $get{map} : "qwerty";
135 my $keyrows = $keyrows{$map};
137 for (my $row = 0; $row <= $#$keyrows; $row++) {
138 my $keyrow = $keyrows->[$row];
139 print qq{<li class="row row$row"><ul>\n};
140 while (my ($mode, $modekeys) = each %keys) {
141 for (my $case = 0; $case <= $#$keyrow; $case++) {
142 my $keycase = $keyrow->[$case];
145 printf(qq{\t<li%s><h3>%s</h3>\n}, # XXX insert here to fix msie<=6
146 $mode eq '' ? '' : sprintf(
147 ' class="%s"', "mode mode" . escapeclass($mode)
149 sprintf('%s<small>: %s</small>',
150 $modekeys->{desc} || "mode $mode",
151 "$rowdesc[$row] row $casedesc[$case]"
154 my $modeclass = "keys";
155 $modeclass .= " lead" if defined $modekeys->{lead}; # leading command key shown
156 $modeclass .= " $casedesc[$case]" if defined $casedesc[$case];
157 print qq{\t\t<ul class="$modeclass">\n};
159 for my $key (@$keycase) {
160 my $keyinfo = $modekeys->{$key};
161 $keyinfo = [ $sign{alias}.$keyinfo, keyunalias($keyinfo)->[1] . " alias" ]
162 if defined $keyinfo and not ref $keyinfo; # alias
163 my ($desc, $flags, $mnem) = @$keyinfo if defined $keyinfo;
164 defined $desc or $flags = $key eq '^0' ? "ni" : "no";
166 my $keytxt = $modekeys->{lead} . Entity($key) if $key ne '^0';
167 $keytxt .= $sign{arg} while $flags =~ s/ ?\barg\b//; # argument
168 $keytxt .= "<small>$sign{motion}</small>" if $flags =~ s/ ?\bargm\b//; # motion argument
169 $keytxt =~ s{\^(?=.)}{<small>^</small>}; # element around ctrl-identifier
170 my $onclick = $flags =~ s/ ?\bmode(\S*)// && defined $keys{$1} && sprintf(
171 ' onclick="setmode(%s)"',
172 $1 eq '' ? '' : sprintf("'mode%s'", escapeclass($1))
174 my $keyhint = defined($mnem) && qq{ title="$mnem"};
176 print qq{\t\t<li class="$flags"$onclick><b$keyhint>$keytxt</b>};
177 print ' ', $desc if defined $desc;
181 print qq{\t\t</ul>\n};
195 <dl class="legend legend-types">
197 <dd>Info command: shows/does something without altering anything.
198 <dt class="pm">motion
199 <dd>Moves the cursor, or defines the range for an operator (<:= $sign{motion} :>).
200 <dt class="po">positioning
201 <dd>Other movement (jumps, window (re)positioning).
202 <dt class="co">command
203 <dd>Direct action command.
204 <dt class="mi">ins mode
205 <dd>Enters Insert or Replace mode.
207 <dd>Enters a different mode.
208 <dt class="mv">vis mode
209 <dd>Enters Visual or Select mode.
210 <dt class="me">key cmd
211 <dd>Additional key commands (click for overview).
216 <dl class="legend legend-options">
217 <dt>key<:= $sign{arg} :>
218 <dd>Commands with a dot need a char argument afterwards.
219 <dt>key<:= $sign{motion} :>
220 <dd>Requires a motion afterwards, operates between cursor and destination.
222 <dd>Not in original Vi (assessment incomplete).
223 <dt class="vim7">vim7
224 <dd>New in vim version 7.x.
227 <ul class="legend legend-set">
228 <li>keyboard <strong>map</strong> is
229 <:= $get{map} ? "set to " : "" :><em><:= $map :></em>
230 <li><strong>ascii</strong> mode is
231 <:= exists $get{ascii} ? "forced " : "" :><em><:=
232 $ascii ? "on" : "off" :></em>
233 <li><strong>keys</strong> are
234 <em><:= $showkeys ? "always shown" : "hidden if unassigned" :></em><:=
235 exists $get{keys} ? "" : " by default" :>
236 <li>default <strong>style</strong> is
237 <:= defined $get{style} ? "set to " : "" :><em><:= $style :></em>
243 <a href="http://<:= $ENV{SERVER_NAME} :>/vim-cheat">shiar.demon.nl/<b>vim-cheat</b></a>
244 <a href="vim-cheat.tar.gz"><:= "v$VERSION" :></a>
245 created by Shiar <:= $sign{sep} :> last update <:
246 use Time::Format qw(time_format);
247 print time_format("yyyy-mm-dd", (stat "vim-cmds.inc.pl")[9]);