]> git.lizzy.rs Git - micro.git/blobdiff - runtime/help/tutorial.md
better top
[micro.git] / runtime / help / tutorial.md
index 707a3c54e36d9d9917c4d811b987d75fb0f14e7f..2245fc368e7312f5c2de4d4c173b75b8335ae6da 100644 (file)
@@ -1,8 +1,8 @@
 # Tutorial
 
-This is a brief intro to micro's configuration system that will give some simple
-examples showing how to configure settings, rebind keys, and use `init.lua` to
-configure micro to your liking.
+This is a brief intro to micro's configuration system that will give some
+simple examples showing how to configure settings, rebind keys, and use
+`init.lua` to configure micro to your liking.
 
 Hopefully you'll find this useful.
 
@@ -16,13 +16,13 @@ the settings and their values. To change an option, you can either change the
 value in the `settings.json` file, or you can type it in directly while using
 micro.
 
-Simply press CtrlE to go to command mode, and type `set option value` (in the
+Press CtrlE to go to command mode, and type `set option value` (in the
 future, I will use `> set option value` to indicate pressing CtrlE). The change
 will take effect immediately and will also be saved to the `settings.json` file
 so that the setting will stick even after you close micro.
 
-You can also set options locally which means that the setting will only have the
-value you give it in the buffer you set it in. For example, if you have two
+You can also set options locally which means that the setting will only have
+the value you give it in the buffer you set it in. For example, if you have two
 splits open, and you type `> setlocal tabsize 2`, the tabsize will only be 2 in
 the current buffer. Also micro will not save this local change to the
 `settings.json` file. However, you can still set options locally in the
@@ -60,41 +60,51 @@ following in `bindings.json`:
 Very simple.
 
 You can also bind keys while in micro by using the `> bind key action` command,
-but the bindings you make with the command won't be saved to the `bindings.json`
-file.
+but the bindings you make with the command won't be saved to the
+`bindings.json` file.
 
-For more information about keybindings, like which keys can be bound, and
-what actions are available, see the `keybindings` help topic (`> help keybindings`).
+For more information about keybindings, like which keys can be bound, and what
+actions are available, see the `keybindings` help topic (`> help keybindings`).
 
 ### Configuration with Lua
 
 If you need more power than the json files provide, you can use the `init.lua`
 file. Create it in `~/.config/micro`. This file is a lua file that is run when
-micro starts and is essentially a one-file plugin.
+micro starts and is essentially a one-file plugin. The plugin name is
+`initlua`.
 
-I'll show you how to use the `init.lua` file by giving an example of how to
-create a binding to `CtrlR` which will execute `go run` on the current file,
+This example will show you how to use the `init.lua` file by creating a binding
+to `CtrlR` which will execute the bash command `go run` on the current file,
 given that the current file is a Go file.
 
 You can do that by putting the following in `init.lua`:
 
 ```lua
-function gorun()
-    local buf = CurView().Buf -- The current buffer
+local config = import("micro/config")
+local shell = import("micro/shell")
+
+function init()
+    -- true means overwrite any existing binding to CtrlR
+    -- this will modify the bindings.json file
+    config.TryBindKey("CtrlR", "lua:initlua.gorun", true)
+end
+
+function gorun(bp)
+    local buf = bp.Buf
     if buf:FileType() == "go" then
-        HandleShellCommand("go run " .. buf.Path, true, true) -- the first true means don't run it in the background
+        -- the true means run in the foreground
+        -- the false means send output to stdout (instead of returning it)
+        shell.RunInteractiveShell("go run " .. buf.Path, true, false)
     end
 end
-
-BindKey("CtrlR", "init.gorun")
 ```
 
-Alternatively, you could get rid of the `BindKey` line, and put this line in the
-`bindings.json` file:
+Alternatively, you could get rid of the `TryBindKey` line, and put this line in
+the `bindings.json` file:
 
 ```json
 {
-    "CtrlR": "init.gorun"
+    "CtrlR": "lua:initlua.gorun"
 }
 ```