Is there any way to manage code snippets with backup for the database and code highlighting in Notepad++?
There are various ways you can store a code snippet, either by keeping it in a GitHub repository or can use a smart code snippet manager, like Codiga's Coding Assistant. Coding Assistant allows you to store and reuse code snippets.
With a code file open in the editor, choose Snippets > Insert Snippet from the right-click menu, then My Code Snippets. You should see a snippet named Square Root. Double-click it. The snippet code is inserted in the code file.
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:
ifelseif
in the Snippets section of the dock: this will insert the code block marked in blue.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:
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:
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
You can insert snippets to documents also by using keyboard shortcut Ctrl+Shift+ENTER:
Notes:
I hope this information will be helpful for you.
This answer is not specifically about how to manage np++ code snippets, but this might be a good alternative since it looks like that plug-in doesn't work very well. I've found a very flexible system wide solution is to use AHK. You can then get snippet like functionality, plus a lot more, by customizing hotkeys and text expansion.
For instance, a one liner AHK script like this :*:123::123456789
will automatically expand typing "123" to "123456789", regardless of your current editor (np++ or VS, whatever). To limit this to specific applications, just add another line like this #IfWinActive, ahk_exe devenv.exe
(Full example here).
More on AHK for plaintext
Simple AHK Script to Manage Code Snippets
I just whipped up a simple solution to manage a CodeSnippet database. A little more work and this could be a lot slicker.
What it does
Provides a code snippet list shown by hitting Ctrl+Alt+S. Double click a snippet and it will paste in your application. Snippets are simply a list of files and the contents of the file provide the code to the snippet.
How to setup it up
1.) Requires a folder named "CodeSnippets" under your MyDocuments directory. Create your code snippet files in this folder.
2.) Use AHK to run the following script. To "set and forget", have the script run on Windows startup. From any application in Windows, hit Ctrl+Alt+S to select a snippet.
#NoEnv HotKey, ^!s, ShowList return ShowList: Gui, Add, ListView, r20 w300 gMyListView, Name Loop, %A_MyDocuments%\CodeSnippets\*.* LV_Add("", A_LoopFileName) Gui, Show return MyListView: if A_GuiEvent = DoubleClick { LV_GetText(RowText, A_EventInfo) FileRead, Snippet, %A_MyDocuments%\CodeSnippets\%RowText% Clipboard := Snippet Gui, Destroy Send ^v } return GuiClose: Gui, Destroy return
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With