免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1730 | 回复: 0

[C] vim插件-带参数运行c [复制链接]

论坛徽章:
0
发表于 2013-05-07 15:36 |显示全部楼层
本帖最后由 blackfur 于 2013-10-23 22:36 编辑

“run-arg.vim
  1. "vim global plugin for run with argments

  2. "define global sign
  3. if exists("g:loaded_runarg")
  4.   finish
  5. endif
  6. let g:loaded_runarg= 1

  7. "backup original settings
  8. let s:save_cpo = &cpo
  9. set cpo&vim

  10. "map and menu
  11. if !hasmapto('<Plug>RunargRa')
  12.   map <unique> <Leader>ra  <Plug>RunargRa
  13. endif
  14. noremap <unique> <script> <Plug>RunargRa  <SID>Ra

  15. noremenu <script> Plugin.Run\ With\ Arguments      <SID>Ra

  16. noremap <SID>Ra :call <SID>Ra(expand("%:p:h"),expand("%:t:r"),expand("%:e"))<CR>

  17. "define func
  18. function s:Ra(filePath,fileName,fileExtension)
  19.         let arg=input("Run ".a:fileName." with arguments: ")
  20.         exe "w"
  21.         if a:fileExtension=="c"
  22.                 let compiler="gcc"
  23.         elseif a:fileExtension=="cpp"
  24.                 let compiler="g++"
  25.         endif
  26.         exe "!".compiler." -o ".a:filePath."\\".a:fileName.".out ".a:filePath."\\".a:fileName.".".a:fileExtension."&&".a:filePath."\\".a:fileName.".out ".arg
  27.         echo "!".a:filePath."\\".a:fileName.".out ".arg
  28. endfunction

  29. "define a command
  30. if !exists(":Rwa")
  31.   command -nargs=0  Rwa :call s:Ra(expand("%:p:h"),expand("%:t:r"),expand("%:e"))
  32. endif

  33. "restore setting
  34. let &cpo = s:save_cpo
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP