我在某些项目中使用 Notepad++ 并且错过了 Visual Studio 的Ctrl+ X、Ctrl+C功能,该功能会在未选择文本时剪切或复制整个当前行。剪切线快捷键好像是Ctrl+ L,不如Ctrl+方便X,复制快捷键好像是Ctrl+ D, Ctrl+ L,更不方便。
虽然之前已经问过类似的问题,但没有提供在 Notepad++ 中执行此操作的方法,我在 Notepad++ 网站或其论坛上找不到解决方案。
我在某些项目中使用 Notepad++ 并且错过了 Visual Studio 的Ctrl+ X、Ctrl+C功能,该功能会在未选择文本时剪切或复制整个当前行。剪切线快捷键好像是Ctrl+ L,不如Ctrl+方便X,复制快捷键好像是Ctrl+ D, Ctrl+ L,更不方便。
虽然之前已经问过类似的问题,但没有提供在 Notepad++ 中执行此操作的方法,我在 Notepad++ 网站或其论坛上找不到解决方案。
我创建了一个 Notepad++ 插件(不需要 python)。它可以在https://bitbucket.org/zastrowm/notepad-visualstudiolinecopy找到。
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.
Install Python Script plugin(can be done with Notepad++ Plugin Manager)
Create the following two python scripts using the menu Plugins -> Python Script -> New script
editor.copyAllowLine()
if editor.getSelectionStart() == editor.getSelectionEnd():
editor.lineCut()
else:
editor.cut()
Python Script -> Configuration
Restart notepad++ (important)
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
使用菜单 Plugins -> Python Script -> New script 创建这个 python 脚本:
if editor.getSelectionStart() == editor.getSelectionEnd():
editor.lineCut()
else:
editor.cut()
重启记事本++(重要)
转到菜单设置 -> 快捷方式映射器 -> 插件命令
在列表中找到刚刚创建的脚本,并为其设置 CTRL+X 快捷方式
享受!
转到设置->快捷方式映射器,然后单击顶部的“闪烁命令”选项卡。在那里,您应该能够将Ctrl+L命令更改为Ctrl + X。
您可以使用 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 添加另一个类似的脚本来删除该行。
MackieChan的插件:notepad-visual studio line copy
仍然必须设置如下:
放入notepad++/plugin文件夹
打开记事本++(重启)
在设置 -> 快捷方式映射器
在Scintilla Commands下,删除 Ctrl + C,X 的现有关联
在Plugin commands下,找到您刚刚创建的脚本并将您的快捷方式映射到它们。
在https://github.com/kbilsted/NppPluginCutNCopyLine有一个插件,它是开源的,如果你有额外的需要,代码很容易修改。
您可以编写一个带有全局键事件挂钩的程序,每次您制作Ctrl+时都会X检查 notepad++ 是否是运行的最重要的应用程序,抓取屏幕,检查是否选择了任何文本(通过查看屏幕截图和您的 notepad++ 颜色设置) , 并将 WM_KEYPRESS 消息发送到模拟Ctrl+的 notepad++ 窗口L(假设您使用的是 Windows)。
(但这不会将行放入剪贴板,您必须进行一些字符识别才能允许它)