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 " :RustRun will compile and run the current file. If it has unsaved changes,
64 " they will be saved first. If it has no path, it will be written to a
65 " temporary file first. The generated binary is always placed in a temporary
66 " directory, but run from the current directory.
68 " The arguments passed to :RustRun will be passed to the generated binary.
70 " If ! is specified, the arguments are given to rustc as well. A -- argument
71 " separates rustc args from the args passed to the binary.
73 " If g:rustc_path is defined, it is used as the path to rustc. Otherwise it is
74 " assumed that rustc is in $PATH.
75 command! -nargs=* -complete=file -bang -bar -buffer RustRun call rust#Run(<bang>0, [<f-args>])
77 " :RustExpand will expand the current file using --pretty.
79 " Any arguments given to :RustExpand will be passed to rustc. This is largely
80 " so you can pass various --cfg configurations.
82 " If ! is specified, the first argument will be interpreted as the --pretty
83 " type. Otherwise it will default to 'expanded'.
85 " If the current file has unsaved changes, it will be saved first. If it's an
86 " unnamed buffer, it will be written to a temporary file.
88 " If g:rustc_path is defined, it is used as the path to rustc. Otherwise it is
89 " assumed that rustc is in $PATH.
90 command! -nargs=* -complete=customlist,rust#CompleteExpand -bang -bar -buffer RustExpand call rust#Expand(<bang>0, [<f-args>])
94 " Bind ⌘R in MacVim to :RustRun
95 nnoremap <silent> <buffer> <D-r> :RustRun<CR>
96 " Bind ⌘⇧R in MacVim to :RustRun! pre-filled with the last args
97 nnoremap <buffer> <D-R> :RustRun! <C-r>=join(b:rust_last_rustc_args)<CR><C-\>erust#AppendCmdLine(' -- ' . join(b:rust_last_args))<CR>
99 if !exists("b:rust_last_rustc_args") || !exists("b:rust_last_args")
100 let b:rust_last_rustc_args = []
101 let b:rust_last_args = []
106 let b:undo_ftplugin = "
107 \setlocal formatoptions< comments< commentstring< includeexpr< suffixesadd<
108 \|if exists('b:rust_original_delimitMate_excluded_regions')
109 \|let b:delimitMate_excluded_regions = b:rust_original_delimitMate_excluded_regions
110 \|unlet b:rust_original_delimitMate_excluded_regions
112 \|unlet! b:delimitMate_excluded_regions
114 \|unlet! b:rust_last_rustc_args b:rust_last_args
116 \|delcommand RustExpand
117 \|nunmap <buffer> <D-r>
118 \|nunmap <buffer> <D-R>
129 let &cpo = s:save_cpo
132 " vim: set noet sw=4 ts=4: