Tuesday, May 4, 2010

Notepad++ Tips and Tricks

As regular readers will know, I'm a great fan of free software. I use Notepad++ for most of my code editing. Here are a few useful tips and tricks I've picked up along the way. Much of this stuff is standard for a text editor but not necessarily that easy to find in Notepad++.

  1. View in browser: You can easily view your open HTML file in a browser by clicking on Run. Choose from IE, Firefox, Chrome and Safari. Or select Run... and browse to another executable. You can also update the shortcuts.xml file to add another browser, or change the location of a browser executable.
  2. Basic version control: By turning on Verbose backup (Settings > Backup/Auto-Completion) you can set up Notepad++ to implement very basic revision control. Every time you save a file, Notepad++ will save a "clean" version in a backup sub-folder called nppBackup. That is, the version that you last saved, with none of your recent changes. The backup filename is appended with a date and timestamp so you end up with a new backup for every change. It probably goes without saying that it's a good idea to periodically delete the ones you don't want. Even if you're using some kind of version control this can be useful between check-ins.
  3. Auto-completion: Whilst you're in the Backup/Auto-Completion screen set it to auto-complete functions.
  4. Create templates: Notepad++ doesn't have the concepts of templates but I decided to set up my own. I created a templates folder and saved a few varieties of basic HTML files, including DOCTYPE, external CSS and JS calls, and an empty body tag. I did this for XHTML Strict and HTML4 Strict, with variations for JQuery and CSS 960grid. I open the relevant template and then Save As... to create my new file.
  5. Close tags: You can use TextFX to automatically close any XHTML tags. Go to TextFX > TextFX > Settings > Autoclose XHTML/XML . There are a whole host of other useful TextFX features, such as converting case and quotes, escaping and unescaping characters, submitting to W3 validators, running HTMLTidy and a whole host of other features I haven't yet found a need for.
  6. Create new tab group: Similar to Visual Studio's New Vertical Tab Group, you can view documents (or tabbed groups of documents) side-by-side using View > Move/Clone Current Document > Move to Other View. F8 then toggles between these views. Choosing to Clone effectively implements split screen and any changes made to one view of the document will be replicated in the other.
  7. Use bookmarks to navigate large documents: When reading through large code files I often spend much of my time scrolling between two or more parts of the file. Clicking between the line number and the line adds a bookmark. I can then easily navigate from one bookmark to the next using F2 (down) and Shift+F2 (up).

30 comments:

  1. Which auto completion do you use? There's function and word but I find the assistance of either varies from language to language. I think I prefer function auto completion in HTML/CSS/Javascript.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. When I started writing this I was using function (hence "set it to auto-complete functions"). Now I'm trying word. I haven't quite decided which one is most useful but word seems to be working okay.

    ReplyDelete
  4. Thanks for your tips. Is there any way to implement "Create new tab group" with 3 documents ? In my case, the third one moves between the 2 that are already created.

    ReplyDelete
  5. Hi Anonymous,
    thanks for your comment and sorry for my delayed reply.

    I don't think you can have more than 2 views. But I also wonder how useful a third view would be as it would significantly limit how much you can see on screen at any one time. (Unless, of course, you have a massive monitor, which I, sadly, do not.)

    Do you know of any other editors that allow more than 2 views? My Visual C# Express only allows 2 views as well.

    One good thing that I have discovered since writing this post is that you can toggle between vertical tab groups and horizontal tab groups. To do this click on the dotted lines between the views and select one of the rotate options. Play around with this feature to see how you can swap tab groups around.

    ReplyDelete
  6. Thanks for the tips... notepad++ is so much more than you can see on the surface... if I could just figure out code highlighting for .erb files now!

    ReplyDelete
  7. I don't code with Ruby on Rails but there is built-in language highlighting for "Ruby". Have you tried this with your .erb files? There are loads of other tips for using Notepad++ with Ruby. Check out these links:
    http://www.praj.com.au/notepad-plus-plus-editor/
    http://balagan.org.uk/software-development/ruby-on-rails/which-editor-or-ide-on-windows.htm
    http://therubyway.wordpress.com/2009/01/08/rails-on-notepad-2-plugins-for-notepad/

    ReplyDelete
  8. I appreciate the links... the ruby language is supported very well. ERB (embedded ruby) would need to be a hybrid of HTML and Ruby - which I have not had luck working with. It's not a killer, still using notepad++, I suppose it will come some day ;)

    ReplyDelete
    Replies
    1. See this is 3 years old and don't use Ruby but - if you go to Settings|Style Configurator, Select Ruby then select INSTRUCTION you can add User Defined Keywords.

      Note that this same type of problem exists for MySQLi in the SQL section of the Configurator. But in this case use KEYWORD to add your User Defined Keywords.

      Delete
  9. I was wondering was there a setting that could change the following. When you must select a length of content from a long line of code, if i go above or below the line the cursor returns to the far left of back to the start of the line. Can you change this so that screen does not move back to the start of the line?

    ReplyDelete
  10. December 1, 2010 5:25 AM response
    click View then Word wrap

    ReplyDelete
  11. About tip #1: Wouldn't it be a lot simpler if Notepad++ just included a "View in Browser" command on its View menu, as many other high-class text editors do? You know---you click that command and it opens your (presumably browser-displayable) document in your system's default browser. This is not hard to do.

    Well, I know you don't actually develop NP++... I guess I'm just venting, as I suggested this several years ago to NP++'s developers and they apparently ignored me.

    ReplyDelete
  12. Oh, never mind---It's on NP++'s "Run" menu: "Launch in Firefox", "Launch in IE", etc.

    (And maybe I'm just being dense, but I still have no idea what you're talking about in Tip #1.)

    ReplyDelete
  13. Very useful tips. It was too helpful for us. Thanks for sharing it. Keep it up.

    ReplyDelete
    Replies
    1. I cannot stand comment username spammers, maybe you didn't see the no-follow tag?? are you thick?? your only wasting your own time.

      Delete
  14. Amazing tips. You might be a great author. Thanks for your time. Keep posting like this.

    ReplyDelete
  15. Hey Ander, what do you mean you have no idea what I'm talking about in Tip #1? I am pretty much just saying what you said in your two comments, i.e what other text editors call "View in browser" can be achieved by clicking "Run" etc. And this is customisable - so if the browser you want to use doesn't appear in the list you can either run the .exe as a one off, or update shortcuts.xml to add it permanently. I hope that makes things more clear for you.

    ReplyDelete
  16. A folder called 'nppBackup' continuously appears on my Desktop when using Notepad++. I have a location specified for the temp file saves already, so I don't understand why it would keep creating this folder in locations that I have not specified. Any ideas?

    ReplyDelete
  17. https://neilpatel.com/blog/loud-is-weak/

    ReplyDelete
    Replies
    1. whatever you do, dont click on the link above, it's a website that tries to load malware unto your computer!!!

      Delete
  18. The vital information in this blogs has allured me.
    WIKIPEDIA

    ReplyDelete
  19. Forex Signals, MT4 and MT5 Indicators, Strategies, Expert Advisors, Forex News, Technical Analysis and Trade Updates in the FOREX IN WORLD

    Forex Signals Forex Strategies Forex Indicators Forex News Forex World

    ReplyDelete
  20. I see the greatest contents on your blog and I extremely love reading them.
    website design company San Francisco

    ReplyDelete
  21. Continue the good work; keep posting more n more n more.
    UI design firms

    ReplyDelete
  22. Another point : is there a user way to remove buttons from the TabBar, in other words to customize this TabBar ?

    ReplyDelete
  23. very useful and interesting article please get to know more

    ReplyDelete