Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
251 views
in Technique[技术] by (71.8m points)

Manage code snippets in Notepad++

Is there any way to manage code snippets with backup for the database and code highlighting in Notepad++?

question from:https://stackoverflow.com/questions/5147177/manage-code-snippets-in-notepad

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There is a good plugin to manage code snippets:

SnippetPlus
.NET 3.5 Required! 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 Note that the latest version may be shown, even though you have an older version installed. Reinstall to ensure you have the latest version.
Author: Rajesh Kumar
Homepage: http://sourceforge.net/projects/snippetplus/

You can install it from Notepad++ Plugin Manager, and activate dock by clicking the black m-like symbol in the toolbar; then select one of the bundled snippets and paste it to editor by double-clicking it.

For example, if you have a Visual Basic file and you need to include a try/catch block which contains an if-elseif-else structure, you must follow these steps indicated in the image:

SnippetPlus example

  1. Put your cursor where you want the new code snippet to be at, then activate dock from toolbar: this will open the docked dialog marked in yellow.
  2. Double-click the option ifelseif in the Snippets section of the dock: this will insert the code block marked in blue.
  3. Select all the code you want to be inside the try/catch block and Double-click the option TryCatch in the SurroundWith section of the dock: this will replace the selected code with all the code block marked in red.

If you want to modify existing snippets or include yours, use the GUI editor:
GUI Editor

Click the snippet you want to modify/delete: it will be shown at right. The active section (either Snippets or SurroundWith) is highlighted with a dark red background:

GUI Editor

You can add custom snippets too: just select the proper language and click any snippet from the section you want the new snippet to belong (either Snippets or SurroundWith), then write the name of the new snippet you want to create (e.g. sample): the button Modify will change to Add New
Add new snippet

You can insert snippets to documents also by using keyboard shortcut Ctrl+Shift+ENTER:

  1. You can write directly snippet name and then press keyboard shortcut, or
  2. You can invoke popup pressing keyboard shortcut, and then pressing keyboard shortcut again to replace snippet name with snippet content.

insert snippet by keyboard shortcut

Notes:

  • This plugin keeps snippets (including custom ones) between restarts.
  • Important Note: If you add/modify/delete snippets, only after a restart of Notepad++ the changes will be applied (including contents of lists at sections Snippets and SurroundWith). Be careful with this to not duplicate or add incomplete snippets.
  • To apply code highlighting for language you're working, just select it from the menu language as is done traditionally:
    code highlight
  • The code snippets shown on Ctrl+Shift+ENTER menu, depend on the language highlighting currently applied to the document. The only code snippets shown globally are whose belonging to category GENERAL.

I hope this information will be helpful for you.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...