Learning to use vim in my iPad (even if I'm an emacs geek)

Flattr this

Just in case you don't know, vi is an advanced text editor, drting back from the same era as emacs was developed (emacs started slightly earlier). Sort of the Jekyll to emacs' Dr Hyde. Emacs users despise vi users, and vi users mock emacs users. This is what the editor wars are all about: "Eight Megabytes And Constantly Swapping" versus "vi has two modes: writing and beeping". If you have been long enough in this blog, you know I'm in the emacs side, but you also know I'm curious enough to delve into the other side.


My first contact with vi was in our first programming class at the University, Informatica (Computer Science). Vi was the editor of choice for the course, so much that you did not have any other option given. Along with a Linux cheatsheet and a short C manual came a vi cheatsheet. A lot of people came to hate vi, a lot of people came to love it. I was more in the hating side, but it wasn't that bad. After a while I just started using a "normal" Linux editor (it was Kate, maybe?) and kept using it (or UltraEdit when I was in Windows) until the end of my degree.

When I finished my degree I had to be a teacher of Calcul Numeric (Numerical Analysis), the third (and last) programming class in the degree. At home I was still using Windows, because the wifi card in my notebook had no Linux drivers and in my office we were using Ubuntu. I needed a cross-platform editor that was quick, versatile and could last for a lifetime. I tried vi (again) and emacs, emacs won the war for two reasons. First was the fact that it was extensible programming in Lisp, and I had already a decent knowledge of Lisp. The second was AucTeX and its "preview" option for LaTeX editing. Nothing can beat pressing C-p C-p C-d and seeing your formulae come to life in your editor. I became an emacs advocate for this reason, then after 5 or 6 years I've found many more reasons why this is the editor. Or, the operating system, if you prefer.

But advocacy is nice, but knowing all the players in the field is better. My department pals used vi (at least most of them), and it was impossible to convince them to switch. I decided learning vi (or vim, vi iMproved) was something I had to do some day, to learn what was there. After all, if I liked it so much I could set viper-mode in emacs and use vi keys in emacs. The best of two worlds, if that world is so nice.

Then the guys at Applidium released a Vim port for iOS devices. Whoah! Even if I'm an emacs guy to the bone, a modal editor is way better than anything else available in the app store, at least for raw editing power. And I say with knowledge, because I've tried most writing apps for iOS devices (see this post).

As an additional reason, Matt Might posted a New Year's post detailing several resolutions for programmers. Among them was breaking your comfort zone to keep your mind sharp. The first example? Switching to vi from emacs or vice-versa. He used to be an emacs user before getting to use Vi. I don't think I could go that far, but these were enough reasons: advocacy (from me, not against me), iPad+bluetooth keyboard and breaking my comfort zone.

How is the experience so far?

Well, I'm writing this post in my sofa, with my iPad and my bluetooth keyboard sitting in my lap. I'm still getting used to having to exit editing mode to move around: I'm very used to pressing C-a or C-e to go to the beginning of end of line. An additional problem is that even with the bluetooth keyboard, Esc can't be mapped to the Esc event, and I needed something to do it. I have jk (pressed together) for it. It was a suggestiond I saw in Hacker News' comment thread for the release of the app, and it's quite handy. Not so much with the on-screen keyboard, but for now it's okay. To remap this, press backslash (the current mapping for Esc) and then :imap jk . Of course if your usual writting language involves writing the jk combination frequently (I think I could come up with one or two examples in Icelandic), this is not the best combination. The other suggested option is :imap al . Easy to tap in a virtual keyboard, not so straightforward in a normal keyboard.

I found out also how to change the font size, at least for now this works (maybe there will be more fonts available in the future), type :set guifont=Courier:h24 (for 24 pixels)

To round everything, I just installed the famous solarized color theme, dark in vim for iPad. Until now I had just thought it was an overhyped color scheme: I had tried in my emacs and didn't enjoy it that much. But in my iPad it shines with a distinct colour, it's so much easier on my eyes that it hurts to get out and write an email! To install it in your vim for iOS, first download solarized.vim from the git repository, then plug your iDevice and use iTunes File Sharing to copy this file to the vim app. Then open vim, :e solarized.vim and :call mkdir(.vim/colors/) (to create the directory needed for it) :w .vim/colors/solarized.vim This is just because I didn't seem to get iTunes File Sharing to work with hidden files (a file starting with a dot is hidden). Then you have to add the following to your .vimrc:
syntax enable
set background=dark
colorscheme solarized
I recommend using this app for any emacs lover out there with an iPad. Of course, it is not emacs, but vim is a pretty awesome text editor, and it's always handy to learn to use it.

To have a useful list of vim commands at hand I installed the Vimmy app, a universal app with the most common vi commands. I can switch to it via the multitasking gestures in my iPad, or use it in my iPod Touch while I'm using it in the iPad.

Conclusion

I don't think I'll ever switch from emacs to vim any time in the future, as I said AucTeX is definitely too good. Of course since then I've found many more things I love: having a REPL for Python, Clojure or Lisp inside my editor. There's even a REPL for PostScript! Also local remote editing with tramp... There are too many things I use on a daily basis and I can't barely remember, they are so entrenched in my .emacs file I can't even realise what they are. But for my iPad it is an awesome addition to write text on the go.

Again, if you have never used vim before and are interested, give it a try. Of course the first time you open it it will be... a jump into the unknown. Tap the screen, press :e filename and start editing happily. Esc (well, jk or backslash, as the initial mapping) :w to save. And you can even :q to exit to springboard!





Good Books I've Read in 2011: Perfect Gifts for Geeks!

Flattr this

Taken from Flickr
The links to books in this post are affiliate links! Beware :)
In case you have not realised it yet, I'm a pretty prolific reader. Online reading (and having an iPad) have slowed down the number of books I read in a given year, and I don't go to the lengths of my girlfriend (who is about to reach her goal of reading 102 books in this year,) I'm nevertheless a frequent reader.

