Manage code snippets in Notepad++

前端 未结 3 1225

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

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-04 11:26

    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
    

提交回复
热议问题