Embracing the Neovim/Vim Terminal

I’ve only finally just started using Neovim’s terminal. Vim 8 has this too of course, but it was Neovim that championed it and included it by default.

I switched to Neovim about a year ago to see if there was anything missing compared to Vim. I find Neovim fascinating purely because of how faithful it is to Vim. They had the perfect answer to open source – “if you don’t like it fork it” and make your own. Vim itself is healthier because of the additions that Neovim included.

I literally can’t visually tell if I am using Vim or Neovim. You have the one initial setup to use your existing .vimrc file and the rest just works perfectly.

I’ve never had to raise a bug because of some incompatibility. All the Vim plugins I use work.

The sheer scale of porting an editor that has been around for 30 years to implement what appears to be 99.9% of it’s functionality is amazing.

First steps

One of the big things of Neovim was its inclusion of a terminal.

I’d tried the terminal a couple of times but I found it jarring, it’s like the Vim experience all over again – you’ve no idea how to quit.

You need a combination of Ctrl + \, Ctrl + n, which is just as insane as :wq for those who don’t know Vim. I don’t know whether it’s an intentional homage, but all I know is that it scared me off for a year.

Somewhere during that year I tried tentatively again and added this (probably from this Vi StackExchange answer) as suggested to my vimrc:

" terminal easy escape
tnoremap <Esc> <C-\><C-n>

But then I just left it there. I always just kept a separate terminal open to run the commands I needed there. This currently is running a bunch of node docker containers. This obviously means alt + tab between the windows, or ctrl + pg up/pg down if you have terminal tabs (I’m using Ubuntu mostly).

However I kept seeing my colleagues running their terminal session within VS Code. I’d roll my eyes at the wasted screen space, but it did seem kind of natural, you have another step in your development process combined into the one editor.

I was always a fan of “Linux is my IDE” so I also didn’t see a problem of switching to the terminal, it also feels ‘fairly natural’ as both Vim and any other terminal programs are still running in the terminal, so I saw it as a benefit of Vim.

It always seemed natural that if you’re running a terminal process you should open up an actual terminal, not some emulator, get yourself the real thing.

However there’s a few niggles:

  1. Searching the terminal output, there are ways but they aren’t as nice as the Vim searching
  2. Scrolling naturally around the output, to the top and back to the bottom – especially when its 10,000+ lines long of log output
  3. Copying and pasting between the terminal output and Vim
  4. It janks either wasting the screenspace of the terminal tabs or having to alt + tab to search for the other terminal window

Welcome back

So I dived in again a couple of days ago. Having the Esc remapping is so natural, I’d forgotten that I’d added it to my vimrc and was simply the first thing I’d tried to get out. I had to go searching for it again just cause I remembered the frustration of quitting from before and didn’t understand why it was so easy.

But now, suddenly it’s awesome. Once you’ve hit Esc it’s just another buffer. It can hide amongst my hundreds of other buffers, so no screenspace wasted. This obviously assumes you’re using Buffers not ‘Tabs’ (aka Tab Pages).

It resolves all the problems above:

  1. Searching – I now have my standard \ command to search and highlight plus grepping/ripgrep/fzf
  2. Scrolling – now again all the gg top and G bottom commands are so much nicer to use, I never feel the need to use the mouse to scroll aimlessly amongst the text, I can always use Ctrl + f/g and j/k too – all the lovely Vim commands are now available
  3. Copying and pasting is just Vim buffers no need for the external clipboard
  4. As it’s all just buffers is no wasted screenspace and it’s easy to switch to with buffer switching.

So where as I understand it’s just an emulator, not the real terminal, but bash is kind of designed to emulated so not a real problem I guess and now I get terminal + evil mode!

So thanks again Neovim for adding this in.

Steps of caution

There are some peculiarities of Neovim terminals to get used to.

  1. Esc is sometimes used in the terminal for genuine reasons, for example cancelling an fzf request – this now won’t work. My solution to this has been to have the escape sequence be <leader><Esc> this allows escape to still work, but be still easy to quit out.
  2. The inception of running Vim via an SSH session inside a Vim terminal has a few niggles, but handles pretty well.
  3. It’s a bit hard to re-find your terminal if you’ve got a couple open – you need to remember the buffer number mostly
  4. If you close Vim you’ll kill all the processes running there without warning