This year I've read several good books that I'd like to share with you, after all, if you are reading this probably our tastes overlap. And then these books will be perfect for you (or for some geek in your life). The books I've selected range from programming, sports and non-fiction. Oddly enough, I don't remember any fiction book I've read this year (not counting some book by Raymond Chandler, which I can recommend each year). Let's go!

Born to Run A Hidden Tribe, Superathletes, and the Greatest Race the World Has Never Seen: I reviewed this book in a previous post here. I found it very good, and urged me to get running. My running frequency is (to put it softly) awful, but I'm trying to improve. If you want to start running or recover some lost motivation, give it a shot, it's a very good read. You can read my review of Born to Run.

Visualize this The FlowingData Guide to Design, Visualization, and Statistics I wanted a book to help me graphing things in my future work as a freelancer, and after looking around a little I found this *great* book by Nathan Yau, the blogger behind Flowing Data. It's an awesome book, which will help you start kicking around the graphs and tables.

Confessions of an advertising man: An almost autobiographical book by famed ad-man David Ogilvy, if you are anything into copywriting, advertising or marketing, you have to read this book. Not only will it help sharpen your ideas, but it is also a very good and entertaining read.

Moonwalking with Einstein The Art and Science of Remembering Everything: A New York Times best-seller by Joshua Foer. After reading his interview-article there, I decided to buy it (pre-ordered it!), and it was very worth the money. An entertaining read of how motivation can get you a long way, and how some memory techniques work. I have not written a review of it, but you can read my own explanation of the memory palace technique.

Even a geek can speak Low-Tech Presentation Skills for High-Tech People: The best book for anyone in need to give a presentation. Clear, concise and to the point, this should be a forced reading for all technically minded people. You can read my review of Even a geek can speak.

Mining the social web Analyzing Data from Facebook, Twitter, LinkedIn, and Other Social Media Sites: If I had to try the book I enjoyed the most reading this year, it is this book. Seriously. Even awesome comes short of what I think about this book. I plan on reviewing it, but I've got not enough time yet... With it you'll learn how to mine twitter, Facebook, LinkedIn and whatnot. And then process all this data. Easily. Yes!

The AdWeek copywriting handbook The Ultimate Guide to Writing Powerful Advertising and Marketing Copy from One of America's Top Copywriters: Your deep entry into copywriting, from a master copywriter. You'll learn how to shape your online copy, from headline to action. It's very well written in an understandable fashion. Keep in mind that if you buy the Kindle edition, the provided checklists are not that useful.

