nano 中隐藏的复制/粘贴键绑定

问题描述 投票:0回答:2

我正在无头树莓派(牛眼)上使用nano中的lidssd1306。目标是允许通过 oled 显示屏上的编码器选择来执行 C 程序。

由于某种原因,在 Nano 中编辑文件时,

ctrl+shift+c
ctrl+shift+v
无法在文件/选项卡之间复制文本。
Ctl+6
Alt+6(Ctl+K)
Ctl+U
按文件中的预期工作。我曾以为我的紧凑型无线键盘是罪魁祸首,但这种可能性已经被排除,我的连接方法也被排除了。来自另一个 PI 的 SSH,来自 win10 桌面的 ExtraPuTTY,甚至本地。

我已经编辑了配置文件

/etc/nanorc
并创建了
~/.nanorc
。在实验设计中,对于每个文件,我启用/禁用了以下选项:

set mouse
bind ^X, ^C, ^V

这些都不允许我在文件之间复制/粘贴。

由于

ctrl+shift+c
ctrl+shift+v
在终端中正常工作,我一直使用
cat
来显示文件并复制我想要的行。从那里我可以使用
ctrl+shift+v
将文本粘贴到 Nano 编辑器中。我可能可以使用
awk
来完成任务,但这两种方法似乎都使简单的任务变得过于复杂。

据此我推断必须存在隐藏/混淆的键绑定或设置

允许在文件之间进行简单复制/粘贴的隐藏键绑定或设置是什么?

RasPi 靶心 ExtraPuTTY 0.29_RC2
纳米5.4

copy paste key-bindings nano
2个回答
0
投票

答案是nano不支持人民币。有趣的是,它们支持按钮 4 和 5。也许有一天我会自己编写代码,我会将其添加到列表中...

来自 nano src 文件中的 winio.c:

#ifdef ENABLE_MOUSE
/* Handle any mouse event that may have occurred.  We currently handle
 * releases/clicks of the first mouse button.  If allow_shortcuts is
 * TRUE, releasing/clicking on a visible shortcut will put back the
 * keystroke associated with that shortcut.  If ncurses supports them,
 * we also handle presses of the fourth mouse button (upward rolls of
 * the mouse wheel) by putting back keystrokes to move up, and presses
 * of the fifth mouse button (downward rolls of the mouse wheel) by
 * putting back keystrokes to move down.  We also store the coordinates
 * of a mouse event that needs further handling in mouse_x and mouse_y.
 * Return -1 on error, 0 if the mouse event needs to be handled, 1 if it's
 * been handled by putting back keystrokes, or 2 if it's been ignored. */