On the power of netbooks and laptops over Android/iOS

iOS and Android turn tablets into oversized phones, so no surprise they lose against phones – they have the same (or usually worse, at a given price point) capabilities while being larger, thus less convenient to carry and more fragile.

TeMPOraL on HN

Windows did try the same as Android and iOS with Windows RT, thankfully that was a disaster. Certainly that’s one of the bad points about iOS and Android they are so locked down that you have to jump through hoops if you wanted to use them as a work machine. You have almost no access to the file system and you have to pay iPad pro levels of money to get the novelty of having windows side-by-side.

Netbooks are ridiculously useful, I used to have a 15 minute bus ride to work with a 12″ Asus EEE and would manage to fill that 15 minutes with active development time every day. The work I did on that bus became the frontend for what now 10 years later is a $50m company. On the other end of the scale I spent weeks with my then 7 year-old nephew creating stop-motion animations using the same netbook.

For my current job I bought myself a $350 refurbished Thinkpad (T430, 8GB RAM, SSD, core i5), this brings me in all my income. You can compare that to people that pay $1000 for an iPhone X because they get bored of their iPhone 8.

The possible drawback is that a Thinkpad doesn’t have a touchscreen. But with my experiment of buying a laptop with a touch screen I found I pretty much never wanted to use the touch screen, it’s a slower interface than keyboard and mouse. You want the screen in front of you at arms length but then you have to reach with your arm to touch the screen.

I bought exactly the same spec Thinkpad for my 5 year old daughter. The Thinkpad T-series are great because you can pour a litre of liquid over them without problem [0] plus they’re built like a brick, so basically perfect for kids. My daughter immediately covered the grey brick with shiny stickers and gave it a name, ‘Fiona’. In theory Fiona has the full capability to do everything my daughter will ever need for the rest of her school years; I don’t imagine a massive shift away from laptops in schools for the next 15 years. Further to that Fiona’s got Ubuntu installed and I can then install Sugar [1] on top (the same software used for One Laptop Per Child [4]).

I can now teach her over the years what it means to have real freedom with your software and hardware.

P.S. I posted an original version of this on HN [3]

Linux Mint Dual Boot

It’s not supposed to be this painful.

I finally (9 months after first attempt) got a UEFI dual boot working.

TL;DR Follow one of these:

  1. http://itsfoss.com/install-ubuntu-1404-dual-boot-mode-windows-8-81-uefi/
  2. http://www.tweaking4all.com/os-tips-and-tricks/uefi-dual-boot-windows81-ubuntu/

I’m calling Linux Mint my lucky charm as that was the first one I got working as a Vagrant desktop and it’s worked perfectly now that I’ve sorted out the other issues.

Having read and re-read so many articles – there were three final things I had problems with/didn’t understand:

  1. Unetbootin was creating blank USB drives fixed by using universal-usb-installer as recommended by both articles above
  2. UEFI bootable USB stick Universal USB works fine (you can create a UEFI only one by simply extracting an ISO using 7-zip and just copying the files, which ignores the extra step that also installs a MBR file (I think))
  3. Booting to USB when the BIOS is set to UEFI In Windows hold shift and click ‘Restart’ (fucking magic) – this point is buried as almost an aside in the main itsfoss.com article above:

To boot from USB, will have to choose boot from USB option from within Windows itself. Either with PC Setting (like for UEFI) or pressing shift key while clicking on Restart.

Point 3 is also in the wonderfully in-depth tweaking4all.com article.

The rest seemed quite ok as I had the rest of the BIOS settings / fast boot options correct.

Once I got the USB stick working, I ran the check disk once and then went into the live Linux Mint. The first happy thing was that the Wifi was working straight off – which wasn’t before with Ubuntu. I then followed the tweaking4all guide to create:

  • first a root (/) /ext4 logical partition
  • leaving 8GB (8191MB, to equal the RAM size) of space for the swap logical partition.