Thinking Forth: I've had this book for a long, long time and I finally got to read it. I used a simple method for getting me to read it: I left it in the bathroom. When I had to spend some time there (for example, shaving with an electric machine!) I read a few pages. And in no time, I had finished. You don't need to have a computer close to read it, but a little knowledge of Forth is quite useful. It is a clean book, introducing some concepts like orthogonality and testing without even trying.

Power Sleep The Revolutionary Program That Prepares Your Mind for Peak Performance: A best-seller book focused on mental abilities and how sleep affects it. Packed with research results and advice, it was a very interesting book, although a little too long. After all, the best suggestion is to go to sleep each day at the same time and keep adding 15 minutes (weekly) to your sleep until you stop feeling sleepy. Now that you have the spoiler, buy it.

Crush It! Why NOW Is the Time to Cash In on Your Passion: One of these self-help books that will get you pumping ideas and rocking you off the sofa. According to Gary, now it is time to crush it. And probably it is. If you are a little low on motivation, read this book. Don't expect it to teach you how to do things, just read it as experiences to think about.

What I talk about when I talk about running: Another running book, this time an autobiographical piece by one of my favourite writers, Haruki Murakami. I was expecting a little better from him... But of course, not every book can be Hard-boiled wonderland and the end of the world. An interesting read about Murakami's running experiences, and how he got to run a 50 miler and the "original" marathon in Greece (under a scorching sun).


This month I've started several books that I'm sure would have make this list, and will probably be delayed until next year:

