- 浏览: 72338 次
- 性别:
- 来自: 杭州
最新评论
-
鹤惊昆仑:
ipython更好
python 交互式kill 命令 -
lijunjie:
使用pkill firefox
python 交互式kill 命令 -
花花公子:
night_stalker 写道执行 ruby 代码也可以,不 ...
vim 随意执行 python 代码 -
night_stalker:
执行 ruby 代码也可以,不过需要编译参数 +ruby 的版 ...
vim 随意执行 python 代码 -
abruzzi:
续一个:继承Burns先生的遗产的那一集中,Bart和Lisa ...
Simpsons 搞笑镜头
一直想找个用vim来管理todo列表的script, 没发现特别好用的,
自己写了个,用sqlite来保存数据.
将下面代码存为 SzTodo.vim,放到plugin目录里.
用 :SzTodo 启动.
自己写了个,用sqlite来保存数据.
将下面代码存为 SzTodo.vim,放到plugin目录里.
用 :SzTodo 启动.
let g:sztodo_db_path="/root/.vim/todo" let s:list_type="unfinished" let s:cur_buf = 0 function! MakeTemplate() python << EOF import vim vim.command("call SwitchToDetailView()") vim.command("call SetSyntax()") template = "=" * 50 + "\n" \ + "tag:" +"\n" \ + "title:" + "\n" \ + "=" * 50 + "\n" for index,line in enumerate(template.split("\n")): if index ==0 : vim.current.buffer[0]=line else : vim.current.buffer.append(line) EOF endfunction function! SaveTodoItem() python << EOF import vim def loadData(lines): item=ToDoItem() content="" seperates=0 for line in lines: if line.startswith("====="): seperates=seperates+1 if line.startswith("id:"): item.id=line[3:].strip() if line.startswith("tag:"): item.tag=line[4:].strip() if line.startswith("title:"): item.title=line[6:].strip() if line.startswith("status:"): item.status=line[7:].strip() if seperates==2 and not line.startswith("===="): content=content+line+"\n" item.content=content[:-1] return item def addItem(item): insertSql="insert into SzTodo(tag,title,create_date,status,content) values (?,?,?,?,?)" con=sqlite.connect(getDbFileName()) cur=con.cursor() values=(item.tag,item.title,item.create_date,item.status,item.content) cur.execute(insertSql,values) con.commit() con.close() def updateItem(item): updateSql="update SzTodo set tag=?,title=?,create_date=?,status=?,content=? where id=?" con=sqlite.connect(getDbFileName()) cur=con.cursor() values=(item.tag,item.title,item.create_date,item.status,item.content,item.id) cur.execute(updateSql,values) con.commit() con.close() data=vim.current.buffer[:] todoItem=loadData(data) if not todoItem.title: print "title can't be empty" else: if todoItem.id.strip() == "" : todoItem.create_date=getCurrentDate() todoItem.status="unstarted" addItem(todoItem) else : updateItem(todoItem) print "todo has been saved" EOF exec bufwinnr(s:cur_buf) . "wincmd w" call ListItems() endfunction function! ListItems() python << EOF import vim listFinished=vim.eval("s:list_type") vim.current.buffer[:]=None vim.command("set nonumber") if listFinished=="finished": selectSql="select id,tag,title,create_date,content from SzTodo where status == 'done' " else: selectSql="select id,tag,title,create_date,content from SzTodo where status != 'done' " con=sqlite.connect(getDbFileName()) cur=con.cursor() items=[] cur.execute(selectSql) for index,row in enumerate(cur): formatedItem=str(row[0])+". "+str(unicode(row[2]).encode("utf-8")) if index==0: vim.current.buffer[0]=formatedItem else : vim.current.buffer.append(formatedItem) con.commit() con.close() EOF endfunction function! SwitchToDetailView() let s:cur_buf = bufnr("%") let s:szdb_result_buf=bufnr("SztodoDetail") if bufwinnr(s:szdb_result_buf) > 0 exec bufwinnr(s:szdb_result_buf) . "wincmd w" %d else exec 'silent! botright split SztodoDetail' exec "e SztodoDetail" exec "set nowrap" map <silent><buffer>s :call SaveTodoItem()<cr> endif endfunction function! ShowItemDetail(preview) python << EOF import vim (row, col) = vim.current.window.cursor line = vim.current.buffer[row-1] id=line[0:line.find(".")] selectSql="select id,tag,title,create_date,content,status from SzTodo where id=?" con=sqlite.connect(getDbFileName()) cur=con.cursor() cur.execute(selectSql,(id,)) todoItem=ToDoItem() for row in cur: todoItem.id=row[0] todoItem.tag=unicode(row[1]).encode("utf-8") todoItem.title=unicode(row[2]).encode("utf-8") todoItem.create_date=unicode(row[3]).encode("utf-8") todoItem.content=unicode(row[4]).encode("utf-8") todoItem.status=unicode(row[5]).encode("utf-8") vim.command("call SwitchToDetailView()") vim.command("call SetSyntax()") for index,line in enumerate(str(todoItem).split("\n")): if index==0: vim.current.buffer[0]=line else: vim.current.buffer.append(line) EOF if a:preview=="true" exec bufwinnr(s:cur_buf) . "wincmd w" endif endfunction function! UpdateItemStatus(status) let choice=input('you really want to update the todo item status to '.a:status."?[y/n]") if choice=="n" return endif python << EOF import vim (row, col) = vim.current.window.cursor line = vim.current.buffer[row-1] id=line[0:line.find(".")] updateSql="update SzTodo set status = ? where id=?" status=vim.eval("a:status") con=sqlite.connect(getDbFileName()) cur=con.cursor() cur.execute(updateSql,(status,id)) con.commit() con.close() EOF endfunction function! InitDb() python << EOF import vim import os createSql="create table SzTodo (id integer primary key , tag char(20), title varchar(200), \ create_date varchar(10),status char(1),content varchar(5000))" path=os.path.dirname(getDbFileName()) if not os.path.exists(path): os.makedirs(path) con=sqlite.connect(getDbFileName()) cur=con.cursor() cur.execute(createSql) con.commit() con.close() print "db has been created" EOF endfunction function! s:DefSzTodoGlobal() python << EOF import vim from pysqlite2 import dbapi2 as sqlite statusDict=dict(done="done",postpone="postpone",doing="doing",unstarted="unstarted") class ToDoItem(object): def __init__(self,id="",tag="",title="",content="",create_date="",status=""): self.id=id self.tag=tag self.title=title self.create_date=create_date self.status=status self.content=content def __str__(self): return "=" * 50 + "\n" \ + "id:" + str(self.id) +"\n" \ + "tag:" + self.tag +"\n" \ + "title:" + self.title + "\n" \ + "status:" + self.status + "\n" \ + "=" * 50 + "\n" \ + self.content def getCurrentDate(): from datetime import datetime t=datetime.now() return t.strftime("%Y-%m-%d %H:%M") def getDbFileName(): dbpath=vim.eval("g:sztodo_db_path") path=os.path.join(dbpath,"todo.dat") return path EOF endfunction function! StartApp() python << EOF import vim import os if not os.path.exists(getDbFileName()): vim.command("call InitDb()") vim.command("call ListItems()") vim.command("call SetMapping()") EOF endfunction function! SetMapping() map <silent><buffer> o :call ShowItemDetail("false")<cr> map <silent><buffer> s :call ShowItemDetail("true")<cr> map <silent><buffer> i :call MakeTemplate()<cr> map <silent><buffer> r :call ListItems()<cr> map <silent><buffer> p :call UpdateItemStatus("postpone")<cr> map <silent><buffer> d :call UpdateItemStatus("done")<cr> command! -nargs=0 FinishedItem :call FinishedItem() command! -nargs=0 UnfinishedItem :call UnfinishedItem() endfunction function! FinishedItem() let s:list_type="finished" call ListItems() endfunction function! UnfinishedItem() let s:list_type="unfinished" call ListItems() endfunction function! SetSyntax() syn keyword sztodoKeyword tag title id status syn keyword sztodoStatus unstarted done doing postpone syn match tag "^tag:.*" syn match title "^title:.*" syn match id "^id:.*" syn match status "^status:.*" hi def link sztodoKeyword Keyword hi def link sztodoStatus Identifier hi def link tag String hi def link id String hi def link title String hi def link status String endfunction call s:DefSzTodoGlobal() command! -nargs=0 SzTodo :call StartApp()
发表评论
-
vim 的一些技巧
2010-03-27 20:43 10361 : 在编辑html文件时,vim对一些 B,I,EM,A ... -
vim 随意执行 python 代码
2009-08-21 16:54 4211vim72的win版本已经有内建的python支持,linux ... -
vim技巧 随笔
2009-03-22 22:50 1754文本块操作 di" : 删除 "&qu ... -
vimperator 小技巧
2009-03-19 23:51 1117在 vimperatorrc文件中 加入set guiopti ... -
python写vim script 之 糗事百科
2009-02-24 12:08 1711工作累了,难免想开点小差,弄点轻松的东西看看,又不能让老大发现 ... -
python写vim script之 山寨版气象
2009-02-14 20:57 1150说明: 1: http://www.hzqx.com/gzhf ... -
python写vim script 之 山寨版 dbext
2009-01-17 20:46 2529山寨版 dbext 需要有python支持的vim,windo ... -
gvim水平滚动条
2008-06-04 19:40 3779set guioptions+=b 一直没找到这个设置..不 ... -
好用的vim工具
2008-01-11 09:55 1668一个可以让vim来编辑任意窗口上文本编辑框的小工具。很有用 ... -
Vimperator 基础操作
2007-05-17 11:41 2431最常用的 h,j,k,l,gg,G,0,$等上下左 ... -
Best of VIM Tips (VIM's best Features) 缩减编辑版
2007-05-15 15:58 1246:nmap ,s :source $VIM/_vimrc & ... -
vim里用不常用的移动操作
2007-04-28 19:49 1098% : 这个常用,移到匹配的括号处 [* or ... -
VIMperator介绍
2007-04-20 17:39 1372官方首页: http://vimpera ... -
用vimdiff来比较文件
2007-04-17 21:47 1321启动 : gvimdiff 文件1 文件2(在比较模式 ... -
vim技巧(摘自linux宝库)
2007-04-14 10:40 1391vim在屏幕行间移动 当文件的某些行比较长,超过屏幕宽度时,通 ...
相关推荐
NULL 博文链接:https://shrek.iteye.com/blog/317954
笨方法学 Vim Script
python.vim_3.3
pythonwin for 2.5 vim编译器,是自己好不容易收集到的,希望大家喜欢
vimscript,由浅入深,勤加练习,写出让大家都喜欢用的vim插件,需要的知识都在这里。
Python-mode:将 Vim 变成 Python IDE 的一款多合一插件
Learn Vimscript the Hard Way PDF版,找了很久才找到
python.vim taglist pydiction 三个插件uzip 解压~
learn vimscript the hard way的mobi版。方便用kindle来离线阅读。
包中包括: python.vim pythoncomplete.vim nerdtree.zip vim-autocomplpop.zip 四个插件及vim官网中对应的说明。 送给那些不能上官网的青年。
vim-jsx-pretty, [Vim script] 对vim的JSX语法非常突出 vim-jsx-pretty演示语法vim-jsx-pretty( 添加彩色配置) vim-jsx-pretty mxw/vim-jsx 自动缩进( 使用 vim-javascript )
Vimapt是一个vim包管理器,"vimapt"是"Vim's Advantage Package Tools"的缩写
前言 vim是个伟大的编辑器,不仅在于她特立独行的编辑方式,还在于她强大的扩展能力。...在编译之前,configure的时候加上–enable-pythoninterp和–enable-python3interp选项,使之分别支持Python2和Pytho
python-vim这是我自己精简后的python vim开发包环境。实还有更加丰富的功能,但那只会让vim速度变得很慢。 所以我要说的是,并不是插件越多越好,而是越精简越好,把不用的插件都在.vimrc中注释掉。更多的介绍python...
针对python的VIM配置文件,包含如何配置YCM过程,具体不懂欢迎咨询。
本书将向您介绍Vimscript,这是用于自定义Vim并使您在Vim中的其余时间更有效的主要编程语言。
mac下vim之python配置步骤,自动缩进,语法高亮,背景,自动补全,文件管理
Vimscript的面向对象框架,外观和感觉都类似于Python,并力求最大程度地提高便利性并与内置函数兼容。 阅读: Vim和Python是朋友,让我们做更多吧! 例子 定义类并创建实例。 let MyClass = object#class ( ' ...