Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Full line selection and keyboard shortcut

    General Discussion
    3
    10
    2430
    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.
    • SoCu
      SoCu last edited by

      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.

      Alan Kilborn Michael Vincent 2 Replies Last reply Reply Quote 0
      • Alan Kilborn
        Alan Kilborn @SoCu last edited by Alan Kilborn

        @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
        • Alan Kilborn
          Alan Kilborn last edited by

          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
          • Alan Kilborn
            Alan Kilborn last edited by

            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
            • Michael Vincent
              Michael Vincent @SoCu last edited by

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

              Alan Kilborn 1 Reply Last reply Reply Quote 6
              • Alan Kilborn
                Alan Kilborn @Michael Vincent last edited by Alan Kilborn

                @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
                • SoCu
                  SoCu last edited by

                  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.

                  Alan Kilborn 1 Reply Last reply Reply Quote 1
                  • Alan Kilborn
                    Alan Kilborn @SoCu last edited by

                    @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
                    • SoCu
                      SoCu last edited by

                      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.

                      Alan Kilborn 1 Reply Last reply Reply Quote 0
                      • Alan Kilborn
                        Alan Kilborn @SoCu last edited by

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

                        1 Reply Last reply Reply Quote 1
                        • First post
                          Last post
                        Copyright © 2014 NodeBB Forums | Contributors