int get_mouseinput(int *mouse_y, int *mouse_x, bool allow_shortcuts)
{
    bool in_middle, in_footer;
    MEVENT event;

    /* First, get the actual mouse event. */
    if (getmouse(&event) == ERR)
        return -1;

    in_middle = wenclose(midwin, event.y, event.x);
    in_footer = wenclose(footwin, event.y, event.x);

    /* Copy (and possibly adjust) the coordinates of the mouse event. */
    *mouse_x = event.x - (in_middle ? margin : 0);
    *mouse_y = event.y;

    /* Handle releases/clicks of the first mouse button. */
    if (event.bstate & (BUTTON1_RELEASED | BUTTON1_CLICKED)) {
        /* If we're allowing shortcuts, and the current shortcut list is
         * being displayed on the last two lines of the screen, and the
         * first mouse button was released on/clicked inside it, we need
         * to figure out which shortcut was released on/clicked and put
         * back the equivalent keystroke(s) for it. */
        if (allow_shortcuts && !ISSET(NO_HELP) && in_footer) {
            int width;
                /* The width of each shortcut item, except the last two. */
            int index;
                /* The calculated index of the clicked item. */
            size_t number;
                /* The number of shortcut items that get displayed. */

            /* Shift the coordinates to be relative to the bottom window. */
            wmouse_trafo(footwin, mouse_y, mouse_x, FALSE);

            /* Clicks on the status bar are handled elsewhere, so
             * restore the untranslated mouse-event coordinates. */
            if (*mouse_y == 0) {
                *mouse_x = event.x;
                *mouse_y = event.y;
                return 0;
            }

            /* Determine how many shortcuts are being shown. */
            number = shown_entries_for(currmenu);

            /* Calculate the clickable width of each menu item. */
            if (number < 5)
                width = COLS / 2;
            else
                width = COLS / ((number + 1) / 2);

            /* Calculate the one-based index in the shortcut list. */
            index = (*mouse_x / width) * 2 + *mouse_y;

            /* Adjust the index if we hit the last two wider ones. */
            if ((index > number) && (*mouse_x % width < COLS % width))
                index -= 2;

            /* Ignore clicks beyond the last shortcut. */
            if (index > number)
                return 2;

            /* Search through the list of functions to determine which
             * shortcut in the current menu the user clicked on; then
             * put the corresponding keystroke into the keyboard buffer. */
            for (funcstruct *f = allfuncs; f != NULL; f = f->next) {
                if ((f->menus & currmenu) == 0)
                    continue;
                if (first_sc_for(currmenu, f->func) == NULL)
                    continue;
                if (--index == 0) {
                    const keystruct *shortcut = first_sc_for(currmenu, f->func);

                    put_back(shortcut->keycode);
                    if (0x20 <= shortcut->keycode && shortcut->keycode <= 0x7E)
                        put_back(ESC_CODE);
                    break;
                }
            }

            return 1;
        } else
            /* Clicks outside of the bottom window are handled elsewhere. */
            return 0;
    }
#if NCURSES_MOUSE_VERSION >= 2
    /* Handle "presses" of the fourth and fifth mouse buttons
     * (upward and downward rolls of the mouse wheel). */
    else if (event.bstate & (BUTTON4_PRESSED | BUTTON5_PRESSED)) {
        if (in_footer)
            /* Shift the coordinates to be relative to the bottom window. */
            wmouse_trafo(footwin, mouse_y, mouse_x, FALSE);

        if (in_middle || (in_footer && *mouse_y == 0)) {
            int keycode = (event.bstate & BUTTON4_PRESSED) ? KEY_UP : KEY_DOWN;

            /* One roll of the mouse wheel should move three lines. */
            for (int count = 3; count > 0; count--)
                put_back(keycode);

            return 1;
        } else
            /* Ignore "presses" of the fourth and fifth mouse buttons
             * that aren't on the edit window or the status bar. */
            return 2;
    }
#endif
    /* Ignore all other mouse events. */
    return 2;
}
#endif /* ENABLE_MOUSE */

0
投票

假设nano在xterm上运行,只需常规的xterm键绑定即可轻松将系统剪贴板粘贴到nano中,例如通过Ctrl-Shift-V,即绕过nano的内部复制粘贴机制。所以那里没有问题。要从 nano 复制粘贴到另一个 nano 或其他任何地方,请将其放入 nanorc 中:

bind M-i "{execute}|xsel -ib{enter}{undo}" main

M-i 是 Alt-i(在我的键盘和许多其他键盘中)。使用 Alt 或 Ctrl (^i) 或 Shift-Alt (Sh-M-i) 放置任何未使用的键。如果使用的话,首先进入(进入nanoc):

unbind M-i main

显然需要xsel或xclip包。

这个功能去年已经被引入到nano中了(我猜)。此机制的一些其他示例,用于全选并锚定您的位置以轻松返回,并将选择转换为大写/小写:

bind ^A "{anchor}{firstline}{mark}{lastline}" all
bind Sh-M-A "{anchor}" all
bind M-1 "{prevanchor}" all
bind M-2 "{nextanchor}" all
bind Sh-M-U "{nextword}{mark}{prevword}{execute}|sed 's/.*/\U&/'{enter}" main
bind Sh-M-L "{nextword}{mark}{prevword}{execute}|sed 's/.*/\L&/'{enter}" main
© www.soinside.com 2019 - 2024. All rights reserved.