How to mimic Visual Studio's CTRL-X, CTRL-V functionality in Notepad++?

落爺英雄遲暮 提交于 2019-12-03 08:24:09

问题


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.

  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




回答3:


  1. Install NppPython plugin (can be done with Notepad++ Plugin Manager)
  2. Create this python script using the menu Plugins -> Python Script -> New script:

    if editor.getSelectionStart() == editor.getSelectionEnd():
        editor.lineCut()
    else:
        editor.cut()
    
  3. Restart notepad++ (important)

  4. Go to Menu Settings -> Shortcut Mapper -> Plugin commands

  5. Find the script you just created in the list and set CTRL+X shortcut for it

  6. 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:

  1. Put it into notepad++/plugin folder

  2. open notepad++ (restart)

  3. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!