Catching a PHP variable using double click in Notepad ++

戏子无情 提交于 2019-12-21 12:08:26

问题


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


回答1:


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




回答2:


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!




回答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



回答4:


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.



来源:https://stackoverflow.com/questions/5092725/catching-a-php-variable-using-double-click-in-notepad

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!