]> git.lizzy.rs Git - rust.git/blob - src/etc/vim/ftplugin/rust.vim
ed5d721de0859da6b1a7ee5b4df636ba1630c550
[rust.git] / src / etc / vim / ftplugin / rust.vim
1 " Language:     Rust
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
6
7 if exists("b:did_ftplugin")
8         finish
9 endif
10 let b:did_ftplugin = 1
11
12 let s:save_cpo = &cpo
13 set cpo&vim
14
15 " Variables {{{1
16
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:*/,:///,://!,://
26 else
27         setlocal comments=s0:/*!,m:\ ,ex:*/,s1:/*,mb:*,ex:*/,:///,://!,://
28 endif
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
33
34 " This includeexpr isn't perfect, but it's a good start
35 setlocal includeexpr=substitute(v:fname,'::','/','g')
36
37 " NOT adding .rc as it's being phased out (0.7)
38 setlocal suffixesadd=.rs
39
40 if exists("g:ftplugin_rust_source_path")
41     let &l:path=g:ftplugin_rust_source_path . ',' . &l:path
42 endif
43
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
47         endif
48         let b:delimitMate_excluded_regions = delimitMate#Get("excluded_regions") . ',rustLifetimeCandidate,rustGenericLifetimeCandidate'
49 endif
50
51 " Motion Commands {{{1
52
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>
60
61 " Commands {{{1
62
63 " See |:RustRun| for docs
64 command! -nargs=* -complete=file -bang -bar -buffer RustRun call rust#Run(<bang>0, [<f-args>])
65
66 " See |:RustExpand| for docs
67 command! -nargs=* -complete=customlist,rust#CompleteExpand -bang -bar -buffer RustExpand call rust#Expand(<bang>0, [<f-args>])
68
69 " Mappings {{{1
70
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>
75
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 = []
79 endif
80
81 " Cleanup {{{1
82
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
88                 \|else
89                   \|unlet! b:delimitMate_excluded_regions
90                 \|endif
91                 \|unlet! b:rust_last_rustc_args b:rust_last_args
92                 \|delcommand RustRun
93                 \|delcommand RustExpand
94                 \|nunmap <buffer> <D-r>
95                 \|nunmap <buffer> <D-R>
96                 \|nunmap <buffer> [[
97                 \|nunmap <buffer> ]]
98                 \|xunmap <buffer> [[
99                 \|xunmap <buffer> ]]
100                 \|ounmap <buffer> [[
101                 \|ounmap <buffer> ]]
102                 \"
103
104 " }}}1
105
106 let &cpo = s:save_cpo
107 unlet s:save_cpo
108
109 " vim: set noet sw=4 ts=4: