[ Content | Sidebar ]

Posts tagged vim

vim创建js文件时自动添加文件注释

参考: VIM自动给脚本加注释

在vimrc里添加下面几行

"添加文件注释
command -nargs=0 Addreadme :call Addreadme()
function Addreadme()
call setline(1,"/**")
call append(1," * @require : none")
call append(2," * @author : someone@bluehua.org")
call append(3," * @date : " . strftime("%Y-%m-%d"))
call append(4," * @description : this is a new file ")
call append(5," */")
endf
:au BufNewFile *.js :Addreadme
Copy Code 

懒人工具之:自动刷新firefox,解放ctrl+f5

y,自从用了vim,该让机器做的都让机器做了。。

这个东东的原理是这样滴,firefox安装一个插件,起作用的就下面几行

var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
file.initWithPath("/tmp/refresh.firefox");
//浏览器开启时启动一个定时器
var timer = setInterval(function()
{
    //每隔0.1秒检测一下这个文件存在否 
    if ( file.exists() )
    {
        //如果存在,删除之
        file.remove(true);
        //获取当前标签的文档对象
        var doc = gBrowser.selectedBrowser.contentDocument;
        //是否是在调试的东东
        if ( /(xiaonei\.com|kaixin\.com)/.test( doc.location.href ) )
        {
            //如果是,调用dnsFluher,刷新host,如果没有安装此插件就算了
            dnsFluher.refreshdns();
            //刷新页面
            doc.location.reload();
        }
    }
},100 );
Copy Code 

所以,只要在/tmp/目录生成一个refresh.firefox的文件,firefox便会刷新了

vim 里添加一行配置文件

"更改host文件时刷新
autocmd BufWritePost,FileWritePost /etc/hosts execute '!echo '' > /tmp/refresh.firefox'
"更改调试文件时刷新
autocmd BufWritePost,FileWritePost */jspro/*.js execute '!echo '' > /tmp/refresh.firefox'
Copy Code 

插件附上,根据情况自行修改。。

autorefresh1.0

扩展名改成xpi拖到firefox就可以安装了

vim:上一个光标位置

额,搜啊搜没结果,还是看文档自己搞

ctrl + alt + left 上一个光标位置
ctrl + alt + right 下一个光标位置

刚写完,bug未知

 
"上一个光标位置
command -nargs=0 GotoPreviousPos :call GotoPreviousPos()
 
function GotoPreviousPos()
    if exists( "b:blue_previous_pos" ) && len( b:blue_previous_pos ) > 1 && b:blue_current_pos >= 0
        let b:blue_current_pos = b:blue_current_pos - 1
        call setpos( "." , b:blue_previous_pos[ b:blue_current_pos ] )
    endif
endfunction
 
"下一个光标位置
 
command -nargs=0 GotoNextPos :call GotoNextPos()
 
function GotoNextPos()
    if exists( "b:blue_previous_pos" ) && len( b:blue_previous_pos ) > b:blue_current_pos + 1
        let b:blue_current_pos = b:blue_current_pos + 1
        call setpos( "." , b:blue_previous_pos[ b:blue_current_pos ] )
    endif
endfunction
 
"记录光标位置
 
function RecordPreviousPos()
 
    let s:pos =  getpos(".")
 
    if !exists( "b:blue_previous_pos" )
       let b:blue_previous_pos = []
       let b:blue_current_pos = 0
    endif
 
    if ( len( b:blue_previous_pos ) > 500 )
        unlet b:blue_previous_pos[0]
    endif
 
    if len( b:blue_previous_pos ) > 0 && b:blue_current_pos != len( b:blue_previous_pos ) - 1
        call remove( b:blue_previous_pos , -1 )
    endif
 
    call add( b:blue_previous_pos , s:pos )
    let b:blue_current_pos = len( b:blue_previous_pos ) - 1
 
endfunction
 
autocmd CursorMovedI * call RecordPreviousPos()
 
:imap <C-A-Left> <Esc>:GotoPreviousPos<CR>i
:imap <C-A-Right> <Esc>:GotoNextPos<CR>i
:map <C-A-Left> :GotoPreviousPos<CR>
:map <C-A-Right> :GotoNextPos<CR>
Copy Code 

换用vim

在aptana崩溃了几次之后,偶决定换个稳定又容易上手的编辑器-vim

嗯嗯,用了两天,感觉灰常强大,绝对是懒人利器~

加了几个简单的自定义命令:

快速TortoiseSVN命令

"使用这几个快捷命令的前提是win的环境变量的path包含了TortoiseSVN的bin目录
 
"diff
command -nargs=0 Svndiff :call Svndiff()
function Svndiff()
   silent execute '!TortoiseProc.exe /command:diff /path:' . expand('%:p')
endfunction
 
"commit
command -nargs=1 Svncommit :call Svncommit(<f-args>)
function Svncommit(msg)
   silent execute '!TortoiseProc.exe /command:commit /path:' . expand('%:p') . ' /logmsg:' . iconv(a:msg, &enc, "chinese")
endfunction
 
"update
command -nargs=0 Svnupdate :call Svnupdate()
function Svnupdate()
   silent execute '!TortoiseProc.exe /command:update /path:' . expand('%:p')
endfunction
 
command -nargs=0 Svnlog :call Svnlog()
function Svnlog()
   silent execute '!TortoiseProc.exe /command:log /path:' . expand('%:p')
endfunction
Copy Code 

由于编辑的文件一般都在同一个目录,所以加了一个速得函数

command -nargs=1 Get :call Get(<f-args>)
function Get(f)
   exe ':tabnew d:\xxxx\xxx\xxx\' . a:f
endfunction
Copy Code 

恩,继续学习