6

I think I have accidentally overridden one of the default settings in the NetBeans editor (7.2 on Windows 7) and a beautiful feature is gone.

Bracket completion feature is now effected.

I am new to NetBeans. When I used to type

echo "

NetBeans used to place the matching " and put the cursor right after the first quote

echo "|"`   // here the `|` denotes the cursor

So when I see the cursor there, I just type... And when I am done typing, I used to be able simply to hit enter (while the cursor is still inside the closing quote) and NetBeans used to automatically put the semi-column at the end of the line (after the closing quote) and advance me to the next line - very nicely. But now, the enter totally creates a new line, pushing the closing quote also to the next line. And obviously, no more semi-column.

So I end up getting this now

echo "test  
 "

The enter used to give me this instead;

echo "test";

I wonder what went wrong and where. Now I have to hit right arrow to get to the right side of the closing quote and place a semi-column manually and then hit enter.

How do you bring back default settings? What do you do in situations like this?

Running Windows 7 and NetBeans 7.2.1

wittich
  • 2,079
  • 2
  • 27
  • 50
Average Joe
  • 4,521
  • 9
  • 53
  • 81
  • It's been a while since I worked with Netbeans, but it just never clicked for me. If you haven't tried these yet, take a look at [PHP Development Tools](http://www.eclipse.org/projects/project.php?id=tools.pdt) and [Aptana Studio 3](http://www.aptana.com/); I use Aptana mostly. There's also non-freebies: Dreamweaver, PHP Storm, and Zend STudio (I hear it's great but pricey). If you need WebDAV, btw, DW is the only option. – Jared Farrish Dec 30 '12 at 07:50
  • it's not clicking with me neither. my next test would be on sublime text 2. what do you like the most about aptana? – Average Joe Dec 30 '12 at 07:56
  • Take a look at this (mildly outdated) [Smashing Magazine article](http://coding.smashingmagazine.com/2009/02/11/the-big-php-ides-test-why-use-oneand-which-to-choose/) on PHP IDE comparisons. What do I like about Aptana? Uhh. It's free. it's frustrated me less than the other choices...? I can't afford to buy DW (which I use at work and happen to like). I've heard Sublime is good, and I've had the pleasure to use gEdit on Ubuntu. Eclipse (Aptana is Eclipse with PHP plugins pre-packaged with it) is wonky too. My complaints with Netbeans are that it's slow to load and process updates. – Jared Farrish Dec 30 '12 at 08:03

1 Answers1

5

General answer to your question

The settings are stored in XML files in your user directory:

Example

${userdir}/config/Editors/text/{PROGRAMMING_LANGUAGE_HERE}/Preferences/org-netbeans-modules-editor-settings-CustomPreferences.xml. 

If you delete this file the language settings (including formatting) will be set to default.

I'm not totally sure that feature is in the language setting, but just check the config directory and delete files until that feature is back!

You can also delete specific parts of the XML file to reset only some settings.


Alternative to your specific problem (Alternative 1)

After the discussion in the comments and some search, I found this link as an alternative to your specific request. I'll still leave the original answer there since it answers the question in the title (and to help with future people who use the search function).

Netbeans Tip: Adding a semicolon to the end of a line for PHP

When writing Java in Netbeans there is a handy shortcut that places a semi-colon (;) at the end of the line, simply by pressing ctrl+;. That doesn’t sound like a big deal, but it seems I often write a piece of code yet somehow not have a semi-colon at the end. I think it’s to do with the code complete (eg. The IDE never quite lets me get to the end of the line before I finish writing the code I want to write – it’s a good thing really). However, this feature isn’t available when writing PHP.

Proof of how handy I actually find this shortcut is that I’m now forever trying to do it in Netbeans when writing PHP, only to be left disappointed.

How to do it in Netbeans for PHP

However, there’s a quick way to create this functionality in Netbeans (and any editor that provides macros support):

In Netbeans, click somewhere in the text editor.

  1. Select Edit > Start Macro

  2. Now whilst in the editor, press the ‘end’ key followed by the ‘;’ key. You should now have a semicolon at the end of your line.

  3. Select Edit > Stop Macro

  4. Give your macro a name (eg. “Append ;”)

Click ‘Set Shortcut’

Press “ctrl+;” and click OK

You’re done!


Alternative to your specific problem (Alternative 2)

Also, in Options -> Editor -> Code Templates, you have a bunch of templates, including a eco shortcut which does EXACTLY what you want (double quotes, ;, etc..)! For some reason, those templates won't work for me with the default setting "Expand Template On TAB", but if I change it to CTRL+SPACE, it works perfectly!

Community
  • 1
  • 1
mbinette
  • 5,094
  • 3
  • 24
  • 32
  • thank you. I found that file as `...editors > text > x-php5 ...` . I deleted it but that did not help. Could you check yours to see if you type `echo "test` and then hit enter. what do you get? – Average Joe Dec 30 '12 at 07:19
  • Actually, I hadn't used Netbeans for a while, but just did a clean install and I can tell you the default behavior is just like you described: It puts the second quote and brings the cursor after the first one. When you press ENTER, it does not put the `;` tho, and does exactly what you described. It's the same for function calls. However, I seem to remember something similar to what you described as the behavior you want. I'm still trying to find out when it happens... – mbinette Dec 30 '12 at 08:04
  • 1
    Just found it. Actually, what looks most like what you described is when you're autocompleting a function (try `str_replace`). It'll write down the signature and you can fill in the different parameters using `TAB`. When you're done, you can press `ENTER` and it goes after the last parenthese. You still have to add the `;` manually. Maybe it was with another editor? – mbinette Dec 30 '12 at 08:10
  • Their web site describes it though! http://netbeans.org/kb/docs/php/editorguide.html#BracketCompletion where it says this Paired single ' ' and double quotes "" "", braces (), and brackets [] are added when the user has typed the first symbol. At the end of a line, a semicolon is added in addition to the closing single or double quote. -- to tell you the truth, I'm not too sure now neither whether it ever did it. For some reason my memory tells me it did though. For sure, it wasn't another editor. even their `eco[tab]` don't work. – Average Joe Dec 30 '12 at 08:21
  • I can definitely see that... Maybe they took that out in recent versions and did not update the documentation. As I said earlier, I haven't been doing much PHP development lately and I'm using other IDEs for other languages. I had intended on switching over to Netbeans for most of them, but haven't done so yet. Anyway, I found something that might interest you - it's not exactly what you want but still - check out my updated post. – mbinette Dec 30 '12 at 08:31
  • Also, in Options -> Editor -> Code Templates, you have a bunch of templates, including the `eco` shortcut which does EXACTLY what you want (double quotes, `;`, etc..)! It doesn't work for me either with the default setting "Expand Template On `TAB`", but if I change it to `CTRL+SPACE`, it works perfectly! (So at least you can use that) – mbinette Dec 30 '12 at 08:39
  • it's like jack in the box. tab does not work but ctrl space does! I'm familiar with eco[tab] which is why I brought it up in my earlier comment. But even that does not work mbinette. yes it does put the ''; or ""; but when you hit enter, the closing delimiter also is sent to the next line. – Average Joe Dec 30 '12 at 08:42
  • I noticed you were familiar with it after I left my comment. I first thought you were talking about array completion (my bad - it's late!). I'm still looking to see if I can find a config file that would allow me to put back the `;` after the end of the line, but I don't think I'll find it.. – mbinette Dec 30 '12 at 08:44
  • I will accept your answer even though that's not what I was after. I posted the issue in the netbeans forum, let's wait and see... http://forums.netbeans.org/viewtopic.php?p=140766#140766 Thanks anyway! – Average Joe Dec 30 '12 at 08:48