這一直沒發現在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 pythonimport sysimport osdel_num = 3if len(sys.argv)>1: del_num = int(sys.argv[1])#copy clipboard data to from.txtcmd = '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 clipboardcmd = 'cat to.txt | xclip -selection clipboard'os.popen(cmd)print ""print "to.txt:"print dataprint "del_num:", del_num print "ok."