问题
I'm using Notepad++ for some projects and miss Visual Studio's Ctrl + X, Ctrl + C functionality that cuts or copies the entire current line when no text is selected. The cut line shortcut seems to be Ctrl + L, which is not as convenient as Ctrl + X and the copy shortcut seems to be Ctrl + D, Ctrl + L, which is even less convenient.
Although a similar question has been asked before, the way to do this in Notepad++ was not provided and I cannot find a solution on the Notepad++ site or on its forums.
回答1:
I've created a Notepad++ plugin that does this (without the need of python). It can be found at https://bitbucket.org/zastrowm/notepad-visualstudiolinecopy.
回答2:
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
copyAllowLine.py
editor.copyAllowLine()
cutAllowLine.py
if editor.getSelectionStart() == editor.getSelectionEnd(): editor.lineCut() else: editor.cut()
Python Script -> Configuration
- under User Scripts, add a menu item for each script.
- under User Scripts, add a menu item for each script.
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
回答3:
- Install NppPython plugin (can be done with Notepad++ Plugin Manager)
Create this python script using the menu Plugins -> Python Script -> New script:
if editor.getSelectionStart() == editor.getSelectionEnd(): editor.lineCut() else: editor.cut()
Restart notepad++ (important)
Go to Menu Settings -> Shortcut Mapper -> Plugin commands
Find the script you just created in the list and set CTRL+X shortcut for it
Enjoy!
回答4:
Go to Settings->Shortcut Mapper and click on the "Scintilla commands" tab at the top. Under there you should be able to change the Ctrl + L command to Ctrl + X.
回答5:
You can add a script with the Python Script Notepad++ plugin, and assign Ctrl + C to the script (remove the Ctrl + C mapping from SCI_COPY in shortcut mapper, Scintilla Commands tab)
The script is just:
if editor.getSelectionStart() == editor.getSelectionEnd():
line = editor.getCurLine()
editor.copyText(line)
else:
editor.copy()
Obviously just add another similar script for Ctrl-X that removes the line instead.
回答6:
The plugin from MackieChan: notepad-visual studio line copy
has to be still setup-ed as follow:
Put it into notepad++/plugin folder
open notepad++ (restart)
in Settings -> Shortcut Mapper
under Scintilla Commands, remove the existing associations for Ctrl + C,X
under Plugin commands, find the scripts you just created and map your shortcuts to them.
回答7:
There is a plugin for it at https://github.com/kbilsted/NppPluginCutNCopyLine its open source and the code is easy to modify if you have extra needs.
回答8:
you can write a program with a global key event hook, which every time you make a Ctrl + X checks if notepad++ is the foremost application running, grabs the screen, checks if any text is selected (by looking at the screenshot and your notepad++ color settings), and sends a WM_KEYPRESS message to the notepad++ window simulating a Ctrl + L (assuming you're using windows).
(this won't put the line into the clipboard though, you'll have to make some character recognition to allow it)
来源:https://stackoverflow.com/questions/619754/how-to-mimic-visual-studios-ctrl-x-ctrl-v-functionality-in-notepad