Look ma, no mouse: tips and tricks
Repeatedly reaching for your mouse slows you down in the short term, and in the long term brings on health problems (RSI). To stay fast and healthy, keep your hands on your keyboard. To keep your hands there, this series, “Look ma, no mouse!” will guide you through easy to use tools to use your keyboard to control your computer instead of your mouse.
In this piece, we’ll look at a few tips and tricks to do so.
Mouse clicks from the keyboard
Even with i3 and vimium, sometimes the browser is out of focus and needs a simple mouse click (especially if we use Ctrl+L). To do this with they keyboard, we’ll bust out xte, an easy to use keyboard and mouse input simulator. It can do a lot more than click, but clicking is what we’re after.
Install:
sudo apt install -y xautomation
Use in the terminal:
echo mouseclick 1 | xte
Integrate left, middle, and right click into i3 by adding the following to i3’s config:
bindsym $mod+Shift+A exec "echo mouseclick 1 | xte"
bindsym $mod+Shift+S exec "echo mouseclick 2 | xte"
bindsym $mod+Shift+D exec "echo mouseclick 3 | xte"
xte can also move the mouse with the keyboard too, but personally, I rarely need to move the mouse so it’s more cumbersome than it’s worth.
Pull Down the Menu Bar
F10. A small, but useful trick for GUI applications, F10 brings down the menu bar which you can then navigate with using arrow keys. Alternatively, Alt, and then the letter of an underlined menu item selects that menu item.
Keyboard copying text from the terminal
In a GUI editor like gmail, we can select text with the keyboard (Ctrl+Shift+arrow keys), but not in a terminal. As such, in gnome-terminal for linux and iterm2 for mac, using the mouse is the standard way to copy text. Let’s fix that:
pbcopy
pbcopy’s a really useful tool, it copies text passed into it on stdin.
On linux, install xsel and alias it to pbcopy
sudo apt install -y xsel
alias pbcopy='xsel --clipboard --input'
On mac, pbcopy is built in.
Now we can copy text directly in the terminal:
echo copy me | pbcopy
copies the text into the terminal. This works great if the text we want to copy is the output of a command, but what if we want to copy text already output into our terminal. We’ll need tmux.
tmux
Tmux is a real upgrade on the terminal experience and indispensable for remote sessions, but today we’ll just cover its copy mode.
Install:
sudo apt install -y tmux
Run:
tmux
Your terminal will clear and in the bottom you’ll see a green bar.
Now generate some text, personally I like seq:
seq 20
Now to copy the numbers 8 through 14, press Ctrl+b then [
In the upper right hand corner, you should see [0/0] in yellow.
Now use k from vi conventions to navigate up to the number 8. Press space (like in vi) to start selecting, and navigate to 14 with j and press enter to “copy”. Type
tmux saveb -
It should output 8 through 14. However if you type pbpaste, it will still show “copy me” That’s because tmux maintains its own separate copy buffer from the system clipboard. To copy the text from tmux into the system clipboard, combine these commands.
tmux saveb - | pbcopy
tmux saveb - will output the contents of the copy buffer and pbcopy takes them and copies them to the clipboard. Personally I have an alias tmux-to-cp for this. Although there’s the “set-clipboard on” configuration option in tmux, it didn’t work on my computer so I cannot recommend it.
Conclusion
This concludes our “Look Ma, No Mouse” series. If you have any tricks to avoid the mouse that you love but we didn’t cover, share in the comments below.
If you don’t want to miss out on more tips to code faster, just hit “Subscribe now” below.