Sunday, February 1, 2015

Using rlwrap with sam editor

Recently, I've started using the sam editor. I've been using vim for the past 15 years, but recently tried Acme. Acme rocks, but I after a few weeks I missed using keyboard navigation, search and replace, etc. So I "fell back" to sam.

I really like the heavy use of regular expressions in sam, in particular the addressing. For example, here's how to print the full function you are in to the screen: -/^func/;/^}/-+.

I've noticed that since I started using sam, I think more of the names used in my code than the visual display of the code. This happens because you start to operate tell sam to do thing like move the function SendCommand to the end of the file, or 0/^func SendCommand/;/^}/-+ m $

One thing I found annoying is not having a command history for commands like that. I started keeping a text file off to the side where I could copy common commands from and then paste into sam (ala Acme), but I remembered rlwrap so I tried that.

It works, with the exception of the tab key. So instead of typing line indents, I just type the new code and use gofmt (,x|gofmt) or with rlwrap, the following keystroke sequence:

esc-key
/
gof
enter-key
enter-key
which, except for the gof, is in my finger muscle memory.

I am going to try it full-time now; here's how I set it up:

  1. If you prefer vi keybindings for history (as I do), put these lines in your $HOME/.inputrc:
    set editing-mode vi
    set keymap vi
    
  2. Add an alias to $HOME/.zshrc (or .bashrc, or whatever)
    alias sam="rlwrap sam -d"