Add Micro post

This commit is contained in:
Jake 2021-04-06 14:29:32 +00:00
parent 5c97632908
commit 9ccf8d40ef
1 changed files with 57 additions and 0 deletions

57
tips/micro.md Normal file
View File

@ -0,0 +1,57 @@
---
title: Micro Editor
date: 2021-04-06
description: Editing code in a shell without going insane with Micro.
---
There's a couple of options available when it comes to editing code on a tilde like South London. The first ones that come to mind are probably `nano`, `vim`/`vi`/`neovim` and `emacs`. I usually end up using `vim` or `nano` if I have something quick to edit like a config file, but editing whole scripts and things is where they start to be a bit frustrating. Micro is an excellent editor that you can install quickly and makes your life a lot easier with mouse support and sane keyboard shortcuts.
## Install
Firstly, we need somewhere to install Micro, so lets make a folder at `~/.local/bin`.
```bash
mkdir -p ~/.local/bin
cd ~/.local/bin
```
Now lets run the install script. You should inspect the contents before running by just leaving the `bash` command off the end.
```bash
curl https://getmic.ro | bash
```
The installer script should automatically detect your architecture and operating system and download the relavent version to the folder that you are in.
Finally, we need to tell our shell that we have programs installed in `~/.local/bin` that we want to use. We can do that by adding the following line to the **bottom** of the `~/.bashrc` file.
```bash
# other things...
export PATH="${PATH}:~/.local/bin"
```
## Usage
Now that we've got Micro installed, simply run `micro` with a filename to open a file.
```
micro ~/public_html/index.html
```
You have the regular keyboard shortcuts you'd expect like <kbd>CTRL</kbd> + <kbd>O</kbd> and <kbd>CTRL</kbd> + <kbd>S</kbd> for open and save respectively.
You can use <kbd>CTRL</kbd> + <kbd>E</kbd> to run editor commands like these useful ones:
- `help`: get help on how to use the editor
- `open /path/to/file`: open a file
- `save`: save the opened file
- `vsplit /path/to/file`: split the editor vertically, opening the given file in the new split (<kbd>CTRL</kbd> + <kbd>W</kbd> to switch between splits, <kbd>CTRL</kbd> + <kbd>Q</kbd> to close the split)
- `hsplit /path/to/file`: same as a vertical split, but you guessed it, horizontal instead
- `set <option> <value>`: configure the editor, see below for some useful options
### Useful options
- `set clipboard internal`: this either needs to be set to `terminal` or `internal` as we'll be using Micro over SSH, otherwise if you installed it on your local computer, you'd set this to `external`. `internal` just keeps the copy and paste buffer inside the editor rather than copying to your system clipboard which I found a bit janky with `terminal`
- `set colorscheme darcula`: this sets the theme that is used for syntax highlighting. Use the command `help colors` to see the other themes that are available
- `set diffgutter true`: this shows a little colour indicator on the line number gutter to whether you have added/updated/removed lines, useful for if you are working with git.