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

Cut command is very slowly on Windows Terminal #3280

Open og900aero opened 2 months ago

og900aero commented 2 months ago

I use micro in Windows 10 with Windows terminal preview 1.20.10822.0 When I open file for edit in micro, then I hold down the CTRL+K key, it doesn't continuously delete the lines, but does nothing. When I release it, it deletes one row. If I use the nano program, there is no such problem.

I tried with the following version:

$micro --version Version: 2.0.13 Commit hash: 68d88b57 Compiled on October 21, 2023

$ micro --version Version: 2.0.14-dev.155 Commit hash: 55103179 Compiled on April 23, 2024

bindings.json:

{
    "\u001b[2J": "SelectToStartOfLine",
    "\u001b[K": "SelectToEndOfLine",
    "\u001b[P": "Delete",
    "Alt-/": "lua:comment.comment",
    "Alt-3": "lua:comment.comment",
    "Alt-Left": "PreviousTab",
    "Alt-Right": "NextTab",
    "Alt-g": "None",
    "Alt-w": "FindNext",
    "Ctrl-d": "DuplicateLine",
    "Ctrl-k": "Cut",
    "Ctrl-r": "command-edit:replaceall ",
    "Ctrl-s": "Save",
    "Ctrl-w": "Find",
    "Ctrl-x": "Quit",
    "CtrlUnderscore": "lua:comment.comment"
}
settings.json:

{
    "*.json": {
        "commenttype": "/* %s */"
    },
    "*.jsonc": {
        "commenttype": "/* %s */"
    },
    "*Xresources*": {
        "commenttype": "! %s"
    },
    "autoclose": false,
    "autosu": true,
    "backup": false,
    "clipboard": "terminal",
    "hlsearch": true,
    "softwrap": true
}
Gavin-Holt commented 1 month ago

Hi

In my Windows setup I wanted to delete the current line or all partially selected lines (my version of wordstar yank block ^KY):

  1. I bind CTRL+Y as follows in bindings.json
    "CtrlY": "lua:initlua.delsel,SelectLine,Delete",
  1. From my init.lua file:
    function delsel(Current)
    -- Please see the Ctrl+Y binding. This avoids deleting EOL
    if Current.Cursor:HasSelection(Current) then
        Current.Cursor:DeleteSelection()
    end
    end
  2. This repeats if I hold down CTRL+Y, it works on Windows console and Windows terminal.

Kind Regards Gavin Holt

og900aero commented 1 month ago
function delsel(Current)
-- Please see the Ctrl+Y binding. This avoids deleting EOL
    if Current.Cursor:HasSelection(Current) then
        Current.Cursor:DeleteSelection()
    end
end

I paste the following line in the bindings.json:

"Ctrl-k": "lua:initlua.delsel,SelectLine,Delete",

Then I create ~/.config/micro/init.lua file, and insert the following rows:

function delsel(Current)
-- Please see the Ctrl+Y binding. This avoids deleting EOL
    if Current.Cursor:HasSelection(Current) then
        Current.Cursor:DeleteSelection()
    end
end

Now , when I press ctrl+k, the the following error message appear:

init:3: invalid number of function arguments (1 expected, got 2)
stack traceback:
        [G]: in function 'HasSelection'
        init:3: in main chunk
        [G]: ?

Press enter to continue
Gavin-Holt commented 1 month ago

Hi

Sorry try:

function delsel(Current)
-- Please see the Ctrl+Y binding. This avoids deleting EOL
    if Current.Cursor:HasSelection() then
        Current.Cursor:DeleteSelection()
    end
end

Kind Regards Gavin Holt

og900aero commented 1 month ago

Hi

Sorry try:

function delsel(Current)
-- Please see the Ctrl+Y binding. This avoids deleting EOL
    if Current.Cursor:HasSelection() then
        Current.Cursor:DeleteSelection()
    end
end

Kind Regards Gavin Holt

Thx. Working great.

But it wouldn't be bad if the deletion would also work with the Cut command when pressed for a long time, as in the case of a Linux terminals.