jump to navigation

A Few Tricks in Notepad++ a PHP-developer Should Know September 1, 2012

Posted by Tournas Dimitrios in PHP.

My preferred IDE when building heavy-weight PHP applications is NetBeans . This tool is valuable when developing applications that are build on top of a Framework (like the Zend Framework) , though , NetBeans demands the .Net Framework , it isn’t portable and consumes  noticeable  resources from the computer where it is installed on .
When building light-weight applications , Notepad++ is probably the best alternative on the Windows platform . It’s not computer resource-intensive , tens of plugins can extend its functionality and most importantly , its size is lesser than 25MB (loaded with a “ton” of plugins and code-snippets) . Although  I’ve been on the “road” for a few Years with Notepad++,  at random intervals , new features and functionality immerge  , just because I had not discovered yet . This article will skip the basics , it assumes that You already know how to  copy/paste text or open a new document via the key-board . Certainly , it will not even mention how to install new plugins or how to configure basic functionality . Initially this article had the title of  “advanced  tricks and tips for Notepad++ ” , but just before publishing , its title was changed . You might already know these tips or probably You have discovered even more tricks , well done to you . Somehow , this tool gives me the impression that its functionality is infinite . Don’t hesitate to add your own tips into the comments section , so that other readers gets benefit from Your experience .

The following picture demonstrates my favorite Notepad++ set-up . Follow instructions of my previous article to configure the same “Theme” on Your machine .

My Notepad++ in Action

Shortcuts for every-day use :

  • Bookmarks : Hit Ctrl+F2 to set a bookmark on any line of code and then hit F2 to jump between bookmarks. Shift+F2 goes back a bookmark.
  • Goto : Ctrl+G lets you jump to a line number quick . Nice feature if your script has hundreds lines of code .
  • Find or Find/Replace of keywords : CTRL+H . The UI-panel of this functionality has a lot of customization (from Match-case to Regular expressions ) . The next paragraph demonstrates basic Regex functionality .
  • Toggle Full-screen :  F11 ( tabs of all open files are visible on the top ) , F12 (only current file) .
  • Go to matching brace :  Double clicking on a function’s curly-brace , highlights it’s complementary part . CTRL+B  has the same functionality .
  • Navigating  on lines , deleting lines  : “HOME” and “END” jumps the cursor to the beginning or to the end of the line respectively .  CTRL+SHIFT+DEL  deletes the whole line (first set cursor at the beginning of the line) .
  • Duplicating of a whole line : CTRL+D . Setting the cursor at the end of any line and pressing this combination ,  duplicates the current line (the new line is positioned under the current line)  .
  • Finding variables and functions :   Double-click on a variable / function-name should highlight all statements with the same name . Navigate UP/DOWN with  CTRL+F3  or  SHIFT+F3  .
  • Copy current’s file path : Edit->Copy to Clipboard->Current Full Path to Clipboard
  • Enable clickable links : Settings->Preferences->Misc->Enable clickable link
  • Moving whole code-block up/down : First highlight the code-block (via drag/drop or via SHIFT+arrow-keys) , then move the whole block (up or down) with CTRL+SHIFT+arrow-keys .

Regular expressions into Notepad++ :

This concept is a thousand-page book by itself . Its origin is from PERL , but today almost all programming languages have this kind of functionality (advanced text manipulation) . For basic “find , find-and-replace , delete” functionality the basic replace-UI is most likely more than adequate (accessed via CTRL+H) . However , advanced  matching criteria can only be achieved with Regex characters . The following table introduces some of them with practical examples . But before starting make sure that you change the Search Mode from Normal to Regular expression in the replace-UI (CTRL+H) .

The meaning of Regex in Notepad++
[ ] The square brackets can be used to match ONE of multiple characters. For instance, [abc] matches any of the characters a, b or c . Hence, gra[ae]y will match words like graey and graay, but not graaet or gry. Ranges can also be used, [a-z] is any lower case character and so on .
( ) The square brackets can be used to  — group– ONE of multiple characters . For example , The sentence “We’re so used to being the big boys .“If you write (used) in the search and xyz in the ‘Replace with’ filed, the result will be “We’re so xyz to being the big boys .
+ The plus sign matches 1 or more times . For example , Helo+s matches Heloos , Helooos , Heloooooos etc.
* The asterisk or star sign matches 0 or more times. For example, Ma*m matches Mm , Mam , Maaam etc.
\d Matches any single digit.
\s Matches white spaces including tabs and line breaks.
\< Matches the start of a word . For example, \<be  matches bedroom but does not matches cube .
\> Matches the end of a word . For example ,  be\> matches cube but does not matches bed .
\ The backslash is for escaping special characters . For example 4\*3 = 12 . See above , ass the asterisk has actually another meaning .
\s Matches : white-space , tab or line-break .
  The  dot matches any character.
