Reputation: 13
I am trying to use notepad++ as a TeX editor, as such I would like to add custom shortcuts which would insert code or even surround with a selected block, however the snippet plugins don't offer custom shortcut AFAIK
I would like to press control + i and it would insert \textit{}
Is it possible to achieve?
Upvotes: 1
Views: 4305
Reputation: 3653
A bit late to answer this but what I usually do is record a Macro. For example, click the Macro => Start Recording
menu option and then type the following:
def main():
pass
if __name__ == "__main__":
main()
After that, click Macro => Stop Recording
. Now you have successfully created a basic snippet which is used in most python scripts! To test, simply create a new file and play the recorded macro by pressing Ctrl+Shift+P
. To save this recorded macro permanently and assign a shortcut to it, click Menu => Save Current Recorded Macro
.
You can do all kinds of wonderful things with macros, creating code snippets is just one application.
Upvotes: 3
Reputation: 10129
If the Snippet Plugin is not working for you I can describe a very laborous way using the NppExec Plugin. For each Shortcut you would create a new NppExec script and then assign this script a shortcut.
enter these lines and save it as e.g. Insert_TextIt
NPP_CONSOLE OFF
SCI_SENDMSG SCI_INSERTTEXT -1 "\textit{}"
SCI_SENDMSG SCI_WORDRIGHT
SCI_SENDMSG SCI_WORDRIGHT
SCI_SENDMSG SCI_CHARRIGHT
Now select Plugins -> NppExec -> Advanced Options ...
The last three commands SCI_WORDRIGHT
and SCI_CHARRIGHT
position the cursor inside the braces. For different text snippets you might have to experiment with the cursor position. See Scintilla Documentation for more possible commands.
Upvotes: 1