这一直没发现在linux下好用的块移动的编辑器
因为你可能在网上copy下来的代码是这样的需要把整个代码向前移4个字符自己写了这样一个程式来实现这个功能
>>> from sqlalchemy import Column, Integer, String
>>> class User(Base):
... __tablename__ = 'users'
...
... id = Column(Integer, primary_key=True)
... name = Column(String)
... fullname = Column(String)
... password = Column(String)
step
1. copy clipboard data to file
2. read data from file
3. block move
4.save file
5. copy file data to clipboard
说明
用到xclip这个软件
ubuntu下可以直接 sudo apt-get install xclip
#copy clipboard data to from.txt
xclip -o > from.txt
#copy data to clipboard
cmd = 'cat to.txt | xclip -selection clipboard'
os.popen(cmd)
block_move.py
#!/usr/bin/env python
import sys
import os
del_num = 3
if len(sys.argv)>1:
del_num = int(sys.argv[1])
#copy clipboard data to from.txt
cmd = 'xclip -o > from.txt'
os.popen(cmd).read()
to_data = []
print "from.txt:"
with open('from.txt') as fp:
for line in fp:
print line,
to_line = line[del_num:]
to_data.append(to_line)
to_file = open('to.txt', 'w')
data = ''.join(to_data)
to_file.write(data)
to_file.close()
#copy data to clipboard
cmd = 'cat to.txt | xclip -selection clipboard'
os.popen(cmd)
print ""
print "to.txt:"
print data
print "del_num:", del_num
print "ok."