$ The dollar sign matches the end of a line
 ^ Be careful with this symbol , the Caret . It’s normal use is to match the start of a line . If it’s used inside the square brackets then it exclude characters . For example [^A-Za-z]digital which will exclude all alphabetic characters (lower and upper case ) from the beginning of the word digital . The word could be 2digital , &digital , /digital …… etc ….

Running macro’s into Notepad++ :

What are macro’s ? : In simple words , “No more text editing  repetitive actions” .
Basically Notepad++ can quickly and conveniently record keys you are pressing and then repeat them (set number of times, in quick succession if necessary) . Steps are :
Hit Start Recording , Do what you need , Hit Stop Recording , Run once or multiple times or until file ends .
Note : When your macro involves moving around from line to line it is best to use keys like Home or End to be sure your cursor is really at the beginning / end of the line .

Notepad++ Encoding configuration :

If your applications are only targeted to visitors from Anglo-Saxon countries , most likely the only character encoding system you will use is the ANSI (which is the default on Notepad++) . All other countries should use encoding systems that support their alphabetical characters and punctuation marks . As a general rule , UTF-8 supports most of the needs for  a global-scale text-document exchange (besides all , on the front , websites are nothing more than HTML text-files that use a specific encoding system to express the language of their audience) .  Actually PHP doesn’t really support Unicode , but because of the way strings are saved you can actually use UTF-8 documents without problems if you save them in the proper format (encoding system) .
As a general rule :

  •  HTML code should be declared as UTF-8 (doc-type and via meta-tag
    <meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″/> )
  • Mysql  Database : “MySQL charset: UTF-8 Unicode (utf8)” and “MySQL connection collation: utf8_general_ci”.
  • Notepad++ has the “Encode UTF-8 without BOM”  configuration . Via “Encoding” tab . Read this link , Display problems caused by the UTF-8 BOM .

Viewing two files side by side in Notepad++ (Multi-view) : 

You can right-click on a tab and select “Move to Other View”  , another option is to select “Clone to Other View” if you want to have the same file open more than once and see different parts of it . You can right-click the divider line and rotate the views to be either side-by-side or top-and-bottom .
A nice setting is :  View -> Synchronise Vertical/Horizontal Scrolling , to keep the windows aligned that way if you wish .

Session Manager :

Sessions keep track of what files are opened in Notepad++ when working on a project . If the current project’s state (session) is saved before closing it , when you restore the session , all the files that you had open will be restored instantly allowing you to resume your work right where you left it off . Sessions also retain extra information like file positions and highlighter for the file .
By default , Notepad++ restores the last session that was active (before closing the editor) , though , this configuration can be changed by “Settings -> Preferences -> MISC -> Remember current session for next launch ” .
Important notice : Sessions do not backup files — This setting is activated from ” Settings -> Preferences -> Backup/Auto-Completion ” .
Storing the current session is simple as : File -> Save session and give it a name ( for later reference , a good choice would be to mirror the name of the current project ) . Restoring a session is even simpler : File -> Load session .
Session files are plain xml files with a .xml extension , but you can change that from Settings -> Preferences -> MISC -> Session file ext (look in the lower right corner) .
Yes , there is something still missing: the ability to see the contents of all session file as an Explorer-like tree view (NetBeans has this feature by default ) .

Run applications from within Notepad++ :

Notepad++ can be configured to start any external application via a custom Key-combination . For example :

  •  NetBeans could be started  by clicking ALT+SHIFT+4 :
    1) Go to Run ->Run
    2)Navigate to the location where the .exe file of the applications is located . Most likely , it’s the “Program Files” directory . If you know the location , write it directly into the input field . Caution :  If the path contains spaces (“Program Files” ) , enclose the whole path into double quotes . For example on my machine , it’s “C:\Program Files\NetBeans 7.1.2\bin\netbeans.exe”
    3)Press “save” : Set a Name and a combination of buttons . Finally , press “cancel” .
    4) Now , NetBeans will start-up , any time you press the combination of buttons (from previous step) .
  • The current script could be viewed into a browser (the source code) .
    A similar approach (as previous example) has to be followed . Just in step2 , pass some extra command-arguments . For example , open current file into the Chrome browser (display the source code)
    “C:\Documents and Settings\a\Local Settings\Application Data\Google\Chrome\Application\chrome.exe” “$(FULL_CURRENT_PATH)”
    Notice: The path and the command-argument are set into individual double-quotes and separated by a space !!!!!!
  • The current script could be run via WAMP .
    A similar approach (as the first example) has to be followed . Just in step2 ,
    pass this extra command-argument .
    “C:\Documents and Settings\a\Local Settings\Application Data\Google\Chrome\Application\chrome.exe” “localhost/testcode/$(FILE_NAME)”
    Notice : The “localhost/testcode/” denotes that the script is located in WAMP’s public folder and one directory down : “C:/wamp/www/testcode/” .
    Other command-arguments can be found on this link .


