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