]> git.lizzy.rs Git - micro.git/blob - runtime/help/tutorial.md
Merge pull request #233 from schollz/master
[micro.git] / runtime / help / tutorial.md
1 # Tutorial
2
3 This is a brief intro to micro's configuration system that will give some
4 simple examples showing how to configure settings, rebind keys,
5 and use `init.lua` to configure micro to your liking.
6
7 Hopefully you'll find this useful.
8
9 ### Settings
10
11 In micro, your settings are stored in `~/.config/micro/settings.json`, a file
12 that is created the first time you run micro. It is a json file which holds
13 all the settings and their values. To change an option, you can either
14 change the value in the `settings.json` file, or you can type it in directly
15 while using micro.
16
17 Simply press CtrlE to go to command mode, and type `set option value` (in the
18 future, I will use `> set option value` to indicate pressing CtrlE). The
19 change will take effect immediately and will also be saved to the `settings.json`
20 file so that the setting will stick even after you close micro.
21
22 You can also set options locally which means that the setting will only have
23 the value you give it in the buffer you set it in. For example, if you have
24 two splits open, and you type `> setlocal tabsize 2`, the tabsize will only
25 be 2 in the current buffer. Also micro will not save this local change to the
26 `settings.json` file. However, you can still set options locally in the
27 `settings.json` file. For example, if you want the `tabsize` to be 2 only
28 in Ruby files, and 4 otherwise, you could put the following in `settings.json`:
29
30 ```json
31 {
32     "*.rb": {
33         "tabsize": 2
34     },
35     "tabsize": 4
36 }
37 ```
38
39 Micro will set the `tabsize` to 2 only in files which match the glob `*.rb`.
40
41 If you would like to know more about all the available options, see the
42 `options` topic (`> help options`).
43
44 ### Keybindings
45
46 Keybindings work in much the same way as options. You configure them using
47 the `~/.config/micro/bindings.json` file.
48
49 For example if you would like to bind `CtrlR` to redo you could put the
50 following in `bindings.json`:
51
52 ```json
53 {
54     "CtrlR": "redo"
55 }
56 ```
57
58 Very simple.
59
60 You can also bind keys while in micro by using the `> bind key action` command,
61 but the bindings you make with the command won't be saved to the `bindings.json`
62 file.
63
64 For more information about keybindings, like which keys can be bound, and
65 what actions are available, see the `keybindings` help topic (`> help keybindings`).
66
67 ### Configuration with Lua
68
69 If you need more power than the json files provide, you can use the `init.lua`
70 file. Create it in `~/.config/micro`. This file is a lua file that is run
71 when micro starts and is essentially a one-file plugin.
72
73 I'll show you how to use the `init.lua` file by giving an example of how to
74 create a binding to `CtrlR` which will execute `go run` on the current file,
75 given that the current file is a Go file.
76
77 You can do that by putting the following in `init.lua`:
78
79 ```lua
80 function gorun()
81     local buf = CurView().Buf -- The current buffer
82     if buf:FileType() == "go" then
83         HandleShellCommand("go run " .. buf.Path, true) -- true means don't run it in the background
84     end
85 end
86
87 BindKey("CtrlR", "init.gorun")
88 ```
89
90 Alternatively, you could get rid of the `BindKey` line, and put this line in
91 the `bindings.json` file:
92
93 ```json
94 {
95     "CtrlR": "init.gorun"
96 }
97 ```
98
99 For more information about plugins and the lua system that micro uses, see
100 the `plugins` help topic (`> help plugins`).