Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request]: How would I set an option in insert mode only? #1174

Closed
roguh opened this issue Mar 21, 2024 · 12 comments
Closed

[Feature Request]: How would I set an option in insert mode only? #1174

roguh opened this issue Mar 21, 2024 · 12 comments

Comments

@roguh
Copy link
Contributor

roguh commented Mar 21, 2024

What feature would you like to see?

I would like to implement "smart hybrid line numbers" in vis, as described for vim here.

This means I want absolute line numbers set number in insert mode, and relative numbers in all other modes set relativenumber. I don't see an event for when a mode changes, is there a way to accomplish this with the Lua API?

@fischerling
Copy link
Contributor

You could do use a frequent event like vis.events.HIGHLIGHT.

Try something like:

do
  local last_mode = nil
  vis.events.subscribe(vis.events.WIN_HIGHLIGHT, function(win)
    if vis.mode == last_mode then
      return
    end

    last_mode = vis.mode
    if last_mode == vis.modes.INSERT then
      win.options.numbers = true
      win.options.relativenumbers = false
    else
      win.options.numbers = false
      win.options.relativenumbers = true
    end
  end)
end

in your visrc.lua.

It is not perfect because the number change lags one redraw behind, but maybe it helps.

@VehementHam
Copy link

VehementHam commented Apr 30, 2024

Or you could remap all of the bindings that take you to insert mode. You would have them do what they normally do, but also run the command to turn on numbers. Then <Esc> in insert mode would run the command to turn on relative numbers.

vis:map(vis.modes.NORMAL, "i", ":set numbers<Enter><vis-mode-insert>")
vis:map(vis.modes.INSERT, "<Escape>", "<vis-mode-normal>:set relativenumber<Enter>")

Of course you would have to do that with ALL of the bind that take you into insert mode.

Tested the code snippit and it works with no noticable delay.

@VehementHam
Copy link

If you take my suggestion, I recommend turning it into a plugin.

@VehementHam
Copy link

In fact this sounds like a feature I want, so if you give me a few days, I will create a plugin for it.

@VehementHam
Copy link

Working on it now.

@roguh
Copy link
Contributor Author

roguh commented May 12, 2024

Thank you! I unfortunately haven't had time to do this, but I can test out your plug-in when it's ready.

Out of curiosity, what feature were you looking to use this for?

@roguh
Copy link
Contributor Author

roguh commented May 13, 2024

I think an event coming from the C source code would be ideal, I might try to add an event for when the mode changes.

https://github.com/martanne/vis/blob/master/vis-core.h#L226

@VehementHam
Copy link

@mcepl
Copy link
Contributor

mcepl commented May 14, 2024

Obviously, this is not an issue to be tracked here, but a question which belongs more to the vis email list. Whichever way, @VehementHam ’s plugin is probably a good solution for your problem anyway.

@rnpnr , this could be probably be closed.

@roguh roguh closed this as completed May 15, 2024
@roguh
Copy link
Contributor Author

roguh commented May 15, 2024

Good call, @mcepl. I just closed it and can email next time.

@VehementHam
Copy link

If you are using my plugin, you should run a git pull. I pushed some important changes.

@VehementHam
Copy link

I would like to mention that there is issues with the Change Operator, because it does not change to insert mode upon press, but instead waits for the next keybind to be pressed, and depending on what it is, changes to instert mode.

Other than that, the plugin works fine. I would love to see a mode changing event be added in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants