1
- " Vim syntax file
2
1
" Language: Rust
2
+ " Description: Vim syntax file for Rust
3
3
" Maintainer: Chris Morgan <[email protected] >
4
- " Last Change: 2014 Feb 27
4
+ " Maintainer: Kevin Ballard <[email protected] >
5
+ " Last Change: May 27, 2014
5
6
6
7
if exists (" b:did_ftplugin" )
7
8
finish
8
9
endif
9
10
let b: did_ftplugin = 1
10
11
12
+ let s: save_cpo = &cpo
13
+ set cpo &vim
14
+
15
+ " Variables {{{1
16
+
11
17
" The rust source code at present seems to typically omit a leader on /*!
12
18
" comments, so we'll use that as our default, but make it easy to switch.
13
19
" This does not affect indentation at all (I tested it with and without
@@ -42,22 +48,74 @@ if exists("g:loaded_delimitMate")
42
48
let b: delimitMate_excluded_regions = delimitMate#Get (" excluded_regions" ) . ' ,rustLifetimeCandidate,rustGenericLifetimeCandidate'
43
49
endif
44
50
51
+ " Motion Commands {{{1
52
+
45
53
" Bind motion commands to support hanging indents
46
- nnoremap <silent> <buffer> [[ :call <SID> Rust_Jump('n', 'Back')<CR>
47
- nnoremap <silent> <buffer> ]] :call <SID> Rust_Jump('n', 'Forward')<CR>
48
- xnoremap <silent> <buffer> [[ :call <SID> Rust_Jump('v', 'Back')<CR>
49
- xnoremap <silent> <buffer> ]] :call <SID> Rust_Jump('v', 'Forward')<CR>
50
- onoremap <silent> <buffer> [[ :call <SID> Rust_Jump('o', 'Back')<CR>
51
- onoremap <silent> <buffer> ]] :call <SID> Rust_Jump('o', 'Forward')<CR>
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
+ " :Run will compile and run the current file. If it has unsaved changes, they
64
+ " will be saved first. If it has no path, it will be written to a temporary
65
+ " file first. The generated binary is always placed in a temporary directory,
66
+ " but run from the current directory.
67
+ "
68
+ " The arguments passed to :Run will be passed to the generated binary.
69
+ "
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.
72
+ "
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 Run call rust#Run (<bang> 0 , [<f-args> ])
76
+
77
+ " :Expand will expand the current file using --pretty.
78
+ "
79
+ " Any arguments given to :Expand will be passed to rustc. This is largely so
80
+ " you can pass various --cfg configurations.
81
+ "
82
+ " If ! is specified, the first argument will be interpreted as the --pretty
83
+ " type. Otherwise it will default to 'expanded'.
84
+ "
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.
87
+ "
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 Expand call rust#Expand (<bang> 0 , [<f-args> ])
91
+
92
+ " Mappings {{{1
93
+
94
+ " Bind ⌘R in MacVim to :Run
95
+ nnoremap <silent> <buffer> <D-r> :Run<CR>
96
+ " Bind ⌘⇧R in MacVim to :Run! pre-filled with the last args
97
+ nnoremap <buffer> <D-R> :Run! <C-r> =join(b:rust_last_rustc_args)<CR><C-\> erust#AppendCmdLine(' -- ' . join(b:rust_last_args))<CR>
98
+
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 = []
102
+ endif
103
+
104
+ " Cleanup {{{1
52
105
53
106
let b: undo_ftplugin = "
54
107
\s etlocal formatoptions < comments < commentstring < includeexpr < suffixesadd <
55
108
\| if exists (' b:rust_original_delimitMate_excluded_regions' )
56
109
\| let b: delimitMate_excluded_regions = b: rust_original_delimitMate_excluded_regions
57
110
\| unlet b: rust_original_delimitMate_excluded_regions
58
- \| elseif exists ( ' b:delimitMate_excluded_regions ' )
59
- \| unlet b: delimitMate_excluded_regions
111
+ \| else
112
+ \| unlet ! b: delimitMate_excluded_regions
60
113
\| endif
114
+ \| unlet ! b: rust_last_rustc_args b: rust_last_args
115
+ \| delcommand Run
116
+ \| delcommand Expand
117
+ \| nunmap <buffer> <D-r>
118
+ \| nunmap <buffer> <D-R>
61
119
\| nunmap <buffer> [[
62
120
\| nunmap <buffer> ]]
63
121
\| xunmap <buffer> [[
@@ -66,31 +124,9 @@ let b:undo_ftplugin = "
66
124
\| ounmap <buffer> ]]
67
125
\"
68
126
69
- if exists ( ' *<SID>Rust_Jump ' ) | finish | endif
127
+ " }}}1
70
128
71
- function ! <SID> Rust_Jump (mode , function ) range
72
- let cnt = v: count1
73
- normal ! m '
74
- if a: mode == # ' v'
75
- norm! gv
76
- endif
77
- let foldenable = &foldenable
78
- set nofoldenable
79
- while cnt > 0
80
- execute " call <SID>Rust_Jump_" . a: function . " ()"
81
- let cnt = cnt - 1
82
- endwhile
83
- let &foldenable = foldenable
84
- endfunction
85
-
86
- function ! <SID> Rust_Jump_Back ()
87
- call search (' {' , ' b' )
88
- keepjumps normal ! w99[{
89
- endfunction
90
-
91
- function ! <SID> Rust_Jump_Forward ()
92
- normal ! j0
93
- call search (' {' , ' b' )
94
- keepjumps normal ! w99[{%
95
- call search (' {' )
96
- endfunction
129
+ let &cpo = s: save_cpo
130
+ unlet s: save_cpo
131
+
132
+ " vim: set noet sw = 4 ts = 4 :
0 commit comments