25

我在某些项目中使用 Notepad++ 并且错过了 Visual Studio 的Ctrl+ XCtrl+C功能,该功能会在未选择文本时剪切或复制整个当前行。剪切线快捷键好像是Ctrl+ L,不如Ctrl+方便X,复制快捷键好像是Ctrl+ D, Ctrl+ L,更不方便。

虽然之前已经问过类似的问题,但没有提供在 Notepad++ 中执行此操作的方法,我在 Notepad++ 网站或其论坛上找不到解决方案。

4

8 回答 8

26

我创建了一个 Notepad++ 插件(不需要 python)。它可以在https://bitbucket.org/zastrowm/notepad-visualstudiolinecopy找到。

于 2012-12-29T21:00:51.710 回答
22

Synthesizing all other answers and comments, plus some additional necessary steps that haven't been mentioned:

Scintilla provides a "copyAllowLine" command that does this. Notepad++ doesn't expose that command in the shortcut mapper, but you can call it from a Python script and map Ctrl + C to that script. There is no corresponding command for "cutAllowLine", but a bit of extra Python code will do it. These scripts must be added to the menu and Notepad++ must restart before they will become available in the shortcut mapper.

  1. Install Python Script plugin(can be done with Notepad++ Plugin Manager)

  2. Create the following two python scripts using the menu Plugins -> Python Script -> New script

    copyAllowLine.py

    editor.copyAllowLine()
    


    cutAllowLine.py

    if editor.getSelectionStart() == editor.getSelectionEnd():
        editor.lineCut()
    else:
        editor.cut()
    


  3. Python Script -> Configuration

    • under User Scripts, add a menu item for each script.

  4. Restart notepad++ (important)

  5. Settings -> Shortcut Mapper...

    • under Scintilla Commands, remove the existing associations for Ctrl + C and Ctrl + X.

    • under Plugin commands, find the scripts you just created and map your shortcuts to them.

Note: when installed via plugin manager, version 1.0.6 was installed. When I attempted to run anything python related in Notepad++ I got an unknown exception from plugin manager. The solution was to manually download and install the 1.0.8 .msi from here: 1.0.8 installer

于 2011-11-29T21:59:33.673 回答
3
  1. 安装NppPython 插件(可以使用 Notepad++ 插件管理器完成)
  2. 使用菜单 Plugins -> Python Script -> New script 创建这个 python 脚本:

    if editor.getSelectionStart() == editor.getSelectionEnd():
        editor.lineCut()
    else:
        editor.cut()
    
  3. 重启记事本++(重要)

  4. 转到菜单设置 -> 快捷方式映射器 -> 插件命令

  5. 在列表中找到刚刚创建的脚本,并为其设置 CTRL+X 快捷方式

  6. 享受!

于 2011-10-03T03:50:37.010 回答
2

转到设置->快捷方式映射器,然后单击顶部的“闪烁命令”选项卡。在那里,您应该能够将Ctrl+L命令更改为Ctrl + X

于 2009-03-06T17:55:51.307 回答
1

您可以使用 Python Script Notepad++ 插件添加脚本,并将Ctrl+分配C给脚本(从快捷方式映射器、Scintilla 命令选项卡中的 SCI_COPY 中删除Ctrl+映射)C

脚本只是:

if editor.getSelectionStart() == editor.getSelectionEnd():
    line = editor.getCurLine()
    editor.copyText(line)
else:
    editor.copy()

显然,只需为 Ctrl-X 添加另一个类似的脚本来删除该行。

于 2010-09-05T08:27:17.520 回答
1

MackieChan的插件:notepad-visual studio line copy

仍然必须设置如下:

  1. 放入notepad++/plugin文件夹

  2. 打开记事本++(重启)

  3. 在设置 -> 快捷方式映射器

    Scintilla Commands下,删除 Ctrl + C,X 的现有关联

    Plugin commands下,找到您刚刚创建的脚本并将您的快捷方式映射到它们。

于 2014-03-06T19:53:23.683 回答
0

在https://github.com/kbilsted/NppPluginCutNCopyLine有一个插件,它是开源的,如果你有额外的需要,代码很容易修改。

于 2016-06-21T18:24:43.310 回答
-2

您可以编写一个带有全局键事件挂钩的程序,每次您制作Ctrl+时都会X检查 notepad++ 是否是运行的最重要的应用程序,抓取屏幕,检查是否选择了任何文本(通过查看屏幕截图和您的 notepad++ 颜色设置) , 并将 WM_KEYPRESS 消息发送到模拟Ctrl+的 notepad++ 窗口L(假设您使用的是 Windows)。

(但这不会将行放入剪贴板,您必须进行一些字符识别才能允许它)

于 2010-09-03T23:20:54.333 回答