zyedidia / micro

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

Disable text autocompletions #3269

Open squili opened 2 months ago

squili commented 2 months ago

Description of the problem or steps to reproduce

I have a file that uses tabs as part of it's specification. Specifically, you might have a file that looks like: @<tab>A<tab>1.2.3.4. When entering this using micro, sometimes micro tries to autocomplete one of the parts of the line, which forces weird cursor movements to avoid the prompts. I assume there's a setting to disable this, but I cannot find it!

Specifications

Commit hash: 68d88b57 OS: Arch Linux Terminal: GNOME Terminal

Andriamanitra commented 2 months ago

I don't know if there's a setting to disable auto-complete but bind Tab InsertTab is a nice workaround.

dmaluka commented 2 months ago

I thing bind Tab InsertTab is the way to disable autocomplete.

The Tab key by default is bound to Autocomplete|IndentSelection|InsertTab, which means: try to autocomplete; if that failed (i.e. no completion found, or there is nothing to complete), try to indent the selection; if that failed (i.e. if there is no selection), just insert the tab.

So if you want the Tab key to just insert the tab, just bind it to InsertTab instead.

Andriamanitra commented 2 months ago

One downside of using keybindings instead of having a setting is that you can't have them apply only to certain filetypes.

We could add a setting so you could do something like this in settings.json:

{
    "*.tsv": {
        "autocomplete": false
    }
}

Alternatively we could add the globbing feature from settings.json to bindings.json too? One potential issue here is that bindings.json already supports pane type specific keybindings using similar syntax which might complicate the implementation.

Or we could leave it as is. It's a pretty niche feature that's really easy to implement as a plugin:

function preAutocomplete(bufpane)
    -- disable autocomplete if filetype is set to "tsv"
    return bufpane.Buf:FileType() ~= "tsv"
end