【发布时间】:2016-09-24 05:44:27
【问题描述】:
在 Notepad++ 中,我一直在使用 Edit->Column Editor 在文本文件的每一行添加一个数字,非常棒!
有没有一种方法可以对所有打开的文档执行此操作,以节省我为每个文本文件执行此操作的时间?
【问题讨论】:
-
最快的方法是用你最喜欢的脚本语言编写脚本。
标签: notepad++ multiple-columns
在 Notepad++ 中,我一直在使用 Edit->Column Editor 在文本文件的每一行添加一个数字,非常棒!
有没有一种方法可以对所有打开的文档执行此操作,以节省我为每个文本文件执行此操作的时间?
【问题讨论】:
标签: notepad++ multiple-columns
是的,您可以编写一个 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 脚本 -> Scripts -> AddLineIdsAllTabs 运行脚本。
替代脚本
在notepad.activateIndex(view, index) 行之后,使用
editor.selectAll()
notepad.runMenuCommand('TextFX Tools', 'Insert Line Numbers')
【讨论】: