GVIM脚本——打开当前文件所在位置

function OpenFileLocation()
	if ( expand("%") != "" )
		execute "!start explorer /select, %" 
	else
		execute "!start explorer /select, %:p:h"
	endif
endfunction

map gb <ESC>:call OpenFileLocation()<CR>

"我的第一个VIM脚本。
"功能:当前文件所在位置,同时不阻塞当前窗口。

把这个脚本做成插件也很简单,只要保存成*.vim文件, 再放到插件目录(如:C:\Program Files\Vim\vim73\plugin)下就好了:

"Vim plugin for open current file's loction
"Maintainer: ShengFu Li
"Last Change: 2012 Sep 30


if exists("loaded_OpenFileLocation")
  finish
endif
let loaded_OpenFileLocation = 1

function OpenFileLocation()
	if ( expand("%") != "" )
		execute "!start explorer /select, %" 
	else
		execute "!start explorer /select, %:p:h"
	endif
endfunction
map <leader>o <ESC>:call OpenFileLocation()<CR>


你可能感兴趣的:(function,脚本,vim)