Community
    • Login

    Move selection horizontally

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    7 Posts 4 Posters 2.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.
    • CennoxXC
      CennoxX
      last edited by

      Hi,
      is there an existing shortcut/Macro/LuaScript for moving a selection horizontally?
      I excessively use [ctrl]+[shift]+[up] and +[down] to move whole lines, now I search for an option to move a selection left and right, like VS Code and Atom do (https://github.com/microsoft/vscode/issues/5251).

      Terry RT Asger Jørgensen 0A 2 Replies Last reply Reply Quote 0
      • Terry RT
        Terry R @CennoxX
        last edited by

        @cennoxx said in Move selection horizontally:

        is there an existing shortcut/Macro/LuaScript for moving a selection horizontally?

        Aren’t you talking about Ctrl-X and Ctrl-V, cut and paste. These are standard Windows commands, and generally work across all applications.

        Terry

        CennoxXC 1 Reply Last reply Reply Quote 0
        • CennoxXC
          CennoxX @Terry R
          last edited by

          @terry-r No, I want to move the selection one character left (or right) at the time, without clicking three different shortcuts. The image at https://github.com/microsoft/vscode/issues/5251 shows it good.

          PeterJonesP 1 Reply Last reply Reply Quote 0
          • PeterJonesP
            PeterJones @CennoxX
            last edited by PeterJones

            @cennoxx ,

            Notepad++ has the ability to move the selected line up or down (Edit > Line Operations > Move Up/Down Current Line). But, that I know of, it doesn’t currently have any commands for “move current selected text right/left”. But I have been known to not know or remember certain features of Notepad++ (it can do a lot, and I am always surprised at things I didn’t know about it that others bring up in answers here!), so others will chime in if they know of a feature that I didn’t think of.

            Notepad++ uses a library from another developer for handling most of the low-level text editing stuff… but maybe if you followed the directions in our Feature Request FAQ, you could see if the Notepad++ developers can add that… and if not, maybe they or you could ask the library developer to add the feature, so that Notepad++ would get it in the next update of that library.

            Also, it’s possible that it could be scripted – if you were willing to install a plugin like PythonScript, you could try to write the script yourself, or you might find one of the regulars here interested enough to figure it out for you… though at least before I’d think about it in detail and see if I could come up with something, I’d want to know that you were willing to go down that path.

            CennoxXC 1 Reply Last reply Reply Quote 1
            • CennoxXC
              CennoxX @PeterJones
              last edited by

              @peterjones Thank you for the detailed reply. Since it looks like this functionality doesn’t exist yet, I’ll see if I can write a script using Scintilla commands…

              CennoxXC 1 Reply Last reply Reply Quote 0
              • CennoxXC
                CennoxX @CennoxX
                last edited by

                If anyone is interested, I made a LuaScript doing this, it’s not perfect, but for me it works for now.

                -- Move selection one character left
                npp.AddShortcut("Selection Add Each", "Alt+,", function()
                	if not(editor.SelectionEmpty) then
                		local selText = editor:GetSelText()
                		editor:BeginUndoAction()
                		editor:DeleteBack()
                		editor:CharLeft()
                		editor:AddText(selText)
                		editor:SetSel(editor.CurrentPos, editor.CurrentPos-string.len(selText))
                		editor:EndUndoAction()
                	end
                end)
                
                -- Move selection one word left
                npp.AddShortcut("Selection Add Each", "Alt+Shift+,", function()
                	if not(editor.SelectionEmpty) then
                		local selText = editor:GetSelText()
                		editor:BeginUndoAction()
                		editor:DeleteBack()
                		editor:WordLeft()
                		editor:AddText(selText)
                		editor:SetSel(editor.CurrentPos, editor.CurrentPos-string.len(selText))
                		editor:EndUndoAction()
                	end
                end)
                
                -- Move selection one character right
                npp.AddShortcut("Selection Add Each", "Alt+.", function()
                	if not(editor.SelectionEmpty) then
                		local selText = editor:GetSelText()
                		editor:BeginUndoAction()
                		editor:Clear()
                		editor:CharRight()
                		editor:AddText(selText)
                		editor:SetSel(editor.CurrentPos, editor.CurrentPos-string.len(selText))
                		editor:EndUndoAction()
                	end
                end)
                
                -- Move selection one word right
                npp.AddShortcut("Selection Add Each", "Alt+Shift+.", function()
                	if not(editor.SelectionEmpty) then
                		local selText = editor:GetSelText()
                		editor:BeginUndoAction()
                		editor:Clear()
                		editor:WordRight()
                		editor:AddText(selText)
                		editor:SetSel(editor.CurrentPos, editor.CurrentPos-string.len(selText))
                		editor:EndUndoAction()
                	end
                end)
                
                1 Reply Last reply Reply Quote 4
                • Asger Jørgensen 0A
                  Asger Jørgensen 0 @CennoxX
                  last edited by

                  @cennoxx
                  If you block select using Alt+Shift+Arrow keys, you can afterwords drag the selection using the left mouse.

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