PHP variables and the dollar sign

2. Help
2007-03-22
2013-03-22
  • In PHP (and a few other languages), variables always begin with a $ sign. It would be nice if the editor knew that this sign is part of the word, so that when you doubleclick the variable or hold down Ctrl and use the arrows to move through text, one word at a time, the $ is considered part of the name.

     
    • Christopher
      Christopher
      2009-03-26

      Yeah, I'm also looking for that feature. That would be very helpful.

      The problem with siranm's suggestion is: If you click between the dollar sign $ and the variable name, then sometimes notepad++ selects more than just this variable, but also brackets and text before the variable.
      For example, if you have this:

      function foo($text, $id) { }

      then it works fine with $id but not with $text.

       
    • I'd like to know that too. Is there any setting in Notepad++ that would make it select PHP variables together with the dollar sign?

       
    • CodeNexus
      CodeNexus
      2007-10-29

      I must admit I had never thought of this and I use it day to day.  Good suggestion!  :)

       
    • Yes! Please!

      That is the first thing  I noted, as a PHP developer.

      Notepad++ is a great product, and I like a lot the automatic indenting it offers, that was what made me use it (although the automatic indenting is really thought for C code, it works fine [not perfect] with PHP).

      I am thinking of writing a plugin that select the "$" when I double-click, but it may be kind of difficult, as I know very little C++... so if someone has it, or is willing to do it : ) it would be reaaaally nice.

       
      • siranm
        siranm
        2008-01-05

        Hi,

        I wanted to share that if you double-click right in between the dollar sign and the variable name, then whole thing is selected (the "$" with the variable name).

        greetings...

        An M

         
  • David
    David
    2013-03-22

    Yes, this was a requirement for me too. Easy fix is to create a macro:

    1. Make sure you have something on your clipboard.

    2. Open a blank document.

    3. Start the macro

    4. Type $ and then ctrl-c to paste whats on the clipboard. Doesn`t matter what it is.

    5. Save the macro with a shortcut.

    Now when you highlight a var, and copy, use the new shortcut. It will paste a dollar symbol and whatever is on the clipboard. Viola!!