
如何不写makefile来打开quickfix
- hbxtght
- 帖子: 191
- 注册时间: 2011-01-17 22:23
如何不写makefile来打开quickfix
RT,人家说quickfix要结合make才可以使用,但是现在我不想写makefile文件,现在我一般就写一个源文件,每次都要写makefile太麻烦了,还有一种方法是设置makeprg,我现在想的是,可不可以根据文件类型的不同,自动设置不同的makeprg呢(比如c,c++)?这样我在源文件里边直接make就行了 

苏东坡问佛印道:“人人皆念观世音菩萨,观世音菩萨念谁?”
佛印答道:“念观世音菩萨。”
苏东坡诧异:“为何亦念观世音菩萨?”
曰:“求人不如求己。”
佛印答道:“念观世音菩萨。”
苏东坡诧异:“为何亦念观世音菩萨?”
曰:“求人不如求己。”
- hbxtght
- 帖子: 191
- 注册时间: 2011-01-17 22:23
Re: 如何不写makefile来打开quickfix
看到一个外国人是这么设置的
可以了 
代码: 全选
au FileType c set makeprg=gcc\ %
au FileType cpp set makeprg=g++\ %

苏东坡问佛印道:“人人皆念观世音菩萨,观世音菩萨念谁?”
佛印答道:“念观世音菩萨。”
苏东坡诧异:“为何亦念观世音菩萨?”
曰:“求人不如求己。”
佛印答道:“念观世音菩萨。”
苏东坡诧异:“为何亦念观世音菩萨?”
曰:“求人不如求己。”
- lilydjwg
- 论坛版主
- 帖子: 4258
- 注册时间: 2009-04-11 23:46
- 系统: Arch Linux
- 联系:
Re: 如何不写makefile来打开quickfix
其实 make 不是非要有 Makefile 才能用的:
代码: 全选
:!make %:r
- hbxtght
- 帖子: 191
- 注册时间: 2011-01-17 22:23
Re: 如何不写makefile来打开quickfix
又学习了lilydjwg 写了:其实 make 不是非要有 Makefile 才能用的:代码: 全选
:!make %:r

苏东坡问佛印道:“人人皆念观世音菩萨,观世音菩萨念谁?”
佛印答道:“念观世音菩萨。”
苏东坡诧异:“为何亦念观世音菩萨?”
曰:“求人不如求己。”
佛印答道:“念观世音菩萨。”
苏东坡诧异:“为何亦念观世音菩萨?”
曰:“求人不如求己。”
- Fermat618
- 帖子: 728
- 注册时间: 2008-12-28 16:01
Re: 如何不写makefile来打开quickfix
这个我还真不知道。lilydjwg 写了:其实 make 不是非要有 Makefile 才能用的:代码: 全选
:!make %:r
不过现在也没什么问题了,我用一个脚本来设定makeprg,做完make立即复原makeprg。
爱因斯坦会弹钢琴
爱因斯坦会拉小提琴
爱因斯坦会骑自行车
爱因斯坦会拉小提琴
爱因斯坦会骑自行车
- hbxtght
- 帖子: 191
- 注册时间: 2011-01-17 22:23
Re: 如何不写makefile来打开quickfix
想观摩一下..Fermat618 写了:这个我还真不知道。lilydjwg 写了:其实 make 不是非要有 Makefile 才能用的:代码: 全选
:!make %:r
不过现在也没什么问题了,我用一个脚本来设定makeprg,做完make立即复原makeprg。

苏东坡问佛印道:“人人皆念观世音菩萨,观世音菩萨念谁?”
佛印答道:“念观世音菩萨。”
苏东坡诧异:“为何亦念观世音菩萨?”
曰:“求人不如求己。”
佛印答道:“念观世音菩萨。”
苏东坡诧异:“为何亦念观世音菩萨?”
曰:“求人不如求己。”
- Fermat618
- 帖子: 728
- 注册时间: 2008-12-28 16:01
Re: 如何不写makefile来打开quickfix
hbxtght 写了:想观摩一下..Fermat618 写了:这个我还真不知道。lilydjwg 写了:其实 make 不是非要有 Makefile 才能用的:代码: 全选
:!make %:r
不过现在也没什么问题了,我用一个脚本来设定makeprg,做完make立即复原makeprg。
代码: 全选
func! CompileGcc()
exec "w"
let compilecmd="gcc "
let compileflag="-o %< "
if search("mpi\.h") != 0
let compilecmd = "!mpicc "
endif
if search("glut\.h") != 0
let compileflag .= " -lglut -lGLU -lGL "
endif
if search("cv\.h") != 0
let compileflag .= " -lcv -lhighgui -lcvaux "
endif
if search("omp\.h") != 0
let compileflag .= " -fopenmp "
endif
if search("math\.h") != 0
let compileflag .= " -lm "
endif
compiler gcc
let s:oldmp = &makeprg
let &makeprg = compilecmd." % ".compileflag
make
let &makeprg = s:oldmp
" exec compilecmd." % ".compileflag
endfunc
func! CompileGpp()
exec "w"
let compilecmd="g++ "
let compileflag="-o %< "
if search("mpi\.h") != 0
let compilecmd = "!mpic++ "
endif
if search("glut\.h") != 0
let compileflag .= " -lglut -lGLU -lGL "
endif
if search("cv\.h") != 0
let compileflag .= " -lcv -lhighgui -lcvaux "
endif
if search("omp\.h") != 0
let compileflag .= " -fopenmp "
endif
if search("math\.h") != 0
let compileflag .= " -lm "
endif
compiler gcc
let s:oldmp = &makeprg
let &makeprg = compilecmd." % ".compileflag
make
let &makeprg = s:oldmp
" exec compilecmd." % ".compileflag
endfunc
func! RunPython()
exec "!python %"
endfunc
func! CompileJava()
exec "!javac %"
endfunc
func! CompileCode()
exec "w"
if &filetype == "cpp"
exec "call CompileGpp()"
elseif &filetype == "c"
exec "call CompileGcc()"
elseif &filetype == "python"
exec "call RunPython()"
elseif &filetype == "java"
exec "call CompileJava()"
endif
endfunc
func! RunResult()
exec "w"
if search("mpi\.h") != 0
exec "!mpirun -np 4 ./%<"
elseif &filetype == "cpp"
exec "! ./%<"
elseif &filetype == "c"
exec "! ./%<"
elseif &filetype == "python"
exec "call RunPython"
elseif &filetype == "java"
exec "!java %<"
endif
endfunc
noremap <F7> :call CompileCode()<CR>
noremap <Leader>k :call CompileCode()<CR>
inoremap <F7> <ESC>:call CompileCode()<CR>
vnoremap <F7> <ESC>:call CompileCode()<CR>
noremap <F5> :call RunResult()<CR>
noremap <Leader>r :call RunResult()<CR>
原来的代码不知道从哪里抄来的了。但原来的代码没有用makeprg来做,没有quickfix,我改了一下,可以用quickfix了。
爱因斯坦会弹钢琴
爱因斯坦会拉小提琴
爱因斯坦会骑自行车
爱因斯坦会拉小提琴
爱因斯坦会骑自行车