micro icon indicating copy to clipboard operation
micro copied to clipboard

When Running Micro with Several Files (to Create Several Tabs), Is It Possible to Choose the Active Tab?

Open spaceman5 opened this issue 6 months ago • 3 comments

Hi

When running micro with several filenames as parameters, micro creates several Tabs, a Tab for each File.

For example: micro file1.txt file2.txt file4.txt file4.txt

The current behavior, is that the first tab is always the active tab.

Is it possible, in command-line, to specify the active tab, so it will be different than first file?

For example using a preceding character, that will indicate what is my chosen active tab when the program starts.. Something like: micro file1.txt file2.txt @file4.txt file4.txt

(I chose the "@" char just as an example, because it's big and noticable, but of course it can be any character that the developer thinks that is good, and hopefully one that is not a bash operator, so it will not be interpreted by the shell)

Is there currently a way to do it? If not, can I recommend this as a small feature request?

Thank you

spaceman5 avatar Jun 15 '25 13:06 spaceman5

There is nothing like this built-in but you can easily implement it as a plugin (put this to ~/.config/micro/init.lua):

local micro = import("micro")

function postinit()
    local tabs = micro.Tabs()
    for i=1,#tabs.List do
        local tab = tabs.List[i]
        local bp = tab:CurPane()
        if bp.Buf.Path:match("^@") then
            tabs:SetActive(i-1)
            bp:OpenCmd({bp.Buf.Path:sub(2)})
        end
    end
end

Note that this has the caveat that if a filename starts with @ you can no longer open it by giving it as a command line argument to micro (you can still open it normally after starting micro with open or tab commands). You could improve the plugin to at least check if a file called "@file.txt" exists before replacing the buffer with "file.txt".


Personally I don't understand the utility of this feature. Adding a @ to one of the arguments takes approximately the same amount of effort as swapping the order, or simply changing the tab after micro opens.

Andriamanitra avatar Jun 15 '25 16:06 Andriamanitra

This feature reminds me of parsecursor option/feature, these features could be merged under the same option imo.

cutelisp avatar Jun 15 '25 22:06 cutelisp

Personally I don't understand the utility of this feature. Adding a @ to one of the arguments takes approximately the same amount of effort as simply changing the tab after micro opens.

If you manually type micro file1.txt file2.txt file4.txt file4.txt every time you need to open that set of files, then yes, it takes the same amount of effort.

But If you created a macro (alias) to run that line, then there's logic to have the active file specified in the command, since it will do it for you every time.

or swapping the order

You might want the files in a certain logical order, and not to ruin that by moving 1 file to the start, just to make it active.

The whole feature takes 2 lines of code, so If the developer thinks it's useful, it would be nice to have it.

BTW, I gave the '@' char as an example, but ideally the chosen char to indicate the active tab will be a char that is not interpreted by bash, so not to clash with bash operators.

spaceman5 avatar Jun 16 '25 14:06 spaceman5