zyedidia / micro

A modern and intuitive terminal-based text editor
https://micro-editor.github.io
MIT License
24.42k stars 1.16k forks source link

[feature request] insert/overwrite indicator #3155

Open shaicoleman opened 4 months ago

shaicoleman commented 4 months ago

At the moment there's no way to see whether you're in insert or overwrite mode.

There are a few possible complementary ways to achieve it:

Commit hash: 68d88b57 OS: Linux Mint 21.3 (based on Ubuntu Linux 22.04) Terminal: kitty 0.32.2

Andriamanitra commented 4 months ago

There are a few possible complementary ways to achieve it:

  • When pressing the Insert key, it will show "Insert" or "Overwrite" in the status line
  • It can be supported through a function that's available statusformatl / statusformatl , e.g. $(overwritemode)

You could write a plugin to accomplish either of these two.

  • The cursor can change (may not work on all terminals)

This one probably need changes in the editor itself but I'm not sure if it's a good idea when you consider the terminal support issue.

taconi commented 4 months ago

@Andriamanitra How would I get the information that insert mode is active in a lua plugin?

Andriamanitra commented 4 months ago

@Andriamanitra How would I get the information that insert mode is active in a lua plugin?

As far as I know the overwrite mode always starts as false so the simplest way is to catch the ToggleOverwriteMode event:

local micro = import("micro")

overwriteMode = false

function onToggleOverwriteMode(bufpane)
    overwriteMode = not overwriteMode

    if overwriteMode then
        micro.InfoBar():Message("Insert mode ON")
    else
        micro.InfoBar():Message("Insert mode OFF")
    end
end

You may want to use a table instead of a boolean to keep track of insert mode state per buffer but hopefully this is enough to get you started.

dmaluka commented 4 months ago

You may want to use a table instead of a boolean to keep track of insert mode state per buffer

To be precise, it should be per bufpane, not per buffer. Overwrite mode is per pane, and the same buffer may be opened in multiple panes.