navigation tips
find non ascii
[^\x00-\x7F]+
replace tips
Replace dialog search mode: regular expression search: <td id='row..'> replace: note: . : means representing a unknown char
Replace dialog search mode: extended search : \r\n\r\n replace: \r\n note: \r\n\r\n means double new lines
Replace dialog search mode: regular expression find: ^\s*$ replace: note: start and any mount space or tab and a end
npp_root\contextMenu.xml
< Language name="haskell" ext="hs lhs as las" commentLine="--" >
Plugin name | |
---|---|
Hex Editor | Hex code file editing |
TextFX | automate common text typing operation |
Compare | compare difference and similarity between 2 files in split view |
Plugin Manager | a plugin online browser and install helper |
Python Script | add Python consolve integration and python automation for notepad++ |
table>tr#row-$*15>td.col-$*12
from Npp import * # test editor.addText('test')
# Create a new document notepad.new() # open file notepad.open("\web\index.htm") # Save the file newFilename = notepad.getCurrentFilename() + ".changed" notepad.saveAs(newFilename);
notepad.getFormatType() notepad.setFormatType(formatType, bufferID) # Npp.FORMATTYPE.WIN # set syntax color language notepad.getLangType(bufferID) notepad.setLangType(langType, bufferID) # Npp.LANGTYPE.PYTHON; Npp.LANGTYPE.TXT; Npp.LANGTYPE.PHP
# dialog # "1" for type 2 button set; return pressed button id notepad.messageBox("hello world","My Title",1) # prompt notepad.prompt("Enter your name:", "Simple Interact UI", "Tom")
Most useful scintilla edit cmd
editor.addText(text) | Add text to the document at current position. |
---|---|
editor.clearAll() | Delete all text in the document. |
editor.selectAll() | Select all the text in the document. |
editor.gotoLine(line) | Set caret to start of a line and ensure it is visible. |
editor.getCurLine() = str | Retrieve the text of the line containing the caret. Returns the index of the caret on the line. |
editor.setTabWidth(tabWidth) | Change the visible size of a tab to be a multiple of the width of a space character. |
editor.getTabWidth() = int | Retrieve the visible size of a tab. |
editor.getSelText() = str | Retrieve the selected text. Return the length of the text. |
editor.lineDelete() | Delete current line |
editor.lineDown() | navi - move cursor to next line |
# Simple search / replace editor.replace("old", "new") editor.replaceLine(3, "New contents") # Python regular expressions search and replace editor.pyreplace(r"^([A-Z]{3,5})--\1", r"CODE: \1") # Call a Scintilla function editor.appendText("Changed codes\r\n"); # Set clipboard editor.copyText("MyTextReadyToPaste") # insert character at beginning of line editor.rereplace("^","|") editor.rereplace("^(.)",r"before_\1") #insert after editor.rereplace("(.)$",r"\1_after") # replace # editor.rereplace(regex, replace) - general editor.rereplace("find","replace") # replace pattern tag with variable elements editor.rereplace("<td[^>]*>", "|") # replace with new line editor.rereplace("</tr>", "|\r\n") # remove pattern editor.rereplace("</*tbody>", "") # replace all tags editor.rereplace("<[^>]*>", "") # delete all blank line editor.replace("\r\n\r\n","\r\n") # delete either ?? editor.rereplace("__(item|link)__","") # swap front text and back text # ref: http://manual.macromates.com/en/regular_expressions ''' example <li><a href='https://addons.mozilla.org/en-US/firefox/addon/copy-urls-expert/'>Copy Urls Expert</a></li> <li><a href='https://addons.mozilla.org/en-US/firefox/addon/awesome-screenshot-capture-/'>Awesome Screenshot Plus</a></li> <li><a href='https://adblockplus.org/en/'>Add-on Search: AdBlock Plus</a></li> <li><a href='https://adblockplus.org/en/elemhidehelper'>Add-on Search: Element Hiding Helper for ABP</a></li> <li><a href='https://addons.mozilla.org/en-US/firefox/addon/image-block/'>Image block toggle</a></li> <li><a href='https://addons.mozilla.org/en-US/firefox/addon/js-switch/'>JS switch</a><li> <li><a href='https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/'>SQLite Manager (sql datebase editor)</a><li> ''' editor.rereplace("<li.+'(.+)'>(.+)<\/a.+li>","\2, \1") ''' result Copy Urls Expert, https://addons.mozilla.org/en-US/firefox/addon/copy-urls-expert/ Awesome Screenshot Plus, https://addons.mozilla.org/en-US/firefox/addon/awesome-screenshot-capture-/ Add-on Search: AdBlock Plus, https://adblockplus.org/en/ Add-on Search: Element Hiding Helper for ABP, https://adblockplus.org/en/elemhidehelper Image block toggle, https://addons.mozilla.org/en-US/firefox/addon/image-block/ JS switch, https://addons.mozilla.org/en-US/firefox/addon/js-switch/ SQLite Manager (sql datebase editor), https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/ '''
# Write to the console window console.write("Saved as %s\n" % newFilename) # Run a command on the file, and output results to the new file console.run('compiler.exe "%s"' % newFilename, editor)
# change working directory in console import os os.listdir('./') # list wildchar files import glob glob.glob('*.py') # list file for filename in os.listdir("C:\\temp"): print filename # show files print [d for d in os.listdir('./') if d.endswith(".py")] [s in os.listdir('./') if s.endswith('.f') or s.endswith('.c') or s.endswith('.z')] [s in os.listdir('./') if s.rpartition('.')[2] in ('f','c','z')]
npp\plugins\PythonScript\lib npp\plugins\PythonScript\scripts (default startup.py is here) npp\plugins\Config\PythonScript\lib npp\plugins\Config\PythonScript\scripts
# ref: https://github.com/bruderstein/PythonScript/blob/master/scripts/startup.py # The lines up to and including sys.stderr should always come first # Then any errors that occur later get reported to the console # If you'd prefer to report errors to a file, you can do that instead here. import sys from Npp import * # Set the stderr to the normal console as early as possible, in case of early errors sys.stderr = console # Define a class for writing to the console in red class ConsoleError: def __init__(self): global console self._console = console; def write(self, text): self._console.writeError(text); # Set the stderr to write errors in red sys.stderr = ConsoleError() # This imports the "normal" functions, including "help" import site # This sets the stdout to be the currently active document, so print "hello world", # will insert "hello world" at the current cursor position of the current document sys.stdout = editor
Show your scripts in Plugin menu > Python Script > Scripts
npp\plugins\Config\PythonScriptStartup.cnf
ITEM/D:\Lib\npp_script\date.py ITEM/D:\Lib\npp_script\my_script1.py
import os,sys cur_path = os.path.dirname(__file__) cur_path in sys.path or sys.path.append(cur_path)
add your script to context menu
<Item PluginEntryName="Python Script" PluginCommandItemName="my_script1" />
<Item FolderName="Script" PluginEntryName="Python Script" PluginCommandItemName="date" />
add your script to tool bar with icon
ITEM/D:\Lib\npp_script\date.py ITEM/D:\Lib\npp_script\my_script1.py TOOLBAR/D:\Lib\npp_script\date.py/D:\_icon\date.bmp TOOLBAR/D:\Lib\npp_script\my_script1.py/D:\_icon\one.bmp SETTING/STARTUP/LAZY
import subprocess import sys def install(package): subprocess.check_call([sys.executable, "-m", "pip", "install", package]) # py2 case: 2.7 = PySide install("PySide") # py3 case: 3.x = PySide2 install("PySide2")
# notepad path\plugins\Config\PythonScript\scripts\startup.py
and code
# optional clear multiple python registered system path issue old_path = sys.path old_path = [x for x in old_path if not x.startswith('D:\\my_other_system_env_registered_python_path\\Python27') ] sys.path = old_path # register lib path import os my_path_list =[ r'D:\my_path_match_version_local_python_path\Python27\Lib\site-packages', r'D:\my_path_to_other_mpp_app_i_write\NppCoder', r'D:\my_path_to_other_npp_script\npp_script' ] for x in my_path_list: if os.path.isdir(x): sys.path.append(x)
import time import Npp # import sys timeStr = time.strftime( '%Y.%m.%d' ) # sys.stdout.write(timeStr) Npp.editor.addText( timeStr )
from Npp import * selected = editor.getSelText() editor.replaceSel('---- {0} ----'.format(selected))
import sys my_path = r'/your_path_to_standard_site_package/' my_path in sys.path or sys.path.append(my_path) from Npp import * from PyQt4 import QtGui from functools import partial a = QtGui.QApplication([]) w = QtGui.QWidget() main_layout = QtGui.QHBoxLayout() w.setLayout(main_layout) my_label = QtGui.QLabel('Hello') my_btn = QtGui.QPushButton('Text') main_layout.addWidget(my_label) main_layout.addWidget(my_btn) my_btn.clicked.connect(partial(editor.addText,'cool')) w.show() a.exec_()