Update some changed export keybindings
[worg.git] / org-tutorials / org4beginners.org
blob0e601943dcbcd53ea1794369313e5f6099d5eb7f
1 #+TITLE: Org mode beginning at the basics
2 #+AUTHOR: Alexander Poslavsky
3 #+EMAIL: alexander.poslavsky AT gmail DOT com
4 #+LANGUAGE:  en
5 #+OPTIONS:    H:2 num:nil toc:t \n:nil ::t |:t ^:nil -:t f:t *:t tex:t d:(HIDE) tags:not-in-toc
7 # This file is released by its authors and contributors under the GNU
8 # Free Documentation license v1.3 or later, code examples are released
9 # under the GNU General Public License v3 or later.
11 [[file:../index.org][{Back to Worg's index}]]
13 Org mode, as it says on the [[https://orgmode.org/ ][official web page]] is for keeping notes,
14 maintaining TODO lists, doing project planning, and authoring with a
15 fast and effective plain-text system. Beginning with Emacs 22.2 and
16 XEmacs 22.1 it has been part of Emacs. The following is a simple
17 tutorial to help you get started using Emacs and Org mode.
19 * The absolute minimum you need to know about Emacs
21 The absolute minimum you need to know about Emacs, to be able to do
22 /anything/, is more then you need to know about many other
23 applications. But, you might compare it to a regular toy and
24 lego. Lego is harder to begin with (you start with a box with little
25 plastic pieces), but in the long run, you can do more with it.
27 Emacs is heavy on shortcuts. starting out, that is rather annoying,
28 but in time you'll notice you start to use the mouse less and less,
29 and you actually start to work quicker.
31 All the basic things can be done, with the mouse, from the menu, open
32 file, save file , etc. You will notice, however, that in time it is
33 faster to use shortcuts, and leave your hands on the keyboard.
35 Emacs uses a lot of double shortcuts, so instead of Alt-F and Alt-S,
36 like most applications, it uses *Control-X Control-F* and *Control-X
37 Control-S*, this seems rather counter-productive in the beginning, but
38 you'll get used to it.
40 *Note:* Key abbreviations:
42 - *M* -- Alt (used to be called Meta on ancient keyboards, that's why)
43 - *C* -- Control
44 - *S* -- Shift
45 - *C-x f* -- means holding both Control /and/ x, release both, and press f
47 **  What version of Emacs should you choose?
49 If it is all the same to you, then choose Emacs over XEmacs (if you
50 disagree then you know already enough to skip this paragraph). Here
51 are some links to help:
53 - [[http://aquamacs.org/][Aquamacs: Emacs for Mac OS X]] (my favourite)
54 - [[http://homepage.mac.com/zenitani/emacs-e.html][Carbon Emacs for OSX]]
55 - [[http://emacsformacosx.com/][Regular Emacs for OS X]]
56 - [[http://ftp.gnu.org/gnu/emacs/windows/][Emacs for MS Windows]]
58 On GNU/Linux, just use your package manager to install Emacs.
60 On Debian:
62 #+BEGIN_SRC sh
63 sudo apt-get install emacs
64 #+END_SRC
66 ** Configuration
68 The biggest pain, when you just begin with Emacs, is the
69 configuration. There is not really a menu for it (you might later hear
70 there is, but they are lying, that menu is really there to trap
71 innocent people), you need to edit a text-file. The location of that
72 config-file (and even the name) is different on different OSes, but
73 the text in it is mostly the same, across platforms. Many people
74 actually use the same config-file on different OSes and even over many
75 years, so in the long run, it is for the best!
77 Location of the configuration file:
79 - Aquamacs: =~/Library/Preferences/Aquamacs Emacs/Preferences.el=
80 - Regular emacs on Linux or OS X: =~/.emacs=
81 - On Windows: =c:\emacs\.emacs.d\init.txt= ([[http://www.claremontmckenna.edu/math/alee/emacs/emacs.html][according to this example installation]])
83 * Starting Org mode
85 New shortcuts in this chapter:
87 - *C-x C-s* -- save document
88 - *C-x C-f* -- open document
89   
90 ** Our first Org document
92 By now, we know enough to start our first Org document. Start up
93 Emacs. If you have a completely new Emacs install, then you should see
94 the Emacs splash-screen. It has a couple of shortcuts, to the Emacs
95 tutorial and some other documents, but for now, we don't need those.
97 To start a new document, use the following short-cut: *C-x C-f*, which
98 will offer you to open a document (or buffer as it is called in
99 Emacs), call it *1.org*. This will give you a brand-new, empty document.
101 To save the document, either press the save icon, or press *C-x C-s*,
102 call it 1.org.
104 Emacs does not actually understand you are editing an Org document,
105 yet. To enable Org mode on your current document, type =M-x org-mode=
106 which will enable the Org mode on the current document.
108 To make Emacs understand that this is an Org document, add the
109 following to the *top* of your document:
111 #+BEGIN_SRC org
112 MY PROJECT -*- mode: org -*-
113 #+END_SRC
115 Those are minuses, /not/ underscores. MY PROJECT is the title of the
116 document, this can be anything.
118 This will enable Org mode for this document, no matter what the
119 file-ending is.
121 To enable Org mode to always work on all your Org files, you have to
122 edit your Emacs configuration, we do that in the following paragraph.
123    
124 ** Our first edit to our Emacs configuration
126 Open your Emacs configuration file (see [[Configuration]]), to open it in
127 Emacs, use *C-x C-f* (open file), and put the following in it:
129 #+begin_src emacs-lisp
130 ;; -*- mode: elisp -*-
132 ;; Disable the splash screen (to enable it agin, replace the t with 0)
133 (setq inhibit-splash-screen t)
135 ;; Enable transient mark mode
136 (transient-mark-mode 1)
138 ;;;;Org mode configuration
139 ;; Enable Org mode
140 (require 'org)
141 ;; Make Org mode work with files ending in .org
142 ;; (add-to-list 'auto-mode-alist '("\\.org$" . org-mode))
143 ;; The above is the default in recent emacsen
144 #+end_src
146 Restart Emacs.
148 *Note:* The mode-line, mentioned in the previous paragraph is only
149 needed if you (1) have files with a different file-ending then
150 configured in your Emacs config (for example myfile.txt).  (2) Don't
151 have the auto-mode-alist line in your configuration.
153 * Keep track of lists and notes
155 New shortcuts in this chapter:
157 - *TAB* / *S-TAB* -- (un)fold
158 - *M-up/down* -- move a headline up or down
159 - *M-left/right* -- promote or demote a headline
160 - *M-RET* -- insert a new headline
161 - *C-x C-s* -- save file
162 - *C-h t* -- Emacs tutorial
164 Now that we have configured Emacs to work with Org document, we can
165 actually start using it. Let's begin with an outline that will help us
166 get to know Org mode. Start a new document (*C-x b*), call it 2.org, and
167 copy and paste the following in it:
169 #+BEGIN_SRC org
170  #-*- mode: org -*-
171  #+STARTUP: showall
173  * Welcome to Org mode
175    Welcome, and thanks for trying out Org mode. Making outlines in
176    Org is very simple. It is just text! Just start typing.
177  * This is a headline, it starts with one or more stars
178    A heading has one star, a sub-heading two, etc.
179  * Working with lists
180  ** Moving around in our outline
181  ** Moving around headlines
182 #+END_SRC
184 Save the file (*C-x C-s*) as 2.org, and you will notice that the colors
185 change, syntax highlighting is turned on, and Emacs understands you
186 are working in Org mode.
188 Now we are ready to really start working with Org mode!
190 ** Working with lists
192 List are great for brainstorming and to keep track of things. Also it
193 helps keeping the big picture in mind when taking notes.
195 The first thing we will do is folding. Especially when you have a long
196 document, this is very useful. In our example document, go to the
197 first headline (just use the arrow keys), *Welcome to Org mode*, end
198 press *TAB*, and now press *S-TAB*. *Tab* will fold and unfold parts or,
199 using shift and tab, the whole document.
201 The basic idea of brainstorming is to write a list of items. Then,
202 later, you might want to change the order of your items, for example
203 in order of importance. To move a headline up or down, use *M-up/down*,
204 try it on any of the headlines. Notice that your list folds in,
205 showing only headings, to give a general overview of the document, and
206 you don't get lost in the details.
208 Next we will promote and demote headings. For example you might make
209 *This is a headline, it starts with one or more stars*, a sub-heading of
210 *Working with lists*, moving it down, and then using *M-right* to demote
213 Finally, to add a new headline, press *M-RET*.
215 Besides headlines there are still other kind of lists, ordered and
216 unordered lists. They look like this:
218 #+BEGIN_SRC org
219 ,** Lord of the Rings
220    My favorite scenes are (in this order)
221    1. The attack of the Rohirrim
222    2. Eowyn's fight with the witch king
223       + this was already my favorite scene in the book
224       + I really like Miranda Otto.
225    3. Peter Jackson being shot by Legolas
226        - on DVD only
227       He makes a really funny face when it happens.
228    But in the end, no individual scenes matter but the film as a whole.
229    Important actors in this film are:
230    - Elijah Wood :: He plays Frodo
231    - Sean Austin :: He plays Sam, Frodo's friend.  I still remember
232      him very well from his role as Mikey Walsh in The Goonies.
233 #+END_SRC
235 Unordered lists start with -,+,or \*. Ordered lists start with a
236 number and a dot. Descriptions use ::.
238 Further information: a short [[http://bzg.fr/org-playing-with-lists-screencast.html][screencast]] presenting a few features of
239 plain lists, also look at the [[https://orgmode.org/manual/Plain-lists.html#Plain-lists][manual]].
241 ** Working with notes
243 To keep notes, there is some markup to make things stand out a bit
244 more. You can use the following markup:
246 : You can make words *bold*, /italic/, _underlined_, =code= and ~verbatim~, and, if you must, +strike-through+.
248 It will look like this:
250 You can make words *bold*, /italic/, _underlined_, =code= and
251 ~verbatim~, and, if you must, +strike-through+.
253 If you like what you see so far, the it might be a good idea to do the
254 Emacs tutorial, that comes with Emacs itself (*C-h t*). The tutorial
255 will teach you some more Emacs shortcuts, used to move around in your
256 documents.
258 * Working with TODO items
260 New shortcuts in this chapter:
262 - *S-left/right* -- cycle workflow
263 - *C-c / t* -- show TODOs in current document
265 ** Basic TODO functionality
267 The biggest use-case of Org mode is using it to keep track of
268 TODOs. To start working with TODOs you don't have to do anything,
269 just add the TODO keyword in a headline:
271 #+BEGIN_SRC org
272 ,** TODO buy airplane
273 #+END_SRC
275 To speed up working with TODO-list there is the following shortcut
276 =S-left/right= which will cycle through: *TODO* - *DONE* and empty.
278 Imagine that you have a large document, with scattered all over the
279 document TODO entries, *C-c C-v* will show only your current TODOs, and
280 folding the rest away.
282 ** Configuring TODOs
284 *** In the file itself
285 Org mode files can be configured by adding workflow states to the
286 beginning of the file, like so:
288 #+BEGIN_SRC org
289 ,#+TODO: TODO IN-PROGRESS WAITING DONE
290 #+END_SRC
292 The line shoud be at the top of file, there should /not/ be any empty
293 lines between the top and the #+TODO line.
295 To activate the new workflow, either reopen the file, or go to the top
296 of the file (any line starting with #) and press *C-c C-c*.
298 Try copying the workflow to your test-file 1.org, seeing it helps
299 understanding what you can do with it.
301 *** In the Emacs-config file
303 Adding the workflow states to every org-file you create gets boring
304 soon, so it also possible to do this in your config file. Add the
305 following /after/ the (require 'org) line:
307 #+BEGIN_SRC lisp
308 (setq org-todo-keywords
309   '((sequence "TODO" "IN-PROGRESS" "WAITING" "DONE")))
310 #+END_SRC
312 To activate the workflow states, restart Emacs.
314 * Agendas
316 New shortcuts in this chapter:
318 - *C-c a* -- agenda
319 - *C-c [* -- add document to the list of agenda files
320 - *C-c ]* -- remove document from the list of agenda files
321 - *C-c .* -- add date
322 - *C-u C-c .* -- add time and date
323 - *C-g* -- stop doing what you are trying to do, escape
325 The basic meaning of the word agenda is /things to be done/, coming from
326 the latin /agendum/. Org mode is very good in making different kind of
327 agendas, or task-lists, collecting all the tasks from one or more
328 org-documents.
330 ** Creating lists of all active TODOs
332 We will start with using 1.org as our basic agenda-file, later we will
333 see how this works in the Emacs-config file.
335 So, again, visit =1.org=. Next press *C-c a*, which calls the
336 agenda. It looks like this:
338 #+BEGIN_EXAMPLE
339 Press key for an agenda command
340 -------------------------------
341 a Agenda for the current week or day
342 t List of all TODO entries
343 #+END_EXAMPLE
345 and then some more.
347 Unfortunately, both will show just empty lists (you can try if you
348 want). So just press *C-g* (the Emacs version of escape). Next we will
349 add 1.org as agenda file, using *C-c [*. Now if you go to the agenda
350 menu (*C-c a*), and press *t* you get a list off all your TODO items.
352 You will also notice that, if you have added a more comprehensive
353 workflow, as explained in [[Working with TODO items]], all items are
354 listed, except DONE.
356 This can be repeated for as many documents as you want, and agenda
357 will give you a complete list of TODOs. If you want to remove a
358 documents from the list of agenda files, press *C-c ]*.
360 ** Appointments and deadlines
362 When a task is time related, then we usually put it in our
363 calendar. This can also be done in Org mode. And agenda can then show
364 us a time-based list of all our TODOs. This is done in the following
365 way.
367 In =1.org=, add a new (sub-)heading called: /Call fred/ (*M-RET* Call fred),
368 but at the end press *C-c .*. This will give you, at the bottom of the
369 screen, the date chooser. You can either type something by hand, or
370 use *S-left/right* to change the date. If you want to add a time as
371 well, use *C-u C-c .* instead of *C-c .*.
373 Now, if you go to the agenda (*C-c a*) and press *a*, you get an agenda
374 entry!
376 Further reading:
378 - [[http://doc.norang.ca/org-mode.html#Clocking][Bernt Hansens extensive description Time Clocking: Usage, Customization,
379  Workflow description]]
380 - [[http://sachachua.com/wp/2007/12/30/clocking-time-with-emacs-org/][Clocking time with Emacs Org]]
381 - And of course [[https://orgmode.org/manual/#toc-Dates-and-times-1][the manual]]
383 ** Configuring the agenda in the Emacs configuration file
385 If you open up your emacs configuration file, after you have used
386 *C-c [*, you will see the following:
388 #+BEGIN_SRC emacs-lisp -n -r
389 (custom-set-variables
390   ;; custom-set-variables was added by Custom.
391   ;; If you edit it by hand, you could mess it up, so be careful.
392   ;; Your init file should contain only one such instance.
393   ;; If there is more than one, they won't work right.
394  '(org-agenda-files (quote ("~/Documents/Projects/org4beginners/2.org"
395  "~/Documents/Projects/org4beginners/1.org"))))
396 (custom-set-faces
397   ;; custom-set-faces was added by Custom.
398   ;; If you edit it by hand, you could mess it up, so be careful.
399   ;; Your init file should contain only one such instance.
400   ;; If there is more than one, they won't work right.
402 #+END_SRC
404 Welcome to the world of Emacs lisp. This is what it looks like if
405 Emacs changes your config file. (*Note:* on Aquamacs, this is in a
406 separate file called customizations.el)
408 For us, the important part is in the middle (lines 5 and 6), the line
409 with /org-agenda-files/. There we see the list of files agenda uses to
410 create its lists. For now we can just leave it there, but at least you
411 know what it is, when you later look at your config-file.
412    
413 Further reading: [[https://orgmode.org/worg/org-tutorials/org-custom-agenda-commands.html][Custom agenda commands]]
415 * GTD
417 New shortcuts in this chapter:
419 - *C-c C-c* -- add tag
421 /Getting things done/, is one of the most popular ways to organize
422 oneself, with 4.3 miljon hits on Google. It is quite possible to use
423 the same kind of setup in org mode, using tags.
425 Tags are used to organize different kind of TODO-entries, for
426 example all tasks on the phone, reading, shopping, etc.
428 To add tags, add the following to the top your document:
430 #+BEGIN_SRC org
431 ,#+TAGS: { @OFFICE(o) @HOME(h) } COMPUTER(c) PHONE(p) READING(r)
432 #+END_SRC
434 Reload the document, or press *C-c C-c* on a line starting with #.
436 Now it is possible to add one or more tags, to any line in your
437 document. If we press *C-c C-c*, the following will pop up:
439 #+BEGIN_EXAMPLE
440 Inherited:
441 Current:
442 { [o] @OFFICE     [h] @HOME    }
443   [C] COMPUTER   [p] PHONE   [r] READING
444 #+END_EXAMPLE
446 These are the shortcuts we defined at the beginning of our
447 document. The first two tags (OFFICE and HOME) are mutually exclusive,
448 the rest can just be added.
450 A very good example of a GTD setup is: [[http://members.optusnet.com.au/~charles57/GTD/gtd_workflow.html][How I use Emacs and Org mode to
451 implement GTD]]
453 ** Adding tags to the Emacs config-file
455 To add tags to the Emacs config-file, so it is available to all your
456 documents, add the following.
458 #+BEGIN_SRC emacs-lisp
459 (setq org-tag-alist '(("@work" . ?w) ("@home" . ?h) ("laptop" . ?l)))
460 #+END_SRC
462 To set mutually exclusive groups, like the previous example, see [[https://orgmode.org/org.html#Setting-tags][here]]
463 in the manual.
465 It is always possible to override your settings by adding something
466 else to the top of the document. This way every document can have its
467 own workflow and/or tags.
469 An extensive example of working with tags can be found [[http://sachachua.com/wp/2008/01/04/tagging-in-org-plus-bonus-code-for-timeclocks-and-tags/][here]] as well.
471 * Export
473 New shortcuts in this chapter:
475 - *C-c C-e* -- export menu
477 Working with Org documents is usually fine, but sometimes you might
478 want to export your documents to another format.
480 To export the current document to, for example, html, press *C-c C-e*,
481 and then *b*. This will export the document and open the new document in
482 your browser.
484 Further reading: [[https://orgmode.org/worg/org-tutorials/org-publish-html-tutorial.html][HTML publishing tutorial]] (which goes further then
485 just a document, you can use it to publish a complete website). And
486 [[https://orgmode.org/manual/Exporting.html#Exporting][the manual]] which explains exporting to HTML, LaTeX, PDF and others.
488 * Becoming proficient with Org mode
490 To really save time with any efficiency tool, you have to know it
491 well. To get to know Org mode, reading and using the manual is
492 important.  Org mode is well documented. The fastest way to read the
493 ORG mode documentation right in Emacs, in the so-called info-browser.
495 To call the info browser, use *C-h i*, and use *TAB* to jump from
496 hyperlink, to hyperlink.
498 To move around in the info-browser use:
500 - u -- up
501 - n -- next
502 - p -- previous
504 Besides the Org mode manual, the is the [[https://orgmode.org/worg/][worg website]], which has
505 many cool ideas and [[https://orgmode.org/worg/org-tutorials/index.html][tutorials]].
507 For quick reminders there are the [[https://orgmode.org/index.html#sec-4.2][Org mode cheat-sheet]] and the
508 emacs cheat-sheet, both will help you to remember those pesky
509 short-cuts.
511 * Beyond the basics
513 As is often said in geek humor: "here be dragons!" From here on you
514 are going into the die-hard section of using Org mode. Most of the
515 following material is not really hard, but make sure to have backups
516 of your important data. If you have questions about the following,
517 look it up in the manual and the faq. Also irc (#orgmode on freenode)
518 is a good place to ask questions.
520 ** TODO Quickly adding tasks with Capture
521 ** Running the latest version of Org mode
523 New commands in this section:
525 - *M-x org-reload* -- reload Org mode after an update
526 - *M-x org-version* -- show Org mode version
528 Pretty soon you will notice that the development of Org mode goes a
529 lot faster the speed Emacs get's updated with. It is quite possible to
530 run the development version of Org mode daily.
532 How do you go about that?
534 1. Install git
535    Not really part of an Org mode tutorial, but here are some
536    places to start:
537    - [[http://code.google.com/p/git-osx-installer/][Git OS X installer]]
538    - [[http://code.google.com/p/msysgit/][Myssysgit]] git on Windows
539    - On Linux, use your package manager:
541    #+BEGIN_SRC sh
542    sudo apt-get install git
543    #+END_SRC
545 2. Decide where you will keep the Org mode code, I use
546    *~/Build/Emacs/org-mode*, but for Emacs it is really all the
547    same, just choose something convenient, and stick with it.
549 3. Download the latest version of Org mode:
551    #+BEGIN_SRC sh
552     mkdir ~/Build/Emacs
553     cd ~/Build/Emacs
554     git clone https://code.orgmode.org/bzg/org-mode.git
555     cd org-mode && make && make doc
556    #+END_SRC
558 4. Add to your Emacs-init file:
560    #+BEGIN_SRC emacs-lisp
561    (setq load-path (cons "~/Build/Emacs/org-mode/lisp" load-path))
562    (setq load-path (cons "~/Build/Emacs/org-mode/contrib/lisp" load-path))
563    #+END_SRC
565 *Important!* If you run the regular version of Org mode, you have
566 =(require 'org)= in your config-file.
568 5. To keep up-to-date with Org mode in the future do:
569    
570    #+BEGIN_SRC sh
571     cd ~/Build/Emacs/org-mode
572     git pull && make clean && make && make doc
573    #+END_SRC
575 6. Reload Org mode, using: *M-x org-reload*, or restart Emacs.
577 To see what version of Org mode you are running: *M-x org-version*