Catching a PHP variable using double click in Notepad ++
Asked Answered
E

4

7

I just switched from eclipse to Notepad++ and I modified some behaviour of notepad, but there is still one not resolved : When I double-click on a variable I expect my editor to catch the entire variable. Notepad excludes automatically the php prefix "$", that is not efficient. Is there a way I can change the behaviour ?

Thank you

Embolectomy answered 23/2, 2011 at 15:10 Comment(6)
Personally, I used to write PHP in Notepad++ and find this behavior appropriate for me. Why you need to capture also $ sign?Latin
Notepad++ source code is open, you can have a dig and override that behavior ;)Fourteen
@galymzhan: That's just like, your opinion man.Mcburney
@gAMBOOKa: Sure. I just can't see the advantage of such behavior. The current behavior highlights all occurrences of a variable when you double click on them - isn't it perfect?Latin
I wouldn't call it "not efficient". In some cases it is, in others not. Both behaviours have their advantages and disadvantages. After a while you will get used to this behaviour.Emersed
@galymzhan: Why wouldn't it highlight the occurrences even when $ is part of the selection? It's really a matter of what you're used to. Personally, I prefer selecting without the $ as well. But that's no reason to believe everyone prefers the same.Mcburney
E
2

I understand your problem, but unfortunately it is not possible with Notepad++ to setup this behaviour.

What you can do is click between the dollar sign and the variable name. Then you will grab the whole variable as long as there is no special character before the dollar sign (for example [$var]).

Emersed answered 23/2, 2011 at 15:36 Comment(4)
indeed, it works. but it is not the solution that I hoped,.Thank you.Embolectomy
Yes, I know, I'm sorry. But I can't do anything about that.Emersed
@MichielPater why is this impossibility in Np++ ?Malka
this doen't work in 5.9.6.2 (unicode)... i just did the update and that behavior is broken !! be careful if you are going to updateMalka
D
20

As of version 7.3.1 (released on 17 Jan 2017) they have added a simple way of doing this. Quoting from the release notes,

An enhancement for customizing of Word characters is added in this version: While double-clicking to select or searching with "Match whole word only" option, the selected characters stop on non-word characters. With this enhancement, users can include any non-word character into word character set, in order to change its default behaviour.

To enable it, go to Settings -> Preferences -> Delimiter, choose "Add your character as part of your word", and add a dollar sign ($) in the text box. Close and it works!

Delastre answered 2/3, 2017 at 2:53 Comment(2)
you are awesome you saved my life :pThundersquall
This is the right answer. The other "selected" answer needs to be changed to this one.Backgammon
B
3

Here is how you can select the whole $php_variable / $word in Npp, including the '$' sign, with Alt + Click:

EDIT: I realize now that you can do skip the Npp macro and do it only with AutoHotKey. But I'll leave the macro anyway in case smb likes it. For more details look into the AutoHotkey.chm, in the contents tab, navigate to: Kheyboard Control >> Send/SendRaw...

Do not put spaces between the {LButton}{...} or they will be inserted into the editor (the space after the comma seems ok).

It would probably go something like this (havent tested it).

!LButton::
Send, {LButton}{CTRLDOWN}{LEFT}{CTRLUP}{LEFT}{CTRLDOWN}{SHIFTDOWN}{RIGHT}{RIGHT}{SHIFTUP}{CTRLUP}
return

END EDIT

I have finally done this with the help of

  • Autohotkey (google it).
  • npp macro

The macro:

  • before you start to record the macro: click inside a php variable so that the blinking cursor is inside it(eg: $php_varia|ble)
  • now hit record macro
  • now press: Ctrl+left, left(no ctrl), ctrl+shift+right, ctrl+shift+right; This will select the whole php variable / word, including the '$'
  • stop the macro record, then: 'Save Current Recorded Macro'. Assign to it a keyboard shortcut (I assigned Ctrl + Alt + Shift + B)

The Autohotkey script:

; alt + click translated to Click followed by Ctrl Shift Alt B
!LButton::
Send, {LButton}{CTRLDOWN}{SHIFTDOWN}{ALTDOWN}b{ALTUP}{SHIFTUP}{CTRLUP}
return

Now when you Alt + Click on a php variable in NPP it will select all of it, including the '$' sign.

I also have script for Copy / Cut / Paste by Ctrl + LMouseBtn / Ctrl + Shift + LMouseButton / Ctrl + RMouseButton:

^RButton::
Send, {CTRLDOWN}v{CTRLUP}
return

^LButton::
Send, {CTRLDOWN}c{CTRLUP}
return

^+LButton::
Send, {CTRLDOWN}x{CTRLUP}
return

; the plus sign means the Shift key, etc
; see 'Keyboard control' >> 'Hotkeys and Hotstrings' in the Autohotkey help.chm
Bequeath answered 22/3, 2011 at 15:16 Comment(0)
E
2

I understand your problem, but unfortunately it is not possible with Notepad++ to setup this behaviour.

What you can do is click between the dollar sign and the variable name. Then you will grab the whole variable as long as there is no special character before the dollar sign (for example [$var]).

Emersed answered 23/2, 2011 at 15:36 Comment(4)
indeed, it works. but it is not the solution that I hoped,.Thank you.Embolectomy
Yes, I know, I'm sorry. But I can't do anything about that.Emersed
@MichielPater why is this impossibility in Np++ ?Malka
this doen't work in 5.9.6.2 (unicode)... i just did the update and that behavior is broken !! be careful if you are going to updateMalka
S
2

I've created a macro that writes $ and then paste whatever it is in the clipboard, then assigned a shortcut to that macro ctr+alt+v.

Schnur answered 16/7, 2012 at 15:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.