mirror of
https://github.com/Hopiu/micro.git
synced 2026-04-28 01:54:42 +00:00
More command binding
Now can bind editable commands with `command-edit:` Ref #974
This commit is contained in:
parent
70616b335e
commit
a4ae7a1e11
4 changed files with 44 additions and 4 deletions
|
|
@ -479,6 +479,9 @@ func BindKey(k, v string) {
|
|||
} else if strings.HasPrefix(actionName, "command:") {
|
||||
cmd := strings.SplitN(actionName, ":", 2)[1]
|
||||
actions = append(actions, CommandAction(cmd))
|
||||
} else if strings.HasPrefix(actionName, "command-edit:") {
|
||||
cmd := strings.SplitN(actionName, ":", 2)[1]
|
||||
actions = append(actions, CommandEditAction(cmd))
|
||||
} else {
|
||||
actions = append(actions, findAction(actionName))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -120,6 +120,16 @@ func DefaultCommands() map[string]StrCommand {
|
|||
}
|
||||
}
|
||||
|
||||
func CommandEditAction(prompt string) func(*View, bool) bool {
|
||||
return func(v *View, usePlugin bool) bool {
|
||||
input, canceled := messenger.Prompt("> ", prompt, "Command", CommandCompletion)
|
||||
if !canceled {
|
||||
HandleCommand(input)
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func CommandAction(cmd string) func(*View, bool) bool {
|
||||
return func(v *View, usePlugin bool) bool {
|
||||
HandleCommand(cmd)
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -47,6 +47,33 @@ save and quit you can bind it like so:
|
|||
}
|
||||
```
|
||||
|
||||
## Binding commands
|
||||
|
||||
You can also bind a key to execute a command in command mode (see
|
||||
`help commands`). Simply prepend the binding with `command:`. For example:
|
||||
|
||||
```json
|
||||
{
|
||||
"Alt-p": "command:pwd"
|
||||
}
|
||||
```
|
||||
|
||||
Now when you press `Alt-p` the `pwd` command will be executed which will show
|
||||
your working directory in the infobar.
|
||||
|
||||
You can also bind an "editable" command with `command-edit:`. This means that
|
||||
micro won't immediately execute the command when you press the binding, but
|
||||
instead just place the string in the infobar in command mode. For example,
|
||||
you could rebind `CtrlG` to `> help`:
|
||||
|
||||
```json
|
||||
{
|
||||
"CtrlG": "command-edit:help "
|
||||
}
|
||||
```
|
||||
|
||||
Now when you press `CtrlG`, `help` will appear in the command bar and your cursor will
|
||||
be placed after it (note the space in the json that controls the cursor placement).
|
||||
|
||||
## Binding raw escape sequences
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue