NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
Moving lines UP/DOWN shortcut.


Joined: 06 Mar 2011
Posts: 14
Reply with quote
Is there shortcut for moving lines UP/DOWN?

for example, eclipse shortcuts:
Alt + UP_arrow
Alt + DOWN_arrow
View user's profileFind all posts by warobushekSend private message
updown lines


Joined: 06 Mar 2011
Posts: 14
Reply with quote
that would be greate if I could write integration script for this.
I've tried example scripts there http://www.nusphere.com/kb/technicalfaq/tip_some_useful_scripts.htm.

But how can I get current position of cursor in my integration script?
View user's profileFind all posts by warobushekSend private message
Guru master

Joined: 24 Jul 2009
Posts: 737
Reply with quote
From what I've seen, it appears integration scripts work on buffers, which would normally be a copy of selected text. Therefore there is not a cursor position to work with. All the script can do is change and return the selected text and then PhpED will swap the old text with new.

If you do not select any text, an empty buffer is passed to your script, you can put text in it and then PhpED will insert that text at the cursor position.
View user's profileFind all posts by plugnplaySend private message
Guru master

Joined: 24 Jul 2009
Posts: 737
Reply with quote
Moving lines up and down in PhpED can be done with AutoHotKey (www dot autohotkey dot com)

This script will do it:
Code:
; Move line down using Alt+Down
!Down::SendInput {Home}{Home}+{Down}^X{Down}^V{Up}

; Move line up using Alt+Up
!Up::SendInput {Home}{Home}+{Down}^X{Up}^V{Up}

This script could do with being made a bit more robust (such as ensuring you are at least in PhpED), but it works fine and the script might also be valid for other applications.

I'm fairly sure that AutoHotKey can even check if you are in a PhpED editing window. If people ask about that, then I will have a look. Smile

Bear in mind that PhpED defines Alt+Up and Alt+Down to move between editing windows, but AutoHotKey will over-ride that. You can use ^Down and ^Up to specify control key instead of Alt key.
View user's profileFind all posts by plugnplaySend private message


Joined: 08 Oct 2007
Posts: 32
Reply with quote
The previous script wasn't work for me in phped, so I took 2h to learn script and wrote another wich work only in phped and preserves clipboard.

The key control are Crtl + Shit + Arrow Up, Crtl + Shit + Arrow Down.

Here it is :

Code:
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

; Move line down using Ctrl+Shift+Down
^+DOWN::
IfWinActive, PhpED
{
   clip = %Clipboard%
   Send, {HOME}{SHIFTDOWN}{DOWN}{SHIFTUP}{CTRLDOWN}x{CTRLUP}{DOWN}{CTRLDOWN}v{CTRLUP}{UP}
   Sleep, 50
   Clipboard = %clip%
   return
}

; Move line up using Ctrl+Shift+Up
^+UP::
IfWinActive, PhpED
{
   clip = %Clipboard%
   Send, {HOME}{SHIFTDOWN}{DOWN}{SHIFTUP}{CTRLDOWN}x{CTRLUP}{UP}{CTRLDOWN}v{CTRLUP}{UP}
   Sleep, 50
   Clipboard = %clip%
   return
}


You have to :
- install autoHotKey (Thanks to plugnplay introducing me to this excellent automation software Wink )
- save the code in a file named phpEdLineMover.ahk
- double click on it

Hope it will be usefull to some peoples
Smile

Ps: I asked this feature in "feature request" for a looong time, maybe if you post your interrest in this post
http://forum.nusphere.com/move-a-line-up-and-down-between-others-t7351.html nusphere will implement it.
View user's profileFind all posts by xaffSend private message
up\down


Joined: 06 Mar 2011
Posts: 14
Reply with quote
Thanks xaff and plugnplay.

It will be much better, if developers of phpEd implement this feature.
Because even last script is quite buggy.
View user's profileFind all posts by warobushekSend private message


