Community
    • Login

    Copy entire line without selecting it?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    14 Posts 7 Posters 19.9k 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.
    • Mikhail VM
      Mikhail V @Martin Pelletier
      last edited by

      @Martin-Pelletier
      I would also recommend PythonScript plugin.
      You’ll just need a two-line script to achieve this:

      myline = editor.getCurLine()
      editor.copyText(myline)

      That’s it. The current line (where the caret is) will be
      copied into clipboard. Then bind your favourite key to run this and done.

      Scott SumnerS Alan KilbornA 2 Replies Last reply Reply Quote 2
      • Claudia FrankC
        Claudia Frank @Martin Pelletier
        last edited by

        @Martin-Pelletier

        didn’t check when it has been added but the most recent versions do have it and
        it is mapped to CTRL+SHIFT+X in default configuration.

        Check shortcut mapper, scintilla commands - the message you are looking for is
        SCI_LINECOPY (row 92 for me).

        Cheers
        Claudia

        Scott SumnerS 1 Reply Last reply Reply Quote 1
        • Scott SumnerS
          Scott Sumner @Claudia Frank
          last edited by

          @Claudia-Frank

          I think a key point is that people expect this functionality on ctrl+c (or ctrl+x for “cut current line if no selection”)…they don’t want to have to remember a separate key combo for these special cases of copy/cut. Even when accepting of a separate keycombo, the default of ctrl+shift+x is horrible for the ‘copy’ variant, IMO.

          1 Reply Last reply Reply Quote 0
          • Scott SumnerS
            Scott Sumner @Mikhail V
            last edited by

            @Mikhail-V

            Your Pythonscript also requires a separate keycombo for the functionality versus the normal copy function. Something like the following short script, mapped to ctrl+c (remove the default Scintilla ctrl+c assignment!), might be better as the user gets normal copy-selection capability plus (unselected) current line copy capability…without having to think about what they are doing (just hit ctrl+c!):

            if len(editor.getSelText()) > 0:
                editor.copy()
            else:
                editor.copyText(editor.getCurLine())
            
            1 Reply Last reply Reply Quote 4
            • V S RawatV
              V S Rawat
              last edited by

              CTRL+SHIFT+X copies the current line without having to select it.

              You can find it in shortcut mapper - scintilla commands tab - SCI_LINECOPY

              1 Reply Last reply Reply Quote 0
              • V S RawatV
                V S Rawat
                last edited by

                My similar question is "How to Delete entire current line (appearing multiline with word-wrap on) without selecting it first?

                Claudia FrankC 1 Reply Last reply Reply Quote 0
                • Claudia FrankC
                  Claudia Frank @V S Rawat
                  last edited by

                  @V-S-Rawat

                  CTRL+SHIFT+L (row 90 - standard configuration)

                  Cheers
                  Claudia

                  1 Reply Last reply Reply Quote 0
                  • Alan KilbornA
                    Alan Kilborn @Mikhail V
                    last edited by

                    @Mikhail-V
                    @ScottSumner

                    Why is the script any more complicated than this one line?
                    editor.copyAllowLine()
                    Replace the default Control-C mapped command with a pointer to that Pythonscript and that is all it takes. Unless I’m missing a key point…

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

                      With 5 “likes” I guess I didn’t miss the point!

                      1 Reply Last reply Reply Quote 1
                      • dailD
                        dail
                        last edited by

                        I’ve always liked the cutting/copying of entire lines like Visual Studio has (I’m sure many other editors/IDEs have it as well). There are at least 2 plugins available through the PluginManager that adds this functionality to N++. Myself, I’ve been using the following LuaScript for quite a while. I’m sure this logic could be easily adapted to be used in PythonScript as well:

                        -- Mimic Visual Studio's "Ctrl+C" that copies the entire line if nothing is selected
                        npp.AddShortcut("Copy Allow Line", "Ctrl+C", function()
                            editor:CopyAllowLine()
                        end)
                        
                        -- Mimic Visual Studio's "Ctrl+X" that cuts the line if nothing is selected
                        npp.AddShortcut("Cut Allow Line", "Ctrl+X", function()
                            if editor.SelectionEmpty then
                                editor:CopyAllowLine()
                                editor:LineDelete()
                            else
                                editor:Cut()
                            end
                        end)
                        
                        Scott SumnerS 1 Reply Last reply Reply Quote 4
                        • Scott SumnerS
                          Scott Sumner @dail
                          last edited by

                          @dail

                          Yes. Since the PythonScript “copy” case has already been beaten to death in this thread, but the PS “cut” case maybe hasn’t been, here’s the port of your LuaScript for that:

                          if editor.getSelectionEmpty():
                              editor.copyAllowLine()
                              editor.lineDelete()
                          else:
                              editor.cut()
                          

                          A fairly direct port! :-D

                          Unfortunately, in PS shortcut-mapping isn’t as easy to do as it is in LS.

                          1 Reply Last reply Reply Quote 5
                          • Alan KilbornA Alan Kilborn referenced this topic on
                          • Alan KilbornA
                            Alan Kilborn
                            last edited by

                            I updated a script method for doing this HERE.

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