Coding From An iPad
As I had mentioned in my post on my current state of Vim, one of the benefits of using Vim is that it’s pretty much everywhere — at least in the non-Windows world:
My laptop running Fedora has it, and the VPS I run also has it if I want to write some code from my iPad — which is a post in itself for another time.
This was especially pertinent for me as I’m trying to see how far I can push the usefulness of my iPad. It’s something that I always reach for when it comes to things like browsing Mastodon or scrolling through Feedly, but I almost never grab it when I want to write a blog post on work on some code for a personal project. With the potential idea of making an iPad my main personal computing device, I’ve been putting that to the test, as I hinted at in my post on WWDC 2022.
Blogging is a no-brainer not even warranting a post of its own. While I had run into issues using using some other blogging platforms via Safari on iPadOS — the names of which I have intentionally omitted to protect the guilty — blogging on Medium offers no such problems. Standard commands like Cmd + i
, Cmd + b
, and Cmd + k
all work flawlessly for editing text without getting gobbled by other things.
Code was another matter since I can’t natively execute anything on the iPad. The Swift Playgrounds app exists, but I’m not particularly interested in writing Swift, at least not at the moment. In my personal life I’m mainly focused on web development and some Python scripting. If I reached a point of competency in Python that I felt like venturing into another language, I’d probably start dabbling in Go, which I also have a passing familiarity with but nothing more than that.
VPS
I figured the easiest way to handle things would be to run a VPS and simply SSH to it from the iPad. I’ve had a VPS for the better part of the past decade of my life, though I’ve gone without one for the past several months. When I decided to bite the VPS bullet again, I looked for something that would be particularly inexpensive since I really just needed it for something that I could write and run code on. Thanks to a mention from a friend on Mastodon — who I’m not linking to simply because I don’t know if they would want the attention — I opted for the cheapest KVM VPS from RackNerd. This cost me $22 USD for a year, compared to the minimum of $5 USD per month that I could get from other places… some of which offer that price only if I happened to be grandfathered in.
SSH
The next issue facing me was how to connect with said VPS once it was deployed. While I would typically ssh
to something just by firing up a Terminal and running the command, naturally that’s not an option on iPadOS. I started looking for SSH applications on the app store, and I was immediately dumbfounded at the number of app which wanted to charge a subscription. I get that a ton of platforms have moved to a subscription model, but this is an SSH app running on my iPad… there’s absolutely no way I’m going to be paying any kind of annual fee for that. When I took all of those options off the table, the most appealing one was Prompt. It cost $15 USD up front, but that was it… there are no ongoing fees.
Prompt works fairly well for a “mobile” SSH client. I’ve not bothered installing it on my iPhone, as I really just wanted it for my iPad when I have the Smart Keyboard Folio connected. The resiliency of the connection has really impressed me thus far. I’ve mainly used it when I’ve been out and about — hence why having a VPS mattered as opposed to just connecting to my Raspberry Pi at home — and I was pleasantly surprised to find that I could take my iPad and:
- Connect to WiFi at the business I was at.
- Connect to my VPN to secure my traffic.
- SSH to my VPS via Prompt.
- Work for any amount of time,
Cmd + Tab
ing between Prompt and Safari as I look things up to RTFM. - Lock my iPad and throw it into my bag because I need to step away for whatever reason and don’t want to just leave my iPad sitting unattended.
- Pull my iPad back out after some amount of time, unlock it, and still be connected to both my VPN and my SSH session.
The workflow above was especially impressive to me because I wasn’t connecting via Mosh; this was through vanilla SSH. It is worth mentioning, however, that initially things weren’t quite so seamless; I had to turn on “Connection History” in the Prompt settings. Prior to this, I noticed I would get disconnected if I had simply switched apps over to Safari for too long:
One hurdle I haven’t quite overcome yet is that occasionally the UI in my editor will get a bit skewed while connected through Prompt. For example, the current line that I hop to may be completely blacked out or missing any type of customization from my theme. I’m not sure if this is a Prompt issue, a theme issue, or something completely unrelated, though. I typically just note which line I’m on in Vim, go to the very top or bottom of the document (whichever will force the screen to completely overwrite), and then navigate back to the line in question. Forcing the screen to re-paint typically solves the problem, though for smaller files that don’t fill a screen I’m left with closing and re-opening the file, which isn’t ideal.
Vim
The other hurdle I ran into was that the aforementioned Smart Keyboard Folio, just like the Magic Keyboard, is completely lacking in an Escape key. This is particularly problematic since I want to use Vim within my SSH session. Vim alleviates all of the other missing keys from the keyboard and allows for the fasting editing experience… as long as I can switch modes. Fortunately, the fix is relatively simple. I just needed to swap the key/key combination to switch modes in Vim from Escape to something different. I personally found this StackExchange response to be not just a great tutorial on how to change the key combination but also on the rationale behind why the poster selected the combination that they did. Following this, I added these lines to my ~/.vimrc
file on my VPS:
inoremap kj <esc>
vnoremap kj <esc>
cnoremap kj <C-C>
In all modes, this switches the behavior of Escape from that key to hitting kj
in quick succession. As the author of the post notes, you virtually never need to type these characters next to one another in Vim’s insert mode. Typing it feels quite natural and, as someone who frequently taps Escape a few times just to ensure I’m in Normal mode any time I haven’t typed something for more than a few seconds in Vim, it’s a net neutral movement that doesn’t displace my cursor from where I want it to be.
After spending about 4 hours today working on a project just through my iPad with this setup, it was fairly pleasant. The biggest distraction was the UI rendering issue I experienced in Vim, the source of which I need to spend a little more time nailing down. I’m not committed to saying that I feel this would be a completely workable solution for me to move to an iPad as my main personal computing device, but it at least shows me that the idea isn’t completely outside the realm of possibility. It’s something that warrants further testing from me, along with seeing how new iPadOS features like Stage Manager impact it.