Joined: 08 Oct 2007
Posts: 32
Reply with quote
I don't know how to improve script to workaround the buggy case because I need to go on the start of a line, but the home touch is a switch in phpEd (start of line / start of first word), so I dont know if I'm at start or not....

Anyway here is a new version with key redirection for others programs (ex : notepad++) and phped launching (you have to change the path if needed).

Code:
#SingleInstance force

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

Run, "C:\Program Files\nusphere\phped\phped.exe"

; Move line down using Ctrl+Shift+Down
^+DOWN::
IfWinActive, PhpED
{
   clip = %Clipboard%
   Send, {HOME}{SHIFTDOWN}{DOWN}{SHIFTUP}{CTRLDOWN}x{CTRLUP}{DOWN}{CTRLDOWN}v{CTRLUP}{UP}
   Sleep, 50
   Clipboard = %clip%
   return
}else{
   Send, {CTRLDOWN}{SHIFTDOWN}{DOWN}{SHIFTUP}{CTRLUP}
   return
}

; Move line up using Ctrl+Shift+Up
^+UP::
IfWinActive, PhpED
{
   clip = %Clipboard%
   Send, {HOME}{SHIFTDOWN}{DOWN}{SHIFTUP}{CTRLDOWN}x{CTRLUP}{UP}{CTRLDOWN}v{CTRLUP}{UP}
   Sleep, 50
   Clipboard = %clip%
   return
}else{
   Send, {CTRLDOWN}{SHIFTDOWN}{UP}{SHIFTUP}{CTRLUP}
   return
}
View user's profileFind all posts by xaffSend private message


Joined: 08 Oct 2007
Posts: 32
Reply with quote
Another update less buggy than two before (found a "way" for where the cursor is)
It still move only one line (because I can't know if lines are over lined)
Hope one day it will be native, because it's so usefull to organise code or just move a comment.

Code:

;
; AutoHotkey Version: 1.x
; Language:       English
; Platform:       Win9x/NT
; Author:         A.N.Other <myemail@nowhere.com>
;
; Script Function:
;   Template script (you can customize this template by editing "ShellNew\Template.ahk" in your Windows folder)
;

#SingleInstance force

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

Run, "C:\Program Files\NuSphere\PhpED\phped.exe"

; Move line down using Ctrl+Shift+Down
^+DOWN::
IfWinActive, PhpED
{
   clip = %Clipboard%
   Send, {DOWN}{END}{HOME}{HOME}{UP}{SHIFTDOWN}{DOWN}{SHIFTUP}{CTRLDOWN}x{CTRLUP}{DOWN}{CTRLDOWN}v{CTRLUP}{UP}{HOME}
   Sleep, 50
   Clipboard = %clip%
   return
}else{
   Send, {CTRLDOWN}{SHIFTDOWN}{DOWN}{SHIFTUP}{CTRLUP}
   return
}

; Move line up using Ctrl+Shift+Up
^+UP::
IfWinActive, PhpED
{
   clip = %Clipboard%
   Send, {UP}{END}{HOME}{HOME}{DOWN}{SHIFTDOWN}{DOWN}{SHIFTUP}{CTRLDOWN}x{CTRLUP}{UP}{CTRLDOWN}v{CTRLUP}{UP}{HOME}
   Sleep, 50
   Clipboard = %clip%
   return
}else{
   Send, {CTRLDOWN}{SHIFTDOWN}{UP}{SHIFTUP}{CTRLUP}
   return
}

View user's profileFind all posts by xaffSend private message


Joined: 30 Jun 2009
Posts: 79
Reply with quote
Here is my feature request. Can you guys +1 it, maybe Dmitri will hear our cry:

http://forum.nusphere.com/text-editing-moving-lines-or-highlighted-blocks-up-d-t8895.html
View user's profileFind all posts by temuriSend private message
Moving lines UP/DOWN shortcut.
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic