• Login
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.
  • C
    CennoxX
    last edited by May 13, 2022, 7:36 AM

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

    T A 2 Replies Last reply May 13, 2022, 7:43 AM Reply Quote 0
    • T
      Terry R @CennoxX
      last edited by May 13, 2022, 7:43 AM

      @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

      C 1 Reply Last reply May 13, 2022, 8:25 AM Reply Quote 0
      • C
        CennoxX @Terry R
        last edited by May 13, 2022, 8:25 AM

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

        P 1 Reply Last reply May 13, 2022, 10:53 PM Reply Quote 0
        • P
          PeterJones @CennoxX
          last edited by PeterJones May 13, 2022, 10:54 PM May 13, 2022, 10:53 PM

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

          C 1 Reply Last reply May 17, 2022, 9:34 AM Reply Quote 1
          • C
            CennoxX @PeterJones
            last edited by May 17, 2022, 9:34 AM

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

            C 1 Reply Last reply May 17, 2022, 10:57 AM Reply Quote 0
            • C
              CennoxX @CennoxX
              last edited by May 17, 2022, 10:57 AM

              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
              • A
                Asger Jørgensen 0 @CennoxX
                last edited by May 19, 2022, 8:38 AM

                @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
                6 out of 7
                • First post
                  6/7
                  Last post
                The Community of users of the Notepad++ text editor.
                Powered by NodeBB | Contributors