Hooked on org-mode

January 10, 2012 at 08:46 PM | categories: emacs, vim | View Comments

So, what's a long-time ViM user doing with an Emacs session running all the time? Using org-mode of course.

First a little bit of a problem statement: I forget everything. I've tried lots of different ways to solve the problem. I started with writing a TODO list at the beginning of each day. For a while I succeeded in using a Palm Pilot to keep track of everything. Next was a Google Calendar. For stuff that didn't fit in the calendar I tried to keep a personal wiki. Each method ended up in failure because it was cumbersome. Let me be clear, to me cumbersome means requires more work than typing on a keyboard.

I was pretty excited when I heard about org-mode. Look at the slogan: Your Life in Plain Text. How could that not be good? Not being a Saint in the Church of Emacs it took me a little longer to get comfortable with org-mode, but it was worth it. I'm sure my org-mode use hardly scratches the surface of what's possible, but it's been enough to keep me organized for the past year.

Here's what it took to get started. I created a directory called ~/notes and added the following to my Emacs startup files:

(add-to-list 'auto-mode-alist '("\\.org$" . org-mode))

(global-set-key "\C-cl" 'org-store-link)
(global-set-key "\C-ca" 'org-agenda)
(global-set-key "\C-cb" 'org-iswitchb)

(setq org-log-done t)
(setq org-log-repeat "time")

(add-hook 'org-mode-hook 'turn-on-auto-fill)

(setq org-directory "~/notes")
(setq org-agenda-files (file-expand-wildcards "~/notes/*.org"))

Whenever I want to record something I open up a relevant .org file in ~/notes and add entries like this:

* Chores
** Empty garbages
** Mow lawn

It's just an outline, with the number of leading * characters determining the level of each entry.

The only keys I really use frequently are:

  • C-c C-t: transition states (make this a TODO or mark it done)
  • C-c C-s: schedule this entry
  • C-c C-d: set a deadline for this entry
  • Tab: fold (show/hide children of this entry)
  • C-c a a: show the agenda for the current week

org-mode is far more customizable, but for me, that's enough. I'm especially pleased at how easy it is just to start logging things that happen in a meeting or adding something that I just remembered needing to do around the house. There's almost no friction. And everything about the entry lives in the text file. Then, with a few key presses (C-c a a) I know what my next week looks like.

Saving ViM Macros

March 11, 2009 at 09:32 AM | categories: tips, vim | View Comments

I use ViM macros (aka complex-repeat) all the time. Occasionally, I find that it would be nice to reuse one of my macros across editing sessions. Turns out it's pretty easy to save the macro. Just add a line like the following to a file that gets sourced when your file is opened by ViM (This example is from ~/.vim/ftplugin/rst.vim).

let @h = "yypVr"

Now, whenever I open a ReStructured Text file, I can hit @h and my macro will run.

More Useful ViM Tags

March 04, 2009 at 08:35 PM | categories: tips, vim | View Comments

Frequently, I find myself writing C code that requires the use of struct ifreq. There are plenty of fields there and of course there are other structures that I never remember. I could always look in the headers, but it ends up being a good amount of digging before I find the real definition and all its accompanying pieces. So, I decided to let ctags and ViM do the work for me. I created ~/bin/update_local_tags with the following contents:

[ -d ~/.localtags ] || mkdir ~/.localtags
ctags -f ~/.localtags/usrinclude.ctags --exclude=vector\*.hpp -R /usr/include >/dev/null 2>&1

Then I created ~/.vim/ftplugin/c.vim with the following contents:

setlocal tags+=$HOME/.localtags/usrinclude.ctags

For good measure I copied c.vim to cpp.vim so it would be loaded for C++ file types also.

Now I just have to run update_local_tags to generate a tag file for everything in /usr/include and ViM automatically includes that list whenever I edit a C or C++ file. Updating the tags file is still a manual process, I should probably attempt to hook it into apt. Observant readers will have noticed that I exclude vector*.hpp when generating the tags. Boost includes a few generated header files that match this pattern and swell the tag file to almost 750 MiB.

Editing ViM Macros

March 17, 2007 at 03:16 PM | categories: tips, vim | View Comments

At the BYU UUG meeting this week, Peter mentioned a great ViM trick that I've never seen before. Here's my feeble attempt to document it.

Because ViM macros are stored in registers they can be edited. This means that if you create a long macro and then realize that you forgot to send the cursor to the beginning of the line before finishing the recording, you don't have to create the entire macro again, you can just add the motion command. You use it like this:

  1. Start recording your macro by typing q and then the single character ([0-9a-zA-Z"] are allowed). The single character is the register your macro will be stored in.
  2. Enter the commands you want included in the macro.
  3. Type q to finish recording the macro.
  4. At this point you could run the macro by using @ and the register name.
  5. To modify the macro, move to a blank line and type "Rp replacing R with the register name of your macro. This will paste all the commands in your macro to the current line.
  6. After making the changes you need, save the macro by typing 0"Ry$ replacing R with the register name you want to use for the macro. The register name does not have to be the same as the original.