Sublime Text:在列位置添加字符

时间:2016-10-03 15:12:35

标签: python comments sublimetext2 sublimetext3

我有一个包含几百行代码的Python文件。最长的行是146个字符。如何在Sublime Text中的整个文件中将#放在第200列?最好有一个或两个Sublime Text命令?

1 200

print("Hello world!") #

2 个答案:

答案 0 :(得分:1)

你可以尝试这样的事情。请注意,这会写入新文件:如果您要我修改以便覆盖现有文件,请告诉我:

WITH cte AS (
    SELECT  
        *,
        RANK() OVER (ORDER BY Authors) [Group]
    FROM (  
        SELECT 
            [Customer],
            STUFF((SELECT ',' + [Author]
                   FROM myTable WHERE Customer = mt.Customer
                   ORDER BY Author
                   FOR XML PATH('')), 1, 1, '') AS Authors
        FROM
            myTable mt
        GROUP BY [Customer] ) t
)

SELECT  
    mt.[ID],
    mt.[Author],
    mt.[Customer],
    cte.[Group]
FROM 
    cte 
    JOIN myTable mt ON mt.Customer = cte.Customer
ORDER BY mt.[ID]

请注意,如果行长度> = 200,则只会在行尾添加“#”(无论列号如何)。

答案 1 :(得分:0)

这是一个可能的解决方案:

N = 200
output = [l.rstrip() for l in f]
output = ["{0}#{1}".format(
    l[:len(l[:N])] + ' ' * (N - len(l[:N])), l[N:]) for l in output]

print("\n".join(output))

或者说不同:

N = 200
output = []
for l in f:
    l = l.rstrip()
    l1 = len(l[:N])
    output.append("{0}#{1}".format(l[:l1] + ' ' * (N - l1), l[N:]))

print("\n".join(output))