Steve Jobs: I will remember how and when I found out Steve died, and will still be inspired by his commencement speech for a long while. I've gone through almost one fifth of the book (a very thick one,) and it is one of the best biographies I've read (the other is John Nash's). Brilliantly written, it reads like a novel with a fast pace.

1Q84: the recent best-seller by Murakami was the gift from my girlfriend for this year's St. George day, and I've only been able to read a few pages. From the raving reviews, I assume I'll like it (I was deceived by Kafka in the shore).

The memory palace of Matteo Ricci: A classic book for memory techniques lovers, I've only got to read the first 20 pages or so. So far, very interesting and well edited.

Guns, Germs and Steel The fates of human societies: A book recommended by my thesis advisor, dealing with why Europe invaded America and why it was not the other way around. Of course, all is theoretical, but it is amazing nevertheless.

If you find some broken link, please let me know!

Working on the go with an iPad, a Bluetooth keyboard and a 6sync account

Flattr this
All hail Steve Jobs
Some of the links in this post are affiliate links. As usual, I only recommend what I've used and like

Inspired by a post by Mark O'Connor from Yield Thought (my frequent readers will have already read something from him from my link collections), I have been working remotely for a week. His set-up is an iPad 2, Apple wireless keyboard, the iSSH app and an account in Linode. My setup is similar, but I use an iPad 1 and 6sync for the VPS.

Why 6sync?

A matter of luck. Around 2 weeks ago, I set up my "name domain" at rberenguel.com (currently down, I messed the Apache configuration a few days ago), and I decided I had played with blogger for long enough. Decided to look up an VPS to host that site and whatever I needed to either host or cloud process in the future. Tweeted asking for options, and in the meantime, Sacha Chua explained how she switched to Linode. Linode was going to win...

Until the guys at 6sync (Mario and Rav) sent me a tweet, urging me to check 6sync before choosing. I checked the page, the prices, and was close to sold out. Exchanged a few tweets, read a few reviews, and I was convinced. Reasons? Many.

First, they offer a more basic and cheaper service. Whereas Linode offers 512 MB of RAM, 20GB storage and 200GB transfer for 19.95$/month as the basic plan, 6sync offers a nano plan with 256MB of RAM, 12GB storage and 150GB transfer for 15$. This plan is currently ideal, since my bandwith and RAM usage for the server side is close to nil, and I don't expect to use that much of bandwith in daily doses. They also offer a Mini plan with 2 CPUs, 512 MB or RAM, 20GB storage and 400GB transfer for just 20$/month, beating the Linode offer on its own ground.

Second, they have a very nice website. As a hobbyist page creator, this is important. I like how they have set-up their site, and the pictures they choose to go by. If they are not the designers, the designers should receive this praise.

Third, they are a funny bunch. I exchanged several tweets with them, and they were very supportive. And as soon as I had my server up and running and ran into problems (or more precisely as it turned out, I was not patient enough for the DNS switch) they were extremely quick to help through their in-page customer chat service.

Fourth, they have a lot of server setups ready. Do you want Debian? Check. Ubuntu? Check. Arch...? Yes! I can use me dear pacman package manager and install whatever I want, in the latest version. Cool.

All in all, very happy for hosting. And then, Mark published his post.

The remote and local setups

At first, instead of filling my 6sync server full of software, I tried a simpler setup: using my office computer in the department. I still have an account for using that computer, and I have already everything setup for working remotely. I only needed a decent ssh client for iPad.

Back in the iPod Touch days, I used the awesome (truly awesome) TouchTerm app, which is (was) perfect for the iPod Touch. Offering a wide array of gestures to control it, it is a marvel of usability. But it has no iPad version. For the occasional SSH session I was using the free zatelnet app. But this also was not a good deal.

When Mark published his post, I decided to buy iSSH, and even if the price tag is high for an app, I don't regret it. The freedom you get when only carrying an iPad and a very slim bluetooth keyboard is unmatched. The app is universal, so you have two apps for the price of one. Check the server stats from your iPhone!

Mark is a vim guy... I guess that's okay for a lot of people, but not for me. I could go the vim way (I have been trying to get a basic proficiency of vim in the past), but I'm an emacs guy. Up to the last moment. And I had to cross fingers for iSSH and emacs to play along nicely...

Well, they mostly do (at least with iOS5). The control key works, and so does the option key (as meta). The real meta key (command) does not work as expected, but esc also works as meta, in case of need. The only problem I've found so far is the fact that control-f and control-b are hard-bound (in the iOS level) to advance/go back a word. Thus control-x control-f does NOT open a document. But if you press shift, emacs does not care about control-X control-F, and the iOS bound setting is overriden.

There's a more important problem with these iOS level shortcuts, control-a goes to the beginning of the line... but leaves a nasty [] in the buffer. I have written an abbrev-expansion and re-bound control-a to get rid of it, but it does not work as well as I want yet. Luckily emacs is flexible enough to allow me to solve this in more than one way. Currently almost done anyway.

Installing all the stuff is a breeze. Of course, I had already installed the LAMP setup, although I only have configured Apache so far, but adding the rest of things I use on a daily basis is straightforward:
pacman -S emacs-nox texlive-core
And now... Dropbox or not dropbox? Dropbox from the command line has a slight problem: you need a browser to accept the linking between your new computer and the remote system. And I didn't want to add the complexity of X to the game (even if iSSH has a very cool X server...). So I left dropbox out of the equation. I can always push/pull the files every once and then without problems.

So, I have everything that I need. Now, how does it work in practice?

The daily grind

As you may already know, my daily grind is split between my part-time freelance job as social media manager (among many other things covering get more pageviews and make more money from the sites, mixed with data analysis and copywriting) and finishing my thesis.

Working in my iPad for the freelancing job was already possible. I could access almost all systems from just a browser. Reading and answering mails, the same, although going from the email app to the CRM is slow. So far, the only problems I've found are spreadsheets (solved since I got Numbers) and e-Junkie. e-Junkie has the nice feature of having a flash-based login box. Clever, isn't it? Well, I'll leave the e-Junkie management for my MacBook moments.

For the thesis part, it was harder. There is an awesome LaTeX editor for iPad, TeX Touch. I can't really stress how good it is. Using it with the on-screen keyboard is as close as you can get to be proficient. The drawback is that once you're used to emacs, if you have a solid keyboard, nothing can beat emacs except telepathy.

This is where the iSSH stuff enters into play. Fire emacs, edit all your TeX in console mode (I can somehow live without AucTeX's preview, although it is slightly hard), compile the pdf and move it to the shared folder (all done via an automated script within AucTeX for compiling). Switch to Safari (or GoodReader) and open the document. Check everything is in place and keep going.

The standard TeX based lather-rinse-repeat is straightforward from within an iPad.

Anyway, I'm not using only the iPad day to day. Only those days when I know I don't have that much work to do, requiring heavy task-switching or firing tons and tons of emails with attachments. For slow (or semi-slow) days, it is awesome.

What benefits are in this?

Well, I'm free of carrying a heavy MacBook. Until I get a nice MacBook Air, my current computer is a slightly too heavy MacBook from 2008. It weights quite a lot, and I need to add the charger (even if it is very light, it weights). When I carry the MacBook, I also carry the protecting case (more weight) and a backpack (weight) with some folders with the stuff I'm correcting for the thesis (I could remove this). And I also carry my iPad.

These days I get by with my purse-bag, which is perfectly sized for the iPad+keyboard. I carry the pages I need to check for the thesis, and no more. So I've gone from 5-odd (or 6-odd) kilograms to slightly more than 1.

I also don't need to worry about plugs or battery, the iPad battery lasts for a days' worth of working.

Again and Again: Playing Go

Flattr this
I’ve been playing the game of Go (also known as weiqi or baduk) on and off for almost 10 years. In case you don’t know, Go is a board game with very old roots, that can be traced back to at least 2500 years ago, probably a lot more. Very popular in Japan (known as Go or Igo), Korea (baduk) and China (weiqi), it has been slowly spreading among the west during the last century. It is featured in the movies Pi and A beautiful mind, for example.

For some odd reason, every autumn I decide I want to play again, and I pick up playing only for it to wane after a while. As every year, I hope this is the last and I keep on playing. What has this game that is so appealing?

Go is a beautiful game. If you are anything into programming, it's like the Lisp of board games. Lisp (at the core McCarthy sketched) is so simple that it is almost like it was discovered more than developed or invented. Likewise, Go is probably one of the simplest games you can define, yet it hides a deepness that is astonishing.

I used to be a chess player back in my early teen years and there was something that always bothered me: why are chess rules so arbitrary? Why does the knight jump in an L shape and no other piece jumps? Why is the rook placed on the sides? I was unsatisfied with these arbitrary rules. In addition to this, even as a very, very early amateur, you could get nowhere without either killer move reading (anticipating moves is usually called reading in the board game lingo) or a quite decent knowledge of some openings. In my days, I settled for the Indian openings, by the way (which then could be stretched into the Catalan opening, which I also used very often).

After giving up chess due to lack of time and drive, I discovered Go, a game where the rules are kind of natural. Although there are some kind of openings close to the sense of chess (known as joseki, which means fixed pattern), they are not fundamental until you are quite a decent amateur, and even yet, are not essential.

For a long time I was member (also was vice-president, accountant and maybe even president for some days) of the club in my maths faculty, where we taught many peope the game. Lack of time and a persistent avoidance of playing, moved me away from the game. Why was I avoiding playing? Fear of competition, fear of losing, fear of making stupid moves and looking stupid. These are feelings I still have, even 10 years later. Slightly less: failing and doing stupid things cures you from this.

This autumn, just a few days after I had joined the baduk subreddit, one of the admins there started a tournament, and I found it perfect to get me playing. So I registered, removing two ranks from what I remembered was my rank. In Go, ranks start at 30 kyu, and progress towards 1 kyu, afterwards you get 1 dan and progress towards 9 dan (there is nothing beyond 9 dan). The rank I remembered (in the online server KGS) was 12k, a rank I held for a long time, and accordingly set my new rank as 14k.

What I did not remember was the fact that KGS had undergone a rank shift. I don't remember the details, but it had something to do with moving the peak of the normal distribution of ranks. After this rank shift (and probably a little improvement while I didn't play) I got to be 6k for a while, maybe even more for short while due to rank drift. What rank drift? When you play a game against a player and win, if the player improves your rank improves accordingly (the effect fades after a certain time, but carries some weight). Since I was playing very little, I was subject to very strong drift effects.

And this is the story of how I have started playing again, and what is this thing called Go. Maybe I'll write more about the game, maybe not. If you are a subscriber you already know how my interests shift from time to time... But I always come back to the basics!