2007-03-28
VIM D语言编辑环境
关键字: D DMD GDC VIM
在正文之前,先佩服一下伟大的GFW——又把 blogspot.com 的二级域名给封了。
如果你和我一样经常为了测试D语言的某个特性而写一些小程序来验证想法,而且恰好也使用 VIM 的话,那么本文就是为你准备的
。
首先,VIM7 中自带的D语言语法文件版本很老,请替换为 http://www.vim.org/scripts/script.php?script_id=379 这个支持0.178的。
下面的代码是 VIM 的DMD编译器支持,将其放入 ~/.vim/complier/dmd.vim (for unix-like, Windows 为 $VIMRUNTIME\vim70\compiler\dmd.vim),GDC 用户请将18行的 dmd 替换为 gdmd。
最后,在 ~/.vimrc(Windows 是 $VIMRUNTIME\_vimrc)文件中加入如下两行:
大功告成,现在只需要任意打开一个D文件,在普通模式下按下 F5就可以运行程序,假如文件中存在编译错误的话,VIM会将其加入错误列表,并自动跳到第一个错误所在的行,同时也支持像 clist 列出错误清单这类的 Quickfix 命令。
下面是我的VIM效果:

Happy Vimming!
如果你和我一样经常为了测试D语言的某个特性而写一些小程序来验证想法,而且恰好也使用 VIM 的话,那么本文就是为你准备的
。首先,VIM7 中自带的D语言语法文件版本很老,请替换为 http://www.vim.org/scripts/script.php?script_id=379 这个支持0.178的。
下面的代码是 VIM 的DMD编译器支持,将其放入 ~/.vim/complier/dmd.vim (for unix-like, Windows 为 $VIMRUNTIME\vim70\compiler\dmd.vim),GDC 用户请将18行的 dmd 替换为 gdmd。
dmd.vim 代码
- " Vim compiler file
- " Compiler: DMD Runner
- " Maintainer: oldrev
- " Last Change: 2007/03/28
- if exists("current_compiler")
- finish
- endif
- let current_compiler = "dmd"
- if exists(":CompilerSet") != 2 " older Vim always used :setlocal
- command -nargs=* CompilerSet setlocal
- endif
- let s:cpo_save = &cpo
- set cpo-=C
- CompilerSet makeprg=dmd\ -run\ %
- CompilerSet errorformat=%f:%l:%m
- let &cpo = s:cpo_save
- unlet s:cpo_save
- " vim: nowrap sw=2 sts=2 ts=8 ff=unix:
最后,在 ~/.vimrc(Windows 是 $VIMRUNTIME\_vimrc)文件中加入如下两行:
.vimrc 代码
- :autocmd BufRead,BufNewFile *.d compiler dmd
- :autocmd BufRead,BufNewFile *.d map
:w :make
大功告成,现在只需要任意打开一个D文件,在普通模式下按下 F5就可以运行程序,假如文件中存在编译错误的话,VIM会将其加入错误列表,并自动跳到第一个错误所在的行,同时也支持像 clist 列出错误清单这类的 Quickfix 命令。
下面是我的VIM效果:
Happy Vimming!
评论
sofire
2007-08-06
我把配置文件改成了。
CompilerSet makeprg=dmd\ -run\ %\ 1>&2
CompilerSet errorformat=%f(%l)%m
我用的是linux下的dmd 1.015,错误提示用的是冒号,例如:
array.d(96): Error: cannot assign to static array [11]
makeprg改动的原因是:
运行程序后,在终端上显示输出结果。
如果不加 1>&2 ,结果就不会显示出来
上面的回复有点问题,贴的是_vimrc配置里面的,
和文章的有点出入。文章里面的意思是:
:autocmd BufRead,BufNewFile *.d compiler dmd
:autocmd BufRead,BufNewFile *.d map <f5> :w<cr>:make<cr>
多谢oldrev,原来用make编译程序,能更方便的定位错误。
引用
CompilerSet makeprg=dmd\ -run\ %\ 1>&2
CompilerSet errorformat=%f(%l)%m
我用的是linux下的dmd 1.015,错误提示用的是冒号,例如:
array.d(96): Error: cannot assign to static array [11]
makeprg改动的原因是:
运行程序后,在终端上显示输出结果。
如果不加 1>&2 ,结果就不会显示出来
上面的回复有点问题,贴的是_vimrc配置里面的,
和文章的有点出入。文章里面的意思是:
引用
:autocmd BufRead,BufNewFile *.d compiler dmd
:autocmd BufRead,BufNewFile *.d map <f5> :w<cr>:make<cr>
多谢oldrev,原来用make编译程序,能更方便的定位错误。
sofire
2007-08-04
引用
:autocmd BufRead,BufNewFile *.d map <F5> :w<CR>:!dmd -debug -run %<CR>
:autocmd BufRead,BufNewFile *.d map <F6> :w<CR>:!dmd -debug -unittest -run %<CR>
其实是这样的,查看本页源代码,就能从中找到_vimrc的配置。
替换掉双引号,大于,小于符号就可以了
PS:
代码标签显示得不对,网站bug,试试用quote标签?
而且,显示_vimrc文本的时候很慢,firefox都提示是否停止进行js
qyqx
2007-04-03
引用
我贴出我的 _vimrc 参考一下:
看不到代码,可以发可我吗?谢谢。qyqxt@hotmail.com
oldrev
2007-04-02
引用
我都是照着做的,可是还没搞好,我用的是GVIM7.0 for windows, 一用VIM打开D文件就提示:
"D:\ASM.d" 20L, 382C
找不到映射
请按ENTER或其它命令继续
"D:\ASM.d" 20L, 382C
找不到映射
请按ENTER或其它命令继续
我贴出我的 _vimrc 参考一下:
scriptencoding utf-8
"-----------------------------------------------------------------------
"BaSS vimrc based con ciaran
"-----------------------------------------------------------------------
"-----------------------------------------------------------------------
" terminal setup
"-----------------------------------------------------------------------
" Extra terminal things
" set termencoding=utf-8
"if exists('&t_SI')
" let &t_SI = "\<Esc>]12;lightgoldenrod\x7"
" let &t_EI = "\<Esc>]12;grey80\x7"
"endif
"-----------------------------------------------------------------------
" settings
"-----------------------------------------------------------------------
" Don't be compatible with vi
set nocompatible
" Enable a nice big viminfo file
set viminfo='1000,f1,:1000,/1000
set history=500
" Make backspace delete lots of things
set backspace=indent,eol,start
" Create backups
"set backup
" Show us the command we're typing
set showcmd
" Highlight matching parens
set showmatch
" Search options: incremental search, highlight search
" set hlsearch
" Selective case insensitivity
set ignorecase
set infercase
" Show full tags when doing search completion
set showfulltag
" Speed up macros
set lazyredraw
" No annoying error noises
set noerrorbells
set visualbell t_vb=
if has("autocmd")
autocmd GUIEnter * set visualbell t_vb=
endif
" Try to show at least three lines and two columns of context when
" scrolling
set scrolloff=3
set sidescrolloff=2
" Wrap on these
set whichwrap+=<,>,[,]
" Use the cool tab complete menu
set wildmenu
set wildignore+=*.o,*~,*.obj
set suffixes+=.in,.a
" Allow edit buffers to be hidden
set hidden
" 1 height windows
set winminheight=1
" Enable syntax highlighting
if has("syntax")
syntax on
endif
" Set our fonts
if has("gui_running")
"set guifont=Raize:h10
set guifont=Consolas:h10.5:cANSI
endif
"中文效果测试"
" Try to load a nice colourscheme
" No icky toolbar, menu or scrollbars in the GUI
if has('gui')
set guioptions+=b
" set guioptions-=m
set guioptions-=T
" set guioptions-=l
" set guioptions-=L
" set guioptions-=r
" set guioptions-=R
end
" By default, go for an indent of 4 tab stuff
" set expandtab //讨厌换成空格
set expandtab
set shiftwidth=4
set tabstop=4
" Do clever indent things. Don't make a # force column zero.
set autoindent
set smartindent
inoremap # X<BS>#
" Enable folds
"if has("folding")
" set foldenable
" set foldmethod=indent
"endif
" Syntax when printing
set popt+=syntax:y
" Enable filetype settings
if has("eval")
filetype on
filetype plugin on
filetype indent on
endif
" Enable modelines only on secure vim versions
if (v:version >= 604)
set modeline
else
set nomodeline
endif
" Nice statusbar
set laststatus=2
set statusline=
set statusline+=#%n\ " buffer number
set statusline+=%f\ " file name
set statusline+=%h%1*%m%r%w%0* " flags
set statusline+=\[%{strlen(&ft)?&ft:'none'}, " filetype
set statusline+=%{&encoding}, " encoding
set statusline+=%{&fileformat}] " file format
if filereadable(expand("$VIM/vimfiles/plugin/vimbuddy.vim"))
set statusline+=\ %{VimBuddy()} " vim buddy
endif
set statusline+=%= " right align
set statusline+=0x%-8B\ " current char
set statusline+=%-14.(%l,%c%V%)\ %<%P " offset
"set statusline=%<%f%=\ [%1*%M%*%n%R%H]\ %-19(%3l,%02c%03V%)%O'%02b'
"set encoding=unicode
set encoding=utf-8
set fileencodings=utf-8,chinese,ucs-bom
set ambiwidth=double
set langmenu=zh_CN.utf-8
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
language messages zh_CN.utf-8
filetype plugin on
filetype on
filetype indent on
set autoindent
set cindent shiftwidth=4
set autoindent shiftwidth=4
"set mouse=a " use the mouse
set sm
set cin
" DISPLAY OPTIONS
set number
set ruler
"set notitle
if (has("gui_running"))
set wrap
set showtabline=2
colorscheme torte
set cursorline
"hi LineNr guibg=darkgrey ctermbg=darkgrey guifg=white ctermfg=grey
if has('multi_byte_ime')
highlight Cursor guibg=white guifg=black
highlight CursorIM guibg=yellow guifg=black
endif
else
set wrap
colorscheme torte
endif
let Tlist_Auto_Open=1
if version >= 603
set helplang=cn
endif
map <F2> :set hlsearch!<CR>
map <F7> :wa<CR>:make<CR>
imap <F7> <ESC>:wa<CR>:make<CR>
imap <F3> <ESC>:wa<CR>a
map <F3> :wa<CR>
nnoremap <silent> <F8> :TlistToggle<CR>
nnoremap <C-Enter> :WinFullScreen<CR>
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
let eq = ''
if $VIMRUNTIME =~ ' '
if &sh =~ '\<cmd'
let cmd = '""' . $VIMRUNTIME . '\diff"'
let eq = '"'
else
let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
endif
else
let cmd = $VIMRUNTIME . '\diff'
endif
silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
endfunction
:autocmd BufRead,BufNewFile *.cmake,CMakeLists.txt,*.cmake.in runtime! indent/cmake.vim
:autocmd BufRead,BufNewFile *.cmake,CMakeLists.txt,*.cmake.in setf cmake
:autocmd BufRead,BufNewFile *.py,*.python map <F5> :w<CR>:!python %<CR>
:autocmd BufRead,BufNewFile *.rb,*.ruby map <F5> :w<CR>:!ruby %<CR>
:autocmd BufRead,BufNewFile *.d map <F5> :w<CR>:!dmd -debug -run %<CR>
:autocmd BufRead,BufNewFile *.d map <F6> :w<CR>:!dmd -debug -unittest -run %<CR>
:autocmd BufRead,BufNewFile *.c,*.cpp,*.cxx,*.cc map <F5> :wa<CR>:!gcc %<CR> :!%<<CR>
:autocmd BufRead,BufNewFile SConstruct,SConscript runtime! indent/python.vim
:autocmd BufRead,BufNewFile SConstruct,SConscript setfiletype python
:autocmd BufRead,BufNewFile SConstruct map <F5> :wa<CR>:!scons -Q<CR>
qyqx
2007-04-02
我都是照着做的,可是还没搞好,我用的是GVIM7.0 for windows, 一用VIM打开D文件就提示:
"D:\ASM.d" 20L, 382C
找不到映射
请按ENTER或其它命令继续
"D:\ASM.d" 20L, 382C
找不到映射
请按ENTER或其它命令继续
oldrev
2007-03-30
F5键要在普通(Normal)模式下
要想在插入模式下也能按F5运行,请将下面的脚本加入 .vimrc(或_vimrc):
:autocmd BufRead,BufNewFile *.d imap <ESC>:w:make
要想在插入模式下也能按F5运行,请将下面的脚本加入 .vimrc(或_vimrc):
:autocmd BufRead,BufNewFile *.d imap <ESC>:w:make
smithfox
2007-03-30
I try vim, thank you.
But can't press F5 to debug.
But can't press F5 to debug.
oldrev
2007-03-30
引用
为什么用VIM打开d文件,提示说没有映射,按F5没效果.
只要按上面的步骤做应该没问题
qyqx
2007-03-30
为什么用VIM打开d文件,提示说没有映射,按F5没效果.
ideage
2007-03-30
试验了.很好.的确方便.F5搞定了.写测试项目合适.
oldrev
2007-03-30
难道没人用vim?
发表评论
- 浏览: 105148 次
- 性别:

- 来自: 昆明

- 详细资料
搜索本博客
我的相册
Screenshot
共 1 张
共 1 张
最近加入圈子
最新评论
-
出色的开源项目管理软件— ...
我也是前几天刚刚从trac换到redmine,感觉好多了,trac有的redmi ...
-- by danielking -
转贴:鲁迅未收入全集的文 ...
借问酒家何处有,牧童遥指杏花村
-- by hqs7636 -
Range Coding 的 D 实现
引用oldrev 2008-01-12LZMA SDK 只是一个 LZMA 算法 ...
-- by oldrev -
D 静态数组初始化大bug
看看日期好伐?
-- by oldrev -
D新闻组里的天才代码
没看过产生的汇编代码,测试了是可行的。如果用宏来实现就完美了
-- by oldrev






评论排行榜