Difference between revisions of "D in Vim"
(Added info about UltiSnips/DSnips (please add info about DCD too)) |
(More complete and better-documented errorformat) |
||
(9 intermediate revisions by 8 users not shown) | |||
Line 1: | Line 1: | ||
Vim features and plugins useful for D coding. | Vim features and plugins useful for D coding. | ||
+ | |||
+ | =Installing Vundle= | ||
+ | |||
+ | Many Vim plugins require a plugin manager for installation. | ||
+ | [https://github.com/gmarik/Vundle.vim Vundle] is one such plugin manager. | ||
+ | |||
+ | To install Vundle see the [https://github.com/gmarik/Vundle.vim#quick-start Quick Start] section on Vundle's site. | ||
=UltiSnips= | =UltiSnips= | ||
Line 25: | Line 32: | ||
* Copy the d.snippets file to UltiSnips user snippets directory. On Linux this should be ~/.vim/UltiSnips. <br/><br/> If you don't know where the user snippets directory is, open a D file and type the :UltiSnipsEdit command (after UltiSnips is installed); this will open a user d.snippets file which you can replace by the DSnips version of d.snippets. | * Copy the d.snippets file to UltiSnips user snippets directory. On Linux this should be ~/.vim/UltiSnips. <br/><br/> If you don't know where the user snippets directory is, open a D file and type the :UltiSnipsEdit command (after UltiSnips is installed); this will open a user d.snippets file which you can replace by the DSnips version of d.snippets. | ||
+ | =Dutyl= | ||
+ | The [https://github.com/idanarye/vim-dutyl Dutyl] plugin integrates D tools such as [https://github.com/Hackerpilot/DCD/ DCD], DUB and DScanner to provide autocompletion, syntax checking, documentation search and more features. | ||
+ | |||
+ | =Vebugger= | ||
+ | The [https://github.com/idanarye/vim-vebugger Vebugger] plugin acts as a frontend for command line debuggers, and can be used to debug D programs with GDB. You'll need to use :VBGstartGDBForD to debug D programs. | ||
+ | |||
+ | =Tagbar= | ||
+ | |||
+ | It also possible to display a tagbar of all all declared functions, classes etc. | ||
+ | Please follow the instructions of [https://github.com/majutsushi/tagbar tagbar]'s [https://github.com/majutsushi/tagbar/wiki#d Wiki]. | ||
− | = | + | =Highlighting Phobos= |
+ | The [https://github.com/Sirsireesh/vim-dlang-phobos-highlighter vim-dlang-phobos-highlighter] plugin allows highlighting of Phobos (functions, templates and types) and user defined functions, along with version identifiers. | ||
+ | |||
+ | =Neovim= | ||
+ | |||
+ | With the rise of Neovim, [https://github.com/ncm2/ncm2-d ncm2-d] or [https://github.com/landaire/deoplete-d deoplete-d] can be used for auto-completion. | ||
+ | |||
+ | = Errorformat = | ||
+ | |||
+ | With this autocmd, Vim will parse error messages from the D compiler and from uncaught exceptions (including failed assertions in unit tests): | ||
+ | |||
+ | <pre> | ||
+ | " errorformat entries: | ||
+ | " - Errors from -verrors=spec (ignored) | ||
+ | " - Uncaught exceptions (e.g., from unit tests) | ||
+ | " - Errors in string mixins | ||
+ | " - Normal compile errors | ||
+ | autocmd FileType d setlocal errorformat= | ||
+ | \%-G\(spec:%*[0-9]\)\ %m, | ||
+ | \%*[^@]@%f\(%l\):\ %m, | ||
+ | \%f-mixin-%*[0-9]\(%l\\,%c\):\ %m, | ||
+ | \%f-mixin-%*[0-9]\(%l\):\ %m, | ||
+ | \%f\(%l\\,%c\):\ %m, | ||
+ | \%f\(%l\):\ %m | ||
+ | </pre> | ||
+ | |||
+ | = Unit Testing = | ||
+ | |||
+ | The following function runs unittests on the current file and displays coverage | ||
+ | information as a split window bound to left of the source window; | ||
+ | |||
+ | <pre> | ||
+ | function! DTest() | ||
+ | let l:fn = substitute(expand('%:r'), '/', '-', 'g') . '.lst' | ||
+ | call delete(l:fn) | ||
+ | cexpr system('dmd -cov -unittest -main -run ' . expand('%')) | ||
+ | if filereadable(l:fn) | ||
+ | normal gg | ||
+ | execute '13vsplit' l:fn | ||
+ | normal gg | ||
+ | set scrollbind | ||
+ | normal ^Wl | ||
+ | set scrollbind | ||
+ | endif | ||
+ | endfunction | ||
+ | </pre> | ||
+ | (note the ^W is a an actual CTRL-W, inserted with CTRL-V, CTRL-W) | ||
+ | |||
+ | <pre>autocmd FileType d nnoremap <f8> :call DTest()<cr></pre> | ||
− | |||
− | |||
− | + | [[Category:Text editors]] |
Latest revision as of 21:46, 12 November 2021
Vim features and plugins useful for D coding.
Contents
Installing Vundle
Many Vim plugins require a plugin manager for installation. Vundle is one such plugin manager.
To install Vundle see the Quick Start section on Vundle's site.
UltiSnips
UltiSnips is a Vim snippet plugin with D support. It makes it possible to complete tasks such as writing a loop, wrapping code in try/catch or adding an operator in a few keystrokes.
Installing UltiSnips:
- Make sure you have a plugin manager such as Vundle installed.
- See the Quick Start section at UltiSnips site.
DSnips
DSnips is a (greatly) improved version of UltiSnips D snippets. It covers almost all D features and its snippets are designed to work together (e.g. can be used within one another or in chains). See DSnips reference
Installing DSnips:
- You need to have UltiSnips installed first.
git clone https://github.com/kiith-sa/DSnips.git
- Copy the d.snippets file to UltiSnips user snippets directory. On Linux this should be ~/.vim/UltiSnips.
If you don't know where the user snippets directory is, open a D file and type the :UltiSnipsEdit command (after UltiSnips is installed); this will open a user d.snippets file which you can replace by the DSnips version of d.snippets.
Dutyl
The Dutyl plugin integrates D tools such as DCD, DUB and DScanner to provide autocompletion, syntax checking, documentation search and more features.
Vebugger
The Vebugger plugin acts as a frontend for command line debuggers, and can be used to debug D programs with GDB. You'll need to use :VBGstartGDBForD to debug D programs.
Tagbar
It also possible to display a tagbar of all all declared functions, classes etc. Please follow the instructions of tagbar's Wiki.
Highlighting Phobos
The vim-dlang-phobos-highlighter plugin allows highlighting of Phobos (functions, templates and types) and user defined functions, along with version identifiers.
Neovim
With the rise of Neovim, ncm2-d or deoplete-d can be used for auto-completion.
Errorformat
With this autocmd, Vim will parse error messages from the D compiler and from uncaught exceptions (including failed assertions in unit tests):
" errorformat entries: " - Errors from -verrors=spec (ignored) " - Uncaught exceptions (e.g., from unit tests) " - Errors in string mixins " - Normal compile errors autocmd FileType d setlocal errorformat= \%-G\(spec:%*[0-9]\)\ %m, \%*[^@]@%f\(%l\):\ %m, \%f-mixin-%*[0-9]\(%l\\,%c\):\ %m, \%f-mixin-%*[0-9]\(%l\):\ %m, \%f\(%l\\,%c\):\ %m, \%f\(%l\):\ %m
Unit Testing
The following function runs unittests on the current file and displays coverage information as a split window bound to left of the source window;
function! DTest() let l:fn = substitute(expand('%:r'), '/', '-', 'g') . '.lst' call delete(l:fn) cexpr system('dmd -cov -unittest -main -run ' . expand('%')) if filereadable(l:fn) normal gg execute '13vsplit' l:fn normal gg set scrollbind normal ^Wl set scrollbind endif endfunction
(note the ^W is a an actual CTRL-W, inserted with CTRL-V, CTRL-W)
autocmd FileType d nnoremap <f8> :call DTest()<cr>