Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 4 commits
  • 4 files changed
  • 0 comments
  • 1 contributor
166 session-01/README.rst
Source Rendered
@@ -176,10 +176,17 @@ Examples/Showcase
176 176 Block select + Insert
177 177 ---------------------
178 178
179   -**TODO**
  179 +This can be useful to comment out a block of code.
  180 +
  181 +Example file
  182 + ``examples/javascript.js``
180 183
181   -Other useful shortcuts
182   -----------------------
  184 +1. Select a block of text using ``CTRL+V``
  185 +2. Either type ``Shift+I`` or ``Shift+A`` to insert text
  186 +3. Confirm using either ``<ESC>`` or ``CTRL+[``
  187 +
  188 +Useful shortcuts
  189 +----------------
183 190
184 191 ``gf``
185 192 Goto file under cursor
@@ -196,50 +203,60 @@ Other useful shortcuts
196 203 ``CTRL+T``
197 204 Indent current line while in insert mode
198 205
199   -**TODO**
  206 +``*``/``#``
  207 + Find the word under the cursor (forwards/backwards)
200 208
201   -Copy(Yank)/Paste
202   -----------------
  209 +``gqq``
  210 + Automatically format the current line
203 211
204   -::
  212 +``VISUAL: gq``
  213 + Automatically format the selected text
205 214
206   - NORMAL: yy, y{motion}
207   - VISUAL: y
208   - NORMAL: p/P
  215 +``CTRL+N``/``CTRL+P``
  216 + Text completion ([N]ext, [P]revious). It is very naïve and only looks for
  217 + words in all open buffers.
209 218
210   -**TODO**
  219 +Copy (Yank) / Paste
  220 +-------------------
211 221
212   -Navigation
213   -----------
  222 +Copying can be done either in normal or visual mode:
214 223
  224 +Normal
  225 + * ``yy``: yank the current line
  226 + * ``y{motion or text-object}``: yank the mentioned text-object
215 227
216   -**TODO**
  228 +Visual
  229 + * ``y``: Yank the selected text
217 230
218   -Quick commands
219   ---------------
  231 +Normal
  232 + * ``p``: Paste below the current line
  233 + * ``Shift+P``: Paste above the current line
220 234
221   -**TODO**
  235 +Navigation
  236 +----------
222 237
223   -* Quicksearch::
  238 +``h``, ``j``, ``k`` and ``l`` as navigation keys!
224 239
225   - *
226   - #
  240 +Macros
  241 +------
227 242
228   -* Text formatting::
  243 +``qa``
  244 + Start a macro recording (``a``) is a named register. It can be any
  245 + alphabetic letter. In other words, you can record up to 26 macros!
229 246
230   - NORMAL: gqq
231   - VISUAL: gq
  247 + From this point on *all* key presses will be recorded into the named macro
  248 + and can be replayed later
232 249
233   -**TODO**
  250 +``q``
  251 + Stop recording.
234 252
235   -Macros
236   -------
  253 +``@a``
  254 + Play the macro stored in register ``a``.
237 255
238   -**TODO**
  256 +``@@``
  257 + Re-execute the last executed macro.
239 258
240   -* SQL Transformation
241 259
242   -**TODO**
243 260
244 261 Folding
245 262 -------
@@ -308,8 +325,8 @@ buffers, windows, splits and tabs
308 325
309 326 **TODO**
310 327
311   -cheat sheets
312   -------------
  328 +Appendix I - Cheat Sheets
  329 +=========================
313 330
314 331 * ``:viusage``
315 332 * http://michaelgoerz.net/refcards/vimqrc.pdf
@@ -317,4 +334,91 @@ cheat sheets
317 334 * http://michael.peopleofhonoronly.com/vim/
318 335 * http://naleid.com/blog/2010/10/04/vim-movement-shortcuts-wallpaper/
319 336
  337 +Appendix II - Example Macro
  338 +===========================
  339 +
  340 +Convert a SELECT Statement to a Java class with getters and setters
  341 +-------------------------------------------------------------------
  342 +
  343 +* Open the file examples/sql.sql::
  344 +
  345 + :e examples/sql.sql
  346 +
  347 +* Yank the line containing the SELECT statement::
  348 +
  349 + /SELECT<CR>yy
  350 +
  351 +* Open a new file::
  352 +
  353 + :e Client.java
  354 +
  355 +* Paste the line::
  356 +
  357 + <SHIFT+P>
  358 +
  359 +* Yank the name of the table (the last word)::
  360 +
  361 + $Bye
  362 +
  363 +* Add a new line below this one, and insert the class statement::
  364 +
  365 + o
  366 + public class<ESC>
  367 +
  368 +* Paste the table name, and uppercase the first character::
  369 +
  370 + pb~
  371 +
  372 +* Add the beginning and ending braces::
  373 +
  374 + A{<CR>}<ESC>
  375 +
  376 +* Go back to the first line (the SELECT statement), and extract the field names::
  377 +
  378 + gg
  379 + dw
  380 + /FROM<CR>
  381 + hD
  382 +
  383 +* Move the line below the "class" line (delete + paste)::
  384 +
  385 + ddp
  386 +
  387 +* Replace all occurences of ``", "`` with a newline::
  388 +
  389 + V
  390 + :s/, /<CTRL+V><CR>/g
  391 +
  392 +* Jump back to the original position::
  393 +
  394 + ggj
  395 +
  396 +* Start the macro::
  397 +
  398 + qq
  399 +
  400 +* Record the following actions::
  401 +
  402 + "tye
  403 + I<CTRL+t>
  404 + public String get<ESC>
  405 + l~
  406 + A(){<CR>
  407 + return this.<CTRL+R>t;<CR>
  408 + }<CR><CR>
  409 + public void set<CTRL+R>t<ESC>
  410 + Blll~
  411 + A(String<SPACE>
  412 + <CTRL+R>t
  413 + ){<CR>
  414 + this.<CTRL+R>t = <CTRL+R>t;<CR>
  415 + }<CR><ESC>
  416 + j0
  417 + q
  418 +
  419 +* This macro can now be executed by positioning the cursor on the beginning of
  420 + the next field (should be already the case), and by typing ``@q``.
320 421
  422 + This macro makes sure that the cursor position after executing it allows us
  423 + to execute it again without moving the cursor. This in turn allows us to
  424 + repeat the macro (for example 10 times) by typing ``10@q``.
23 session-01/examples/html.html
... ... @@ -0,0 +1,23 @@
  1 +{% extends "base.html" %}
  2 +{% block title %}Device List{% endblock %}
  3 +{% block content %}
  4 +<h1>Device List</h1>
  5 +
  6 +<table>
  7 + <thead>
  8 + <tr>
  9 + <th>Hostname</th>
  10 + </tr>
  11 + </thead>
  12 + <tbody>
  13 + {% for device in devices %}
  14 + <tr>
  15 + <td><a href="{{url_for('device', device_name=device.hostname)}}">{{ device.hostname }}</a></td>
  16 + </tr>
  17 + {% endfor %}
  18 + </tbody>
  19 +</table>
  20 +
  21 +{% endblock %}
  22 +
  23 +{# vim: set filetype=jinja : #}
29 session-01/examples/javascript.js
... ... @@ -0,0 +1,29 @@
  1 +/** Updates the devices combobox.
  2 + *
  3 + * @param {string} ctName The name of the CT.
  4 + * @param {Object} opt_default The entry which should be selected by default.
  5 + */
  6 +ipbase.views.ReservePort.prototype.updateDevices = function(ctName, opt_default) {
  7 + var that = this;
  8 + var location_id = ctName.replace(
  9 + new RegExp(ipbase.model.ct.prototype.SIMPLE_ROW_FORMAT), '$1');
  10 + goog.dom.forms.setValue(goog.dom.getElement('location'), location_id);
  11 + var ct = new ipbase.model.ct(location_id);
  12 + ct.devices(function(devices) {
  13 + if (this.device_selector === null) {
  14 + that.logger.warning('Device selector is null!');
  15 + return;
  16 + }
  17 +
  18 + that.device_selector.removeAllItems();
  19 + for (var i in devices) {
  20 + that.device_selector.addItem(
  21 + new goog.ui.ComboBoxItem(devices[i].hostname, devices[i]));
  22 + }
  23 +
  24 + if (goog.isDefAndNotNull(opt_default)) {
  25 + // @todo: add 'replacement' (part of PK)
  26 + that.device_selector.setValue(opt_default.hostname);
  27 + }
  28 + });
  29 +}
11 session-01/examples/sql.sql
... ... @@ -0,0 +1,11 @@
  1 +CREATE TABLE client (
  2 + email varchar(128) NOT NULL PRIMARY KEY,
  3 + first_name varchar(20),
  4 + last_name varchar(20),
  5 + tel varchar(10)
  6 +);
  7 +
  8 +
  9 +SELECT email, first_name, last_name, tel FROM client;
  10 +
  11 +

No commit comments for this range

Something went wrong with that request. Please try again.