Full line selection and keyboard shortcut
-
Hello,
It would be nice to be able to put the cursor on a line, and without selecting anything, press Ctrl + C and be able to copy the whole line.Would it be possible to add the option?
I would also like to know how to add to the keyboard shortcut, the option to select all, I can not find it in the list.
Best regards.
-
@socu said in Full line selection and keyboard shortcut:
press Ctrl + C and be able to copy the whole line
There a plugin for this although all I can do is point you to it, I can’t recommend it as I don’t use it (I favor a PythonScript solution):
@socu said in Full line selection and keyboard shortcut:
how to add to the keyboard shortcut, the option to select all, I can not find it in the list.
Are you talking about Ctrl+a ?? Not hard to find in the list:
-
More info on the “press Ctrl + C and be able to copy the whole line” part of the OP’s question can be found HERE.
-
I dusted off my PythonScript for doing this, and will show it here as
CopySelectionOrCopyCaretLine.py
. This version does the desired functionality but it also has a twist: It flashing what is being copied to the clipboard (for the standard cases), so the user has some visual confirmation that the hotkey for it was actually pressed. Recommend tying the script to Ctrl+c or Ctrl+Insert if you like it.# -*- coding: utf-8 -*- from __future__ import print_function from Npp import * import inspect import os import time #------------------------------------------------------------------------------- class CoSOCCL(object): def __init__(self): self.this_script_name = inspect.getframeinfo(inspect.currentframe()).filename.split(os.sep)[-1].rsplit('.', 1)[0] if editor.getSelections() > 1: # multiple selections are active if editor.getSelectionEmpty(): self.mb('Multiple empty selections specified -- nothing to copy!') else: # simply copy the multi-selected data to the clipboard editor.copy() return if not editor.getSelectionEmpty(): # a single text selection of non-zero length exists; simply copy it to the clipboard editor.copy() self.selected_text_flash() # provide visual confirmation of what is being copied return # no selected text and only one caret active; copy the contents of the entire line the caret is on to the clipboard current_position = editor.getCurrentPos() current_line_number = editor.lineFromPosition(current_position) start_of_curr_line_pos = editor.positionFromLine(current_line_number) editor.setSel(start_of_curr_line_pos, start_of_curr_line_pos + len(editor.getLine(current_line_number))) editor.copy() self.selected_text_flash() # provide visual confirmation of what is being copied editor.setEmptySelection(current_position) def selected_text_flash(self, times_to_flash=3, delay_betw_flashes=0.05): # see part of this thread: https://sourceforge.net/p/npppythonscript/discussion/1188886/thread/b882571d/?page=0 for j in range(times_to_flash): time.sleep(delay_betw_flashes) editor.hideSelection(True) if j != times_to_flash - 1: time.sleep(delay_betw_flashes) editor.hideSelection(False) def mb(self, msg, flags=0, title=''): # a message-box function return notepad.messageBox(msg, title if title else self.this_script_name, flags) #------------------------------------------------------------------------------- if __name__ == '__main__': CoSOCCL()
-
@socu said in Full line selection and keyboard shortcut:
It would be nice to be able to put the cursor on a line, and without selecting anything, press Ctrl + C and be able to copy the whole line.
Unless I’m misunderstanding, this is build-in to Scintilla and thus Notepad++. It’s called
SCI_LINECOPY
and by default, theSHIFT+CTRL+X
is associated with it as a shortcut:Settings => Shortcut Mapper…
Cheers.
-
@michael-vincent said in Full line selection and keyboard shortcut:
Unless I’m misunderstanding, this is build-in to Scintilla and thus Notepad++. It’s called SCI_LINECOPY and by default, the SHIFT+CTRL+X
Yes, but a key point about that is that it is a different keycombo to what one is used to for copying. Nobody wants that: To have to think about it in the heat of coding battle: “Let’s see, I want to copy, which keycombo is that again…?”
As to simpler methods than my script above, one could see my comment HERE where I said “Why is the script any more complicated than this one line?”
The answer to that is: more features. I like my little flash effect from the longer script I posted above. And…all copy functionality is on one keycombo. :-)
-
Hello, Thank you very much to all, and sorry for not responding earlier, I have not received mail notification of new responses.
As some options are in English, it is difficult for me to understand some things, and believe it or not it is the first time I use it, I have heard very well of Notepad, but it has been for programming issues, in my case I use it as a notepad,
I have tried a little the HTML theme, I will ask a question outside of this post as they are different topics.Thanks for the screenshots, I can see where those options are, now I am trying to test the CopySelectionOrCopyCaretLine.py script, but I am not linking the script well.
P.S. sorry, if the text is not understood, I am using a translator.
Best regards.
-
So I think you are doing the correct PythonScript setup, from what you’ve shown, with an end goal of tying execution of the script to a keycombo.
The next thing to do is to go into the Shortcut Mapper and find the command on the Plugins tab, and actually link it to a keycombination.
If you are going to assign it to an existing keycombo, you will need to delete the originally assigned function.
-
I got it, it is what I was looking for, it has cost me a little, because the translation that makes Google is not very clear.
The problem I had is that the script was displayed, or I have not seen it the first time.
By the way, since I’m new here, and also in Notepad, I’m going to make a request to those of you who have more strength here in the forum, if you can communicate that it would be nice that the listings that appears in the “keyboard shortcuts”, could have an option to sort them, everything would be easier to find.
Thank you very much.
-
@socu said in Full line selection and keyboard shortcut:
it would be nice that the listings that appears in the “keyboard shortcuts”, could have an option to sort them, everything would be easier to find.
I don’t think that is necessarily true, as sometimes to know what the shortcuts are referring to, you need to see the entries around them.
The current ordering pretty much follows the ordering in the main menu, left-to-right, top to bottom. This is shown in the Category column in the Shortcut Mapper.
-
Hello, anyone has any problem with the CopySelectionOrCopyCaretLine.py ?
I think it happens to me since this last update of Notepad, I noticed that, when copying no longer did that flashing, I went to check if the keyboard was unconfigured, and I realized that the line is marked in color, that seems that there is some conflict, I have always had that key combination set.
As you can see in that screenshot, it is not the only one showing conflicts, how can I fix this problem to continue using this plugin ?
Edited:
Ok, that’s it, sorry for asking, I don’t know why the default Copy option was activated with the same combination, you can see that with each update you have to reconfigure everything that has been changed, I think this would not have to be changing with each update.Thank you.
-
@SoCu said in Full line selection and keyboard shortcut:
you can see that with each update you have to reconfigure everything that has been changed, I think this would not have to be changing with each update.
No, that’s not true.
However, if the author of Notepad++ “adjusts” keycombos for a new release (there’s been some mumbo jumbo with Ctrl+c lately), then you might have to.