After Linux Mint installed – basically everything was perfect. Where as the tweaking4all guide talks about running the ‘Boot Repair’ program from Mint before restarting. However I took a gamble based on the itsfoss article that a reboot should work. And it did.

The GRUB bootloader was happily installed into the EFI ‘partition’ (not sure if that’s the right word) so that now starting the computer shows the dual-boot screen.

Then booting Linux Mint works perfectly fine – and again the Wifi was working. As was the other major obvious one of the power button working.

As a minor anecdotal point – the booting times (Lenovo Yoga 13, Core i7, 8GB RAM, SSD) for Mint vs Windows was 20s for both to get to the desktop after logging in. There goes my theory of how gloriously fast Linux is to load. I guess that just isn’t the case with Ubuntu based systems.

Now to blat Mint and see if Fedora is any faster.

vi commands for the Windows user

This is a cheat sheet for Windows keyboard junkies who feel as out of place in vi as I do. I got most of the vi commands from the rather useful IBM vi tutorial. dd was the only one I ever learnt (and I didn’t know that I could paste after deleting it). There’s loads more vi commands, I’ve just listed the ones that are most similar to Windows ones.

Alot of the vi commands are two letters together e.g. dd. To do these just tap the two letters quickly. N.B. capitalisation matters. So moving to line 100 in vi is 100, Shift+G quickly. But capital G & P are the only two capitals we use.

Update: I’ve just come across this excellent article on learning to speak vim, to get a more in depth understanding.

Quick start

Ctrl+Home = gg
Ctrl+End  = G
Ctrl+x    = dw / dd / dG
Ctrl+c    = yw / yy / yG
Ctrl+v    = p

Goto

Command Windows (Notepad) Vi (command mode) Notes
First line Ctrl+Home gg
Last line Ctrl+End G
Line N Ctrl+g, N, Enter Ngg e.g. 100, g, g quickly
End of the line End
  • End
  • $
Start of the line Home
  • Home
  • 0
Next word Ctrl+Right w
Previous word Ctrl+Left b
Page up Pg Up
  • Pg Up
  • Ctrl+u
Ctrl+u acts more similarly to Pg Up in Windows as Pg Up won’t take the cursor all the way to the top in vi.
Page down Pg Dn
  • Pg Dn
  • Ctrl+d
Find text Ctrl+f, [text], Enter (forward)
  • /[regex] (forward)
  • ?[regex] (back)
regex (regular expression): so you need to escape dots and backslashes e.g. \. \/
Replace text Ctrl+h, [search], [replace], Enter (forward)
  • :%s/[search]/[replace]/, Enter (line)
  • :%s/[search]/[replace]/g, Enter (global)
The vi search and replace are regex

Cut, Copy, Paste

Command Windows (Notepad) Vi (command mode) Notes
Delete Delete
  • Delete
  • x
Select Word
  • Double-click word
  • Ctrl+Left, Ctrl+Shift+Right (or vice-versa)
Double-click word
Select Line
  • Left-click in margin
  • Home, Shift+End
  • Home, Shift+Down
Drag mouse over line
Select All
  • Ctrl+a
  • Ctrl+Home, Ctrl+Shift+End
Delete Word Select Word, Delete dw
Delete Line Select Line, Delete dd
Delete rest of line Shift+End, Delete d$
Delete New line
  • End, Delete (next)
  • Home, Backspace (prev)
J (next)
Delete All Select All, Delete gg, dG
Copy Word Select Word, Ctrl+c Select Word, right-click,
yw, p/P
Copy Line Select Line, Ctrl+c y aka ‘Yank’
Copy All Select All, Ctrl+c gg, yG
Cut Word Select Word, Ctrl+x Delete Word
Cut Line Select Line, Ctrl+x Delete Line
Cut All Select All, Ctrl+x Delete All
Paste Ctrl+v
  • p (after cursor)
  • P (before cursor)

Undo, Redo

Command Windows (Notepad) Vi (command mode) Notes
Undo Ctrl+z u
Redo Ctrl+y Ctrl+r