Notepad++ 列编辑器
Notepad++ Column Editor
在 Notepad++ 中,我一直使用“编辑”->“列编辑器”在文本文件的每一行上放置一个数字,太棒了!
有没有一种方法可以对所有打开的文档执行此操作,以节省我对每个文本文件执行此操作的时间?
是的,您可以编写 Python 脚本来执行此操作。执行这些步骤(如果 N/A 则省略):
- 安装PythonScript
- 转到插件 -> Python 脚本 -> 新脚本
- 创建一个新的
AddLineIdsAllTabs.py
脚本
- 添加这些内容:
offset = 1 # Define the offset (step) value
fileNames = notepad.getFiles() # get all open files
for x in fileNames[1:]: # iterate thru all tabs (first is doubled, thus skipping)
filename, bufferID, index, view = x # get the details
notepad.activateIndex(view, index) # activate the tab
line_number = editor.getLineCount() # get line count
for id in range(line_number): # iterate thru all lines
editor.gotoLine(id) # go to line with a given ID
editor.home() # place cursor at the line start
editor.addText("{0}. ".format(str(id+offset))) # Add text
现在,运行 来自 Plugins 的脚本 -> Python Script -> 脚本 -> AddLineIdsAllTabs.
替代脚本
在notepad.activateIndex(view, index)
行之后,使用
editor.selectAll()
notepad.runMenuCommand('TextFX Tools', 'Insert Line Numbers')
在 Notepad++ 中,我一直使用“编辑”->“列编辑器”在文本文件的每一行上放置一个数字,太棒了!
有没有一种方法可以对所有打开的文档执行此操作,以节省我对每个文本文件执行此操作的时间?
是的,您可以编写 Python 脚本来执行此操作。执行这些步骤(如果 N/A 则省略):
- 安装PythonScript
- 转到插件 -> Python 脚本 -> 新脚本
- 创建一个新的
AddLineIdsAllTabs.py
脚本 - 添加这些内容:
offset = 1 # Define the offset (step) value
fileNames = notepad.getFiles() # get all open files
for x in fileNames[1:]: # iterate thru all tabs (first is doubled, thus skipping)
filename, bufferID, index, view = x # get the details
notepad.activateIndex(view, index) # activate the tab
line_number = editor.getLineCount() # get line count
for id in range(line_number): # iterate thru all lines
editor.gotoLine(id) # go to line with a given ID
editor.home() # place cursor at the line start
editor.addText("{0}. ".format(str(id+offset))) # Add text
现在,运行 来自 Plugins 的脚本 -> Python Script -> 脚本 -> AddLineIdsAllTabs.
替代脚本
在notepad.activateIndex(view, index)
行之后,使用
editor.selectAll()
notepad.runMenuCommand('TextFX Tools', 'Insert Line Numbers')