如何不写makefile来打开quickfix

Vim、Emacs配置和使用
回复
头像
hbxtght
帖子: 191
注册时间: 2011-01-17 22:23

如何不写makefile来打开quickfix

#1

帖子 hbxtght » 2011-09-29 18:38

RT,人家说quickfix要结合make才可以使用,但是现在我不想写makefile文件,现在我一般就写一个源文件,每次都要写makefile太麻烦了,还有一种方法是设置makeprg,我现在想的是,可不可以根据文件类型的不同,自动设置不同的makeprg呢(比如c,c++)?这样我在源文件里边直接make就行了 :em03
苏东坡问佛印道:“人人皆念观世音菩萨,观世音菩萨念谁?”
佛印答道:“念观世音菩萨。”
苏东坡诧异:“为何亦念观世音菩萨?”
曰:“求人不如求己。”
头像
hbxtght
帖子: 191
注册时间: 2011-01-17 22:23

Re: 如何不写makefile来打开quickfix

#2

帖子 hbxtght » 2011-09-29 19:26

看到一个外国人是这么设置的

代码: 全选

au FileType c set makeprg=gcc\ %
au FileType cpp set makeprg=g++\ %
可以了 :em05
苏东坡问佛印道:“人人皆念观世音菩萨,观世音菩萨念谁?”
佛印答道:“念观世音菩萨。”
苏东坡诧异:“为何亦念观世音菩萨?”
曰:“求人不如求己。”
头像
lilydjwg
论坛版主
帖子: 4258
注册时间: 2009-04-11 23:46
系统: Arch Linux
联系:

Re: 如何不写makefile来打开quickfix

#3

帖子 lilydjwg » 2011-09-29 19:31

其实 make 不是非要有 Makefile 才能用的:

代码: 全选

:!make %:r
头像
hbxtght
帖子: 191
注册时间: 2011-01-17 22:23

Re: 如何不写makefile来打开quickfix

#4

帖子 hbxtght » 2011-09-29 20:07

lilydjwg 写了:其实 make 不是非要有 Makefile 才能用的:

代码: 全选

:!make %:r
又学习了 :em11
苏东坡问佛印道:“人人皆念观世音菩萨,观世音菩萨念谁?”
佛印答道:“念观世音菩萨。”
苏东坡诧异:“为何亦念观世音菩萨?”
曰:“求人不如求己。”
头像
Fermat618
帖子: 728
注册时间: 2008-12-28 16:01

Re: 如何不写makefile来打开quickfix

#5

帖子 Fermat618 » 2011-09-30 20:53

lilydjwg 写了:其实 make 不是非要有 Makefile 才能用的:

代码: 全选

:!make %:r
这个我还真不知道。

不过现在也没什么问题了,我用一个脚本来设定makeprg,做完make立即复原makeprg。
爱因斯坦会弹钢琴
爱因斯坦会拉小提琴
爱因斯坦会骑自行车
头像
hbxtght
帖子: 191
注册时间: 2011-01-17 22:23

Re: 如何不写makefile来打开quickfix

#6

帖子 hbxtght » 2011-10-01 1:51

Fermat618 写了:
lilydjwg 写了:其实 make 不是非要有 Makefile 才能用的:

代码: 全选

:!make %:r
这个我还真不知道。

不过现在也没什么问题了,我用一个脚本来设定makeprg,做完make立即复原makeprg。
想观摩一下.. :em01
苏东坡问佛印道:“人人皆念观世音菩萨,观世音菩萨念谁?”
佛印答道:“念观世音菩萨。”
苏东坡诧异:“为何亦念观世音菩萨?”
曰:“求人不如求己。”
头像
Fermat618
帖子: 728
注册时间: 2008-12-28 16:01

Re: 如何不写makefile来打开quickfix

#7

帖子 Fermat618 » 2011-10-01 11:58

hbxtght 写了:
Fermat618 写了:
lilydjwg 写了:其实 make 不是非要有 Makefile 才能用的:

代码: 全选

:!make %:r
这个我还真不知道。

不过现在也没什么问题了,我用一个脚本来设定makeprg,做完make立即复原makeprg。
想观摩一下.. :em01

代码: 全选

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>

不知道怎么指定代码类型是viml, 凑和着看吧。
原来的代码不知道从哪里抄来的了。但原来的代码没有用makeprg来做,没有quickfix,我改了一下,可以用quickfix了。
爱因斯坦会弹钢琴
爱因斯坦会拉小提琴
爱因斯坦会骑自行车
回复