• Login
Community
  • Login

Full line selection and keyboard shortcut

Scheduled Pinned Locked Moved General Discussion
12 Posts 3 Posters 9.8k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S
    SoCu
    last edited by Feb 6, 2022, 12:37 PM

    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.

    A M 2 Replies Last reply Feb 6, 2022, 12:47 PM Reply Quote 0
    • A
      Alan Kilborn @SoCu
      last edited by Alan Kilborn Feb 6, 2022, 12:47 PM Feb 6, 2022, 12:47 PM

      @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):

      c7885070-a5a1-402e-817b-12b55d81fb28-image.png





      @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:

      0ac9e78b-b1af-41c0-b72e-58393d430b2a-image.png

      1 Reply Last reply Reply Quote 3
      • A
        Alan Kilborn
        last edited by Feb 6, 2022, 12:50 PM

        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.

        1 Reply Last reply Reply Quote 2
        • A
          Alan Kilborn
          last edited by Feb 6, 2022, 6:39 PM

          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()
          
          1 Reply Last reply Reply Quote 4
          • M
            Michael Vincent @SoCu
            last edited by Feb 6, 2022, 7:54 PM

            @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, the SHIFT+CTRL+X is associated with it as a shortcut:

            Settings => Shortcut Mapper…

            2237df2a-ba08-4720-92eb-5075cf27eba9-image.png

            Cheers.

            A 1 Reply Last reply Feb 6, 2022, 8:16 PM Reply Quote 6
            • A
              Alan Kilborn @Michael Vincent
              last edited by Alan Kilborn Feb 6, 2022, 8:18 PM Feb 6, 2022, 8:16 PM

              @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. :-)

              1 Reply Last reply Reply Quote 4
              • S
                SoCu
                last edited by Feb 7, 2022, 2:59 PM

                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.

                alt text

                P.S. sorry, if the text is not understood, I am using a translator.

                Best regards.

                A 1 Reply Last reply Feb 7, 2022, 3:08 PM Reply Quote 1
                • A
                  Alan Kilborn @SoCu
                  last edited by Feb 7, 2022, 3:08 PM

                  @socu

                  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.

                  1 Reply Last reply Reply Quote 2
                  • S
                    SoCu
                    last edited by Feb 7, 2022, 6:38 PM

                    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.

                    alt text

                    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.

                    A 1 Reply Last reply Feb 7, 2022, 6:41 PM Reply Quote 0
                    • A
                      Alan Kilborn @SoCu
                      last edited by Feb 7, 2022, 6:41 PM

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

                      S 1 Reply Last reply Feb 10, 2024, 6:00 PM Reply Quote 1
                      • S
                        SoCu @Alan Kilborn
                        last edited by SoCu Feb 10, 2024, 6:13 PM Feb 10, 2024, 6:00 PM

                        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.

                        alt text

                        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.

                        A 1 Reply Last reply Feb 10, 2024, 7:52 PM Reply Quote 0
                        • A
                          Alan Kilborn @SoCu
                          last edited by Feb 10, 2024, 7:52 PM

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

                          1 Reply Last reply Reply Quote 2
                          • First post
                            Last post
                          The Community of users of the Notepad++ text editor.
                          Powered by NodeBB | Contributors