【问题标题】:Notepad++ Column EditorNotepad++ 列编辑器
【发布时间】:2016-09-24 05:44:27
【问题描述】:

在 Notepad++ 中,我一直在使用 Edit->Column Editor 在文本文件的每一行添加一个数字,非常棒!

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

【问题讨论】:

  • 最快的方法是用你最喜欢的脚本语言编写脚本。

标签: notepad++ multiple-columns


【解决方案1】:

是的,您可以编写一个 Python 脚本来执行此操作。执行这些步骤(如果不适用,则省略):

  • 安装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 脚本 -> Scripts -> AddLineIdsAllTabs 运行脚本。

替代脚本

notepad.activateIndex(view, index) 行之后,使用

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

【讨论】:

    猜你喜欢
    • 2011-03-28
    • 1970-01-01
    • 2020-06-23
    • 2016-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-11
    • 2014-05-01
    相关资源
    最近更新 更多