2016-09-23 64 views
2

在Notepad ++中我一直在使用Edit-> Column Editor在文本文件的每一行上放一个数字,太好了!Notepad ++列编辑器

有没有一种方法可以对所有打开的文档执行此操作,以便为每个文本文件节省这些操作?

+0

最快的方法是在你最喜欢的脚本语言编写一个脚本。 – Toto

回答

1

是的,你可以写一个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 

现在,从运行脚本插件 - >的Python脚本 - >脚本 - >AddLineIdsAllTabs

替代文字

notepad.activateIndex(view, index)线后,使用

editor.selectAll() 
notepad.runMenuCommand('TextFX Tools', 'Insert Line Numbers')