2 " Description: Vim syntax file for Rust
3 " Maintainer: Chris Morgan <me@chrismorgan.info>
4 " Maintainer: Kevin Ballard <kevin@sb.org>
5 " Last Change: May 27, 2014
7 if exists("b:did_ftplugin")
10 let b:did_ftplugin = 1
17 " The rust source code at present seems to typically omit a leader on /*!
18 " comments, so we'll use that as our default, but make it easy to switch.
19 " This does not affect indentation at all (I tested it with and without
20 " leader), merely whether a leader is inserted by default or not.
21 if exists("g:rust_bang_comment_leader") && g:rust_bang_comment_leader == 1
22 " Why is the `,s0:/*,mb:\ ,ex:*/` there, you ask? I don't understand why,
23 " but without it, */ gets indented one space even if there were no
24 " leaders. I'm fairly sure that's a Vim bug.
25 setlocal comments=s1:/*,mb:*,ex:*/,s0:/*,mb:\ ,ex:*/,:///,://!,://
27 setlocal comments=s0:/*!,m:\ ,ex:*/,s1:/*,mb:*,ex:*/,:///,://!,://
29 setlocal commentstring=//%s
30 setlocal formatoptions-=t formatoptions+=croqnl
31 " j was only added in 7.3.541, so stop complaints about its nonexistence
32 silent! setlocal formatoptions+=j
34 " This includeexpr isn't perfect, but it's a good start
35 setlocal includeexpr=substitute(v:fname,'::','/','g')
37 " NOT adding .rc as it's being phased out (0.7)
38 setlocal suffixesadd=.rs
40 if exists("g:ftplugin_rust_source_path")
41 let &l:path=g:ftplugin_rust_source_path . ',' . &l:path
44 if exists("g:loaded_delimitMate")
45 if exists("b:delimitMate_excluded_regions")
46 let b:rust_original_delimitMate_excluded_regions = b:delimitMate_excluded_regions
48 let b:delimitMate_excluded_regions = delimitMate#Get("excluded_regions") . ',rustLifetimeCandidate,rustGenericLifetimeCandidate'
51 " Motion Commands {{{1
53 " Bind motion commands to support hanging indents
54 nnoremap <silent> <buffer> [[ :call rust#Jump('n', 'Back')<CR>
55 nnoremap <silent> <buffer> ]] :call rust#Jump('n', 'Forward')<CR>
56 xnoremap <silent> <buffer> [[ :call rust#Jump('v', 'Back')<CR>
57 xnoremap <silent> <buffer> ]] :call rust#Jump('v', 'Forward')<CR>
58 onoremap <silent> <buffer> [[ :call rust#Jump('o', 'Back')<CR>
59 onoremap <silent> <buffer> ]] :call rust#Jump('o', 'Forward')<CR>
63 " See |:RustRun| for docs
64 command! -nargs=* -complete=file -bang -bar -buffer RustRun call rust#Run(<bang>0, [<f-args>])
66 " See |:RustExpand| for docs
67 command! -nargs=* -complete=customlist,rust#CompleteExpand -bang -bar -buffer RustExpand call rust#Expand(<bang>0, [<f-args>])
71 " Bind ⌘R in MacVim to :RustRun
72 nnoremap <silent> <buffer> <D-r> :RustRun<CR>
73 " Bind ⌘⇧R in MacVim to :RustRun! pre-filled with the last args
74 nnoremap <buffer> <D-R> :RustRun! <C-r>=join(b:rust_last_rustc_args)<CR><C-\>erust#AppendCmdLine(' -- ' . join(b:rust_last_args))<CR>
76 if !exists("b:rust_last_rustc_args") || !exists("b:rust_last_args")
77 let b:rust_last_rustc_args = []
78 let b:rust_last_args = []
83 let b:undo_ftplugin = "
84 \setlocal formatoptions< comments< commentstring< includeexpr< suffixesadd<
85 \|if exists('b:rust_original_delimitMate_excluded_regions')
86 \|let b:delimitMate_excluded_regions = b:rust_original_delimitMate_excluded_regions
87 \|unlet b:rust_original_delimitMate_excluded_regions
89 \|unlet! b:delimitMate_excluded_regions
91 \|unlet! b:rust_last_rustc_args b:rust_last_args
93 \|delcommand RustExpand
94 \|nunmap <buffer> <D-r>
95 \|nunmap <buffer> <D-R>
106 let &cpo = s:save_cpo
109 " vim: set noet sw=4 ts=4: