dddpppbox 发表于 2006-2-4 20:51:58

vim 怎样用一键编译运行?

我经常写一些 不超过500行的小程序,用windows 中的 IDE感觉很方便,一点鼠标就可以编译运行,
现在我打算慢慢转入LINUX,不知怎样设置VIM可以像IDE那样一键编译运行?

BOoRFGOnZ 发表于 2006-2-4 21:27:22

既然都用了 linux了。。这点就不用了吧 :mrgreen:

druggo 发表于 2006-2-4 21:58:47

可以2步:)
编译
:make
执行
:!./程序名

dddpppbox 发表于 2006-2-5 00:15:08

那makefile怎么写, 要一次写一个?

其实这个2步我还是觉得麻烦,这样要敲10多下键盘,不如点一下鼠标来得干脆,

有没有高人写的宏一类的东西?
使VIM可以一次编译运行?

BOoRFGOnZ 发表于 2006-2-5 07:45:31

emacs

dddpppbox 发表于 2006-2-12 19:55:41

我的.vimrc 推荐给学生朋友

set nocompatible
"source $VIMRUNTIME/vimrc_example.vim
"source $VIMRUNTIME/mswin.vim
"source $VIMRUNTIME/gvimrc_example.vim

"if version > 603
   set helplang=cn
"endif

if !exists("syntax_on")
    syntax on
endif

" 设置跳格距离
set tabstop=4
" *****************************
set showmatch
set matchtime=1
set makeprg=g++\ -g\ %
" 设置自动缩进格数
set shiftwidth=4
" 打开自动缩进功能
set autoindent
"设置语法高亮风格

"设置退格键为普通模式
set backspace=2

"设定自动换行
set wrap

"设置括号匹配
"set sm

" 断行设置
set lbr " 不在单词中间断行
set fo+=mB " 打开断行模式对双字节语言的支持

" 文件浏览器
let g:winManagerWindowLayout = "FileExplorer"

" 把list的窗口放在右边,免得和文件浏览器冲突
let Tlist_Use_Right_Window=1

let &termencoding = &encoding
"set encoding=utf-8
set fileencodings=gbk,gb2312,utf-8,ucs-bom,cp936

"----------------below for txt file
augroup filetypedetect
au BufNewFile,BufRead *.* setf ztxt
augroup END


"au BufWinLeave *.txt mkview
"au BufWinEnter *.txt silent loadview


"colorscheme InkPot

set nu

filetype on

let Tlist_Ctags_Cmd = 'd:\ctags\ctags.exe'

set guifont=新宋体:h10:cGB2312

au BufWritePost * filet detect

"behave mswin

set diffexpr=MyDiff()
function MyDiff()
let opt = '-a --binary '
if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
let arg1 = v:fname_in
if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
let arg2 = v:fname_new
if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
let arg3 = v:fname_out
if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
if &sh =~ '\<cmd'
    silent execute '!""C:\Program Files\Vim\vim63\diff" ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . '"'
else
    silent execute '!C:\Program" Files\Vim\vim63\diff" ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3
endif
endfunction


" 映射F5为make
noremap <silent> <F3> "+y
inoremap <silent> <F2> :<Esc>ggVG<CR>
noremap <silent> <F2> :<Esc>ggVG<CR>
noremap <silent> <F4> ::w<CR>
inoremap <silent> <F4> <Esc>:w<CR>
noremap <silent> <F5> ::make<CR>
noremap <silent> <F6> ::!a.exe<CR>
"noremap <silent> <F11> ::

" 映射F8使用Tlist
nnoremap <silent> <F8> :Tlist<CR>
" 映射F7调用文件浏览器
nnoremap <silent> <F7> :WMToggle<CR>

if has("autocmd")

" 自动检测文件类型并加载相应的设置
filetype plugin indent on

" Python 文件的一般设置,比如不要 tab 等
autocmd FileType python setlocal et | setlocal sta | setlocal sw=4

" Python Unittest 的一些设置
" 可以让我们在编写 Python 代码及 unittest 测试时不需要离开 vim
" 键入 :make 或者点击 gvim 工具条上的 make 按钮就自动执行测试用例
autocmd FileType python compiler pyunit
"autocmd FileType python setlocal makeprg=python\ D:\Downloads\Programs\gVim\vim\skeleton\alltests.py
autocmd FileType python setlocal makeprg=python\ %
autocmd BufNewFile,BufRead test*.py setlocal makeprg=python\ %

" 自动使用新文件模板
autocmd BufNewFile test*.py 0r D:\Downloads\Programs\gVim\vim\skeleton\test.py
autocmd BufNewFile alltests.py 0r D:\Downloads\Programs\gVim\vim\skeleton\alltests.py
autocmd BufNewFile *.py 0r D:\Downloads\Programs\gVim\vim\skeleton\skeleton.py

autocmd BufNewFile *.build 0r $HOME\template.build

autocmd BufNewFile *.cs 0r $HOME\template.cs

endif
"
"augroup c_prog
"   au!
"   fun! CFold()
"      set foldmethod=syntax
"      syntax region functionFold start="\(^\({\|\S.*{\)$\n\)\@<=\_[^}]" end="\(^{.*\)\@<!$\n\(^}\)\@=" transparent fold
"      syntax region commentFold start="/\*" end="\*/" transparent fold keepend
"      syntax region commentFold2 start="^\(^//.*$\n\)\@<!//.*\(\n//\)\@=$" end="^\(^//.*$\n\)\@<=//.*\(\n//\)\@!$" transparent fold keepend
"   endfun
"   autocmd FileType cs,cpp,c call CFold()
"augroup END   
"
augroup python_prog
au!
fun! Python_fold()
    execute 'syntax clear pythonStatement'
    execute 'syntax keyword pythonStatement break continue del'
    execute 'syntax keyword pythonStatement except exec finally'
    execute 'syntax keyword pythonStatement pass print raise'
    execute 'syntax keyword pythonStatement return try'
    execute 'syntax keyword pythonStatement global assert'
    execute 'syntax keyword pythonStatement lambda yield'
    execute 'syntax match pythonStatement /\<def\>/ nextgroup=pythonFunction skipwhite'
    execute 'syntax match pythonStatement /\<class\>/ nextgroup=pythonFunction skipwhite'
    execute 'syntax region pythonFold start="^\z(\s*\)\%(.*:\s*\%(#.*$\)\?\)" end="^\%(\n*\z1\s\)\@!" transparent fold'
    execute 'syntax sync minlines=2000 maxlines=4000'
    set autoindent
    set foldmethod=syntax
    " set foldopen=all foldclose=all
    set foldtext=substitute(getline(v:foldstart),'\\t','\ \ \ \ ','g').'\ \ ('.(v:foldend-v:foldstart+1).'\ lines)'
    set fillchars=vert:\|,fold:\
    set tabstop=4 shiftwidth=4 "nowrap
endfun
autocmd FileType python call Python_fold()
augroup END

dddpppbox 发表于 2006-2-12 19:59:14

<F4> 保存 <F5> 编译 (C++程序) <F6> 运行 a.exe
<F2> 全选 <F3> 复制
这样的话,还是需要三次按键,感觉不太完美,谁能再帮我改进一下?

--这个是WINDOWS下的 vimrc,是从UBUNTU论坛上得到的,然后自己又修改了一点
页: [1]
查看完整版本: vim 怎样用一键编译运行?