Open haqk opened 4 years ago
You can do this with some Lua code. Place the following in ~/.config/micro/init.lua
:
function toggleSoftwrap(bp)
bp.Buf.Settings["softwrap"] = not bp.Buf.Settings["softwrap"]
end
Then in ~/.config/micro/bindings.json
you can bind this action with
{
"Alt-r": "lua:initlua.toggleSoftwrap"
}
That works, but only if I run under sudo. If I open micro as a normal user I get:
function does not exist: lua:initlua.toggleSoftwrap
Press enter to continue
Any clues?
It looks like you might have a recent version of micro installed for sudo and an old version installed for your normal user. I recommend checking the version and upgrading to the latest version.
Why won't you implement a toggle for soft wrap by default. Other command line editors can toggle soft wrap via a keybinding or a command like Nano, Vim and Emacs. It would be more convenient for users to do it through a simple toggle rather than having to bind it through Lua or changing the config each time.
I could second that. set <option> <value>
is used for setting an option, and i think a toggle <option>
command would be nice. It would work only for boolean options and generate an error if it is used for example with a number option.
And perhaps also togglelocal
(similar to setlocal
).
I currently have the following in my bindings.json
{
"Alt-Z": "command:set wordwrap on,command:set softwrap on",
"Alt-z": "command:set wordwrap off,command:set softwrap off",
}
and it works really well for me. I would prefer if the same key was used to toggle, as opposed to using a shifted version of Z to turn it on. Note that alt+z
is the default keybinding is VSCode, which is a good argument for enabling this by default with that keybinding in micro.
As I wrote in https://github.com/zyedidia/micro/issues/2086#issuecomment-826351299, a generic toggle
command can be quite easily implemented in Lua. But perhaps it's time to implement it in Micro itself, to have it out of the box, since quite a few people express interest in this feature.
Then you'll be able to use "Alt-z": "command:toggle wordwrap,command:toggle softwrap"
(though in this specific case I'd still write some Lua code to make sure that the values of softwrap
and wordwrap
stay in sync. I.e.: toggle softwrap
and set wordwrap
to the same value as softwrap
.)
Is it possible to implement a ToggleSoftwrap action?