A few must-see plugins : 

  • SnippetPlus : Code snippet and Surround With plugin for Notepad++. Write snippet name and replace it with real code or select some text and surround it with something like IF , TryCatch ,Table ,Div or whatever .Will give you hint if you don’t remember the snippet name . My favorite plugin , over the last Years I have collected over 600 code-snippets . This plugin is only available from Sourceforge (can’t be done via Notepad’s Plugin-manager)  . This excellent plugin deserves a separate article .
  • SourceCookifier : This is a neat plugin that lets you jump to the definition of a function by hitting Ctrl+Shift+Enter . It also provides a nice sidebar with a breakdown of your code(functions , vars , Classes , methods  etc.) . This excellent plugin deserves a separate article .
  • NppExport : It is a true WYSIWYG exporter . It allows you not only to save your source code as a html/rtf file, but also to copy your source code in the clipboard in RTF/HTML format , so you can paste it into your word processor (MS Word, Abiword, openoffice.org Writer) to get the same visual effect . Installation can be done via Notepad’s Plugin-manager .
  • DBGP Plugin : This PHP debugger , or XDebug , speaks the DBGP protocol . This plugin allows you to alter your Notepad++ into a PHP IDE . A simple workflow is as follows :
    Web browser <==> Port 80 <==> Apache + PHP + Xdebug extension <==> Port 9000 <==> DBGp Plugin-notepad++
    This excellent plugin deserves a separate article .
  • Explorer : Open your file in Notepad++ quickly using Explorer plugin . It has two sections : Folder tree box(to see directories-sub directories) and File box. Using bottom filter box , You can filter files to find in large listing . Installation can be done via Notepad’s Plugin-manager .
  • Compare : No need to install other app to compare files , You can do it easily with Notepad++ itself . Open two files you wish to compare . Click Plugins > Compare > Compare , you’ll get differences highlighted . To off compare screen and back to editor window , Plugins > Compare > Clear Results . Installation can be done via Notepad’s Plugin-manager .

I had to skip many concepts or detailed explanations , the article had to be kept into reasonable size . Future articles will go in more details on some of the aforementioned plugins  . Happy Notepad-ing  :) .


1. Miles - September 11, 2012

Awesome blog! Do you have any helpful hints for aspiring writers?
I’m planning to start my own site soon but I’m a little lost on everything.

Would you recommend starting with a free platform like WordPress
or go for a paid option? There are so many choices out there that
I’m completely confused .. Any ideas? Thank you!

tournasdimitrios1 - September 11, 2012

It all depends how comfortable you feel with web-administration and especially with the WordPress platform .
I would be glad to help you , at least to get you started . If you need help , just pm .
ps My spam-filter has marked your comment as spam , so I’ll delete it in a couple of days from my Blog .

2. LuzParee - September 22, 2012

I just want to say I’m new to blogs and truly enjoyed your web blog. Very likely I’m want to bookmark your blog post . You really have fabulous posts. Thanks a lot for revealing your web site.

3. mmo - September 23, 2012

I came here searching for something else, but this interested me regardless. Enthusing stuff!

4. akkwe - November 16, 2012

My Sourcecookifier shows NO vars😦

tournasdimitrios1 - November 16, 2012

I had also similar “weird functionality” , then , I had to un-install some other plugins . It’s like a sort of plugin conflict . For example Sourcecookifier doesn’t work if “SnippetPlus” is installed . I have to “switch” between those two plugins (installing / un-installing) .
Keep also in mind that Sourcecookifier depends on the .Net Framework (.NET 2.0 is required , upgrade your computer to the latest version of this Framework) .
As a last resource , try to get support from it’s home-page .
Thanks for your visit on this Blog🙂

5. Amor Asad - April 1, 2013

If you’re into HTML/CSS then emmet is a great notpad++ plugin for you.

6. webMonkey - September 13, 2013

It is not my first time to pay a quick visit this web site, i am visiting this website
dailly and take nice information from here all
the time.

7. wstam88 - December 11, 2013

Thank you for sharing this informative article. I want to mention that in order to duplicate the current line pressing ctrl-d does not require the cursor to be at the end of the line.

8. Jaydeep Gorwami - October 13, 2015

I have little more tricks to add for more information.
– Duplicate the selected text ==> ctrl + d ( Select the text you want to copy ).
– Set indent to the whole selected bolck by pressing Tab on selected text.
– Navigate between opend files ==> ctrl + Tab.
– Close the current file ==> ctrl + w

9. HGN - November 12, 2015

Nice, really nice tips, I thought I already knew all of them! Thanks Tournas!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s