boon/TUTORIAL.txt
Jean-Philippe Bernardy c2642ff463 update the tutorial
2016-08-27 20:31:00 +02:00

397 lines
12 KiB
Text

Boon tutorial. See end for copying conditions.
This tutorial assumes that you know Emacs already.
Make sure boon is installed. Load the colemak configuration with:
(require 'boon-colemak)
You may also additionally
(require 'boon-extras)
if you like.
Turn on boon globally with
(boon-mode)
If you just eval'ed the above, Boon may not be active in the current
buffer. If it is not activated, activate it by
M-x turn-on-boon-mode
Boon indicates the difference between command mode and insert mode in
several ways:
- The modeline says Boon:<STATE> (where state can be INS or CMD)
- The cursor is a box in command mode, and a bar in insert mode.
- If you eval (boon-powerline-theme) and have powerline installed then
the mode text will be of various colors.
You can switch from command to insert mode by typing v (mnemonic: v
looks like an insert mark) and back to command mode by typing <ESC>.
>> Switch to command mode now (type <ESC>)
Most Emacs keychord commands via M-... and C-... are accessible as
normal. For example, M-x turn-off-boon-mode reverts to your regular
experience.
The characters ">>" at the left margin indicate directions for you to
try using a command. For instance:
>> Type C-u and C-y to scroll this text
* BASIC CURSOR CONTROL
----------------------
How do you move to a specific place within the text on the screen?
The whole right-hand side of the keyboard is dedicated to this
purpose.
There are several ways you can do this. You can still use the arrow
keys, but it's more efficient to keep your right hand around the home
row and use the commands: e i u y. These characters are equivalent to
the four arrow keys, like this:
Previous line, u
:
:
Backward, e .... Current cursor position .... Forward, i
:
:
Next line, y
>> Move the cursor to the line in the middle of that diagram.
You'll find it easy to remember these letters by their location on the
keyboard. In fact, most of the time you'll forget what you're typing
exactly, and just know intuitively what you're doing. Note that,
when you navigate within a line your hand stays on the home row.
Navigating lines happens on the top row. Soon you will forget the
letters that your hand is typing when moving the cursor. You will be
using these basic cursor positioning commands a lot, but there are
faster ways to go about moving the cursor.
If moving by characters is too slow, you can move by words. The key "o"
moves forward a word and "n" moves back a word.
>> Type a few o's and n's.
As in regular Emacs, when you are in the middle of a word, o moves to
the end of the word. When you are in white space between words, o
moves to the end of the following word. "n" works likewise in the
opposite direction. In fact, o and n move by whole syntactic units:
they will skip over parentheses when it makes sense.
>> Move the cursor to the '*' in the following expression. Move to the
relevant line, then type o and n a few times. Combine these keys
with e and i to get to the place you want.
54 / ((8 + y) * (x - 3))
Notice that you can quickly move in the expression while staying
comfortably on the home row.
You can move to the beginning or end of a line by typing "l" or ";".
As u and y, these line-based commands are on the top row. Emacs tries
to manage the cursor position inside a line intelligently. This often
works, but one sometimes need to quickly move to the beginning or end
of line after moving up or down. You can do all this by staying on the
top row.
If you want to speed up moving up and down, use the shift key: "U" and
"Y" move by whole paragraphs.
>> Try a couple of "U", and then a couple of "Y".
>> Try a couple of "l", and then a couple of ";"
Checkout the cheat sheet (linked from README) for a summary of
movement operations.
>> Try all of these commands now a few times for practice.
These are the most often used commands.
Two other (less important) cursor motion commands are "<" (two
characters), which moves to the beginning of the whole text, and ">",
which moves to the end of the whole text.
>> Try < now, to move to the beginning of the tutorial.
Then use Y repeatedly to move back here.
You can type a prefix argument by typing the numbers before the
command.
>> Move forward by seven words.
To insert a character several times, you can use the escaping
command "q" (mnemonic: quote).
>> Try that now -- type 8 q * to insert ********.
* OTHER MOVEMENT COMMANDS
-------------------------
There are two other movement commands, bound to h and k.
- k (mnemonic: bacK to marK) jumps pops a mark and jumps to it. (If a region is active, exchange point and mark)
- h (mnemonic: hop) activates avy-goto-word-1 (if installed)
- Additionally, j is bound to 'jump to definition' which is
mode-dependent.
* IF EMACS STOPS RESPONDING
---------------------------
If Emacs stops responding to your commands, you can stop it safely by
typing C-g. You can use C-g to stop a command which is taking too
long to execute.
You can also use C-g to discard a numeric argument or the beginning of
a command that you do not want to finish.
<ESC> is an alternative which works in many contexts.
* C-x prefix
-------------
Instead of the C-x prefix; you may just type 'x'
>> Type x 2 to split this window
>> Type x 1 to close the other windows
Additionally, the execute-command command (M-x) is bound to 'xx'
* C-c prefix
------------
Mode-specific commands have often the form "C-c C-<key>". These are
accessible by typing simply "c <key>" from command mode. Unfortunately
there is no such binding in text mode by default --- so you cannot
test this right away.
* INSERTING AND DELETING
------------------------
If you want to insert text, type 'v' (can you remember the mnemonic?).
Ordinary characters, like A, 7, *, etc., are then inserted as you type
them. To insert a Newline character, simply type <Return>.
In insert mode, regular Emacs editing commands can be used.
>> Type v to insert some text; then <ESC> to go back to command mode.
Deleting text is mostly done with the 't' command (mnemonic: take).
The take command expects an argument. This argument can be any
right-hand move command, such as 'e' (backward-char).
>> Type "te" to delete the character before the cursor
In the above "e" is the argument to the "t" command.
>> Type "tn" to delete backwards, up to the beginning of a word
You can also use a left-hand _region specifier_ as an argument to
'take'. Such arguments include 's': the symbol at point.
>> Type "ts" to delete the symbol where the cursor is (even if in the
middle of the symbol)
One of the most useful region specifier is <spc>, which refers to the
current line.
>> Type "t<spc>" to delete the current line.
The region specifiers are defined in the boon-select-map keymap. (Type
C-h v boon-select-map to inspect it)
Region arguments can be given a repeat count.
>> Type "t7e" to delete seven characters forward.
You can also kill a segment of text by selecting it first, then use
the kill command. Move to one end of that part, and type <SPC>.
(<SPC> is the Space bar.) Next, move the cursor to the other end of
the text you intend to kill. As you do this, Emacs highlights the
text between the cursor and the position where you typed <SPC>.
Finally, type "t". This kills all the text between the two positions.
>> Move the cursor to the Y at the start of the previous paragraph.
>> Type <SPC>. Emacs should display a message "mark 0"
at the bottom of the screen.
>> Move the cursor to the n in "end", on the second line of the
paragraph.
>> Type t. This will kill the text starting from the Y,
and ending just before the n.
Selecting text with <SPC> actually takes a region argument. When this
argument is a move command, <SPC> behaves like putting a mark at the
current point. But, <SPC> can take any region argument, including
left-hand ones.
>> Type "<SPC>p" to select a paragraph
>> Type <SPC> again to undo the selection
In particular, the region specifier "current line" (<SPC>) can be
given to the marking command (<SPC>).
>> Type <SPC><SPC> to select the current line
>> Type "y" a few times to select some lines
>> Type "t" to delete all these lines
You can kill and switch to insert mode in a single command, bound to
'r' (mnemonic: replace).
>> Try typing 'rs' to replace the symbol at point.
The command for yanking is "s". (mnemonic: splice)
>> Try it; type s to yank the text back.
(Shifted "S" does yank-pop.)
It is often the case that yanking a word does not give correct
spacing. You can automatically fix the spacing after a yanking by
repeating the command; (type 'ss').
>> Kill the word between parentesis, for example by using "ts": (very).
>> Yank it somewhere in a sentence using "ss".
* UNDO
------
Undo is bound to "-" (minus); while redo is bound to "_" (underscore).
* PARENS
--------
Boon provides help to manipulate parentheses.
The command 'a' (mnemonic: around) adds parentheses around a region.
It takes two arguments:
1. the kind of parentheses to use ('p' for regular parentheses)
2. the region to surround. This region is specified by the same
language as the 't' command
>> Move the cursor inside a word and type 'aps' to
enclose it in parens.
>> Inspect the kind of parentheses available by typing 'C-h v boon-enclosures <RET>'
It is possible to remove parentheses by using the 'a' operator, which
transforms a region argument to its enclosure.
>> Move the cursor inside a (sexp), and type 'tx' to delete the
expression.
>> Move the cursor inside another (sexp), and type 'tax' to delete the
parens.
The 'a' operator is especially useful when applied to 'x' (sexp), 'n'
and 'o' --- but works on any region.
* SEARCHING
-----------
Searching is bound to "f<key>" (search forward) and "w<key>" (search backward).
The <key> stands for the kind of thing you want to search. For example
"fe" moves to the next error. "f<spc>" does incremental search. "fs"
searches the symbol at point. "F" finds the next occurence. Use "f
C-h" to see all the things you can search.
* MULTIPLE REGIONS, MULTIPLE CURSORS
------------------------------------
Boon provides a region operator to work on all occurences of a string
in a region. This operator takes two arguments: 1. the string 2. the
region where to match the string. The string itself is specified by a
region containing it. For example, you can remove all occurences of
boon in this paragraph.
>> Move the cursor inside the word 'boon' in the above paragraph
>> Type 't@sp'
If you have the 'multiple-cursors' package installed, you can also
replace such occurences.
>> Undo the previous command
>> Move the cursor inside the word 'boon' in the above paragraph
>> Type 'r@sp'
Boon has special support for multiple cursors, which means that all
commands described above should work out of the box with multiple
cursors.
* HELM
-------
Helm is a very useful package. Boon provides special support for it.
>> If you have not done it yet, install helm now. (package-install 'helm)
The command 'p' starts helm-occur; which does a quick search for all
occurrences of a pattern in the current buffer.
>> Type 'p' now
>> type "helm" <return> to jump to the beginning of this section.
You can search for the current symbol by typing "<spc>" in an empty
helm mini-buffer.
>> Move the cursor to an occurrence of the helm word, and type "p<spc>".
>> Use C-y and C-u to select an occurrence, then type <return> to jump to
the currently selected occurrence
Other, less common uses for helm are bound to "g<key>".
>> Type "g C-h" to see the bound helm variants.
* SPECIAL BUFFERS
-----------------
Certain emacs mode already offer their "own" command system. Such
modes include 'dired', 'magit', and others. In such buffers, it makes
little sense to have an 'insert mode', and most edit commands do not
make sense either. Thus, boon switches to "special mode". In "special
mode", boon overrides just a few keys:
- x (C-x map)
- g (helm)
- G (revert-buffer)
You can get the original behaviour of x, g and G by prefixing them
with a quote (').
* COPYING
---------
This tutorial descends from a long line of Emacs tutorials
starting with the one written by Stuart Cracraft for the original Emacs.
This version of the tutorial is not a part of GNU Emacs, but derived
from the standard Emacs tutorial,
Copyright (C) 1985, 1996, 1998, 2001-2013 Free Software Foundation,
Inc.