Skip to content

Instantly share code, notes, and snippets.

@hotoo
Created July 20, 2010 05:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hotoo/482560 to your computer and use it in GitHub Desktop.
Save hotoo/482560 to your computer and use it in GitHub Desktop.
" cmdhere plugin for NERDTree.
" put this in $VIM/vimfiles/nerdtree_plugin/cmdhere.vim
" @author 闲耘™ (hotoo.cn[AT]gmail.com)
" @version 1.0 2010/07/20
if exists("g:loaded_nerdtree_cmdhere")
finish
endif
let g:loaded_nerdtree_cmdhere = 1
function! NERDTreeCmdhere()
let node = g:NERDTreeFileNode.GetSelected()
if executable("chcp")
let code_page = 'cp' . matchstr(system("chcp"), "\\d\\+")
else
" If chcp doesn't work, set its value manually here.
let code_page = 'cp936'
endif
if has('win32') && !has('win32unix') && (&enc!=code_page)
let path = iconv(node.path.str({'escape':1}), &enc, code_page)
endif
if has('win32')
if node.path.isDirectory
exec ":!start cmd /c cmd /k pushd " . path
else
exec ":!start cmd /c cmd /k pushd " . path . "\\.."
endif
endif
endfunction
autocmd filetype nerdtree command! -nargs=0 -buffer Cmd :call NERDTreeCmdhere()
autocmd filetype nerdtree command! -nargs=0 -buffer Cmdhere :call NERDTreeCmdhere()
if has("win32")
" Open command(cmd) window.
command -nargs=0 Cmd :!start cmd
command -nargs=0 Cmdhere :!start cmd
endif
@hotoo
Copy link
Author

hotoo commented Jul 20, 2010

安装:

  1. cmdhere.vim 放至 $VIM/vimfiles/nerdtree_plugin/ 目录下;
  2. cmdhere.vimrc 添加到 vimrc 中。

用法:
在打开的文件或 NERDTree 中 执行 :Cmd 或 :Cmdhere 命令会启动 cmd 命令行,
起始目录为文件所在目录或 NERDTree 选中的目录。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment