Bram Moolenaar | 6ebe4f9 | 2022-10-28 20:47:54 +0100 | [diff] [blame] | 1 | *ft_rust.txt* For Vim version 9.0. Last change: 2022 Oct 17 |
Bram Moolenaar | d2f3a8b | 2018-06-19 14:35:59 +0200 | [diff] [blame] | 2 | |
| 3 | This is documentation for the Rust filetype plugin. |
Bram Moolenaar | 3c2881d | 2017-03-21 19:18:29 +0100 | [diff] [blame] | 4 | |
| 5 | ============================================================================== |
Bram Moolenaar | 6ebe4f9 | 2022-10-28 20:47:54 +0100 | [diff] [blame] | 6 | CONTENTS *rust* |
Bram Moolenaar | 3c2881d | 2017-03-21 19:18:29 +0100 | [diff] [blame] | 7 | |
Bram Moolenaar | 6ebe4f9 | 2022-10-28 20:47:54 +0100 | [diff] [blame] | 8 | 1. Introduction |rust-intro| |
| 9 | 2. Settings |rust-settings| |
| 10 | 3. Commands |rust-commands| |
| 11 | 4. Mappings |rust-mappings| |
Bram Moolenaar | 3c2881d | 2017-03-21 19:18:29 +0100 | [diff] [blame] | 12 | |
| 13 | ============================================================================== |
Bram Moolenaar | 6ebe4f9 | 2022-10-28 20:47:54 +0100 | [diff] [blame] | 14 | INTRODUCTION *rust-intro* |
Bram Moolenaar | 3c2881d | 2017-03-21 19:18:29 +0100 | [diff] [blame] | 15 | |
| 16 | This plugin provides syntax and supporting functionality for the Rust |
| 17 | filetype. |
| 18 | |
| 19 | ============================================================================== |
Bram Moolenaar | 6ebe4f9 | 2022-10-28 20:47:54 +0100 | [diff] [blame] | 20 | SETTINGS *rust-settings* |
Bram Moolenaar | 3c2881d | 2017-03-21 19:18:29 +0100 | [diff] [blame] | 21 | |
| 22 | This plugin has a few variables you can define in your vimrc that change the |
| 23 | behavior of the plugin. |
| 24 | |
Bram Moolenaar | 6ebe4f9 | 2022-10-28 20:47:54 +0100 | [diff] [blame] | 25 | *g:rustc_path* |
Bram Moolenaar | 3c2881d | 2017-03-21 19:18:29 +0100 | [diff] [blame] | 26 | g:rustc_path~ |
| 27 | Set this option to the path to rustc for use in the |:RustRun| and |
| 28 | |:RustExpand| commands. If unset, "rustc" will be located in $PATH: > |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 29 | let g:rustc_path = $HOME .. "/bin/rustc" |
Bram Moolenaar | 3c2881d | 2017-03-21 19:18:29 +0100 | [diff] [blame] | 30 | < |
| 31 | |
Bram Moolenaar | 6ebe4f9 | 2022-10-28 20:47:54 +0100 | [diff] [blame] | 32 | *g:rustc_makeprg_no_percent* |
Bram Moolenaar | 3c2881d | 2017-03-21 19:18:29 +0100 | [diff] [blame] | 33 | g:rustc_makeprg_no_percent~ |
| 34 | Set this option to 1 to have 'makeprg' default to "rustc" instead of |
| 35 | "rustc %": > |
| 36 | let g:rustc_makeprg_no_percent = 1 |
| 37 | < |
| 38 | |
Bram Moolenaar | 6ebe4f9 | 2022-10-28 20:47:54 +0100 | [diff] [blame] | 39 | *g:rust_conceal* |
Bram Moolenaar | 3c2881d | 2017-03-21 19:18:29 +0100 | [diff] [blame] | 40 | g:rust_conceal~ |
| 41 | Set this option to turn on the basic |conceal| support: > |
| 42 | let g:rust_conceal = 1 |
| 43 | < |
| 44 | |
Bram Moolenaar | 6ebe4f9 | 2022-10-28 20:47:54 +0100 | [diff] [blame] | 45 | *g:rust_conceal_mod_path* |
Bram Moolenaar | 3c2881d | 2017-03-21 19:18:29 +0100 | [diff] [blame] | 46 | g:rust_conceal_mod_path~ |
| 47 | Set this option to turn on |conceal| for the path connecting token |
| 48 | "::": > |
| 49 | let g:rust_conceal_mod_path = 1 |
| 50 | < |
| 51 | |
Bram Moolenaar | 6ebe4f9 | 2022-10-28 20:47:54 +0100 | [diff] [blame] | 52 | *g:rust_conceal_pub* |
Bram Moolenaar | 3c2881d | 2017-03-21 19:18:29 +0100 | [diff] [blame] | 53 | g:rust_conceal_pub~ |
| 54 | Set this option to turn on |conceal| for the "pub" token: > |
| 55 | let g:rust_conceal_pub = 1 |
| 56 | < |
| 57 | |
Bram Moolenaar | 6ebe4f9 | 2022-10-28 20:47:54 +0100 | [diff] [blame] | 58 | *g:rust_recommended_style* |
Bram Moolenaar | 3c2881d | 2017-03-21 19:18:29 +0100 | [diff] [blame] | 59 | g:rust_recommended_style~ |
Bram Moolenaar | 6ebe4f9 | 2022-10-28 20:47:54 +0100 | [diff] [blame] | 60 | Set this option to enable vim indentation and textwidth settings to |
| 61 | conform to style conventions of the rust standard library (i.e. use 4 |
| 62 | spaces for indents and sets 'textwidth' to 99). This option is enabled |
Bram Moolenaar | 3c2881d | 2017-03-21 19:18:29 +0100 | [diff] [blame] | 63 | by default. To disable it: > |
| 64 | let g:rust_recommended_style = 0 |
| 65 | < |
| 66 | |
Bram Moolenaar | 6ebe4f9 | 2022-10-28 20:47:54 +0100 | [diff] [blame] | 67 | *g:rust_fold* |
Bram Moolenaar | 3c2881d | 2017-03-21 19:18:29 +0100 | [diff] [blame] | 68 | g:rust_fold~ |
| 69 | Set this option to turn on |folding|: > |
| 70 | let g:rust_fold = 1 |
| 71 | < |
| 72 | Value Effect ~ |
| 73 | 0 No folding |
| 74 | 1 Braced blocks are folded. All folds are open by |
| 75 | default. |
| 76 | 2 Braced blocks are folded. 'foldlevel' is left at the |
| 77 | global value (all folds are closed by default). |
| 78 | |
Bram Moolenaar | 6ebe4f9 | 2022-10-28 20:47:54 +0100 | [diff] [blame] | 79 | *g:rust_bang_comment_leader* |
Bram Moolenaar | 3c2881d | 2017-03-21 19:18:29 +0100 | [diff] [blame] | 80 | g:rust_bang_comment_leader~ |
| 81 | Set this option to 1 to preserve the leader on multi-line doc comments |
| 82 | using the /*! syntax: > |
| 83 | let g:rust_bang_comment_leader = 1 |
| 84 | < |
| 85 | |
Bram Moolenaar | 6ebe4f9 | 2022-10-28 20:47:54 +0100 | [diff] [blame] | 86 | *g:ftplugin_rust_source_path* |
Bram Moolenaar | 3c2881d | 2017-03-21 19:18:29 +0100 | [diff] [blame] | 87 | g:ftplugin_rust_source_path~ |
| 88 | Set this option to a path that should be prepended to 'path' for Rust |
| 89 | source files: > |
Bram Moolenaar | c51cf03 | 2022-02-26 12:25:45 +0000 | [diff] [blame] | 90 | let g:ftplugin_rust_source_path = $HOME .. '/dev/rust' |
Bram Moolenaar | 3c2881d | 2017-03-21 19:18:29 +0100 | [diff] [blame] | 91 | < |
| 92 | |
Bram Moolenaar | 6ebe4f9 | 2022-10-28 20:47:54 +0100 | [diff] [blame] | 93 | *g:rustfmt_command* |
Bram Moolenaar | 3c2881d | 2017-03-21 19:18:29 +0100 | [diff] [blame] | 94 | g:rustfmt_command~ |
| 95 | Set this option to the name of the 'rustfmt' executable in your $PATH. If |
| 96 | not specified it defaults to 'rustfmt' : > |
| 97 | let g:rustfmt_command = 'rustfmt' |
| 98 | < |
Bram Moolenaar | 6ebe4f9 | 2022-10-28 20:47:54 +0100 | [diff] [blame] | 99 | *g:rustfmt_autosave* |
Bram Moolenaar | 3c2881d | 2017-03-21 19:18:29 +0100 | [diff] [blame] | 100 | g:rustfmt_autosave~ |
| 101 | Set this option to 1 to run |:RustFmt| automatically when saving a |
| 102 | buffer. If not specified it defaults to 0 : > |
| 103 | let g:rustfmt_autosave = 0 |
| 104 | < |
Bram Moolenaar | 6ebe4f9 | 2022-10-28 20:47:54 +0100 | [diff] [blame] | 105 | *g:rustfmt_fail_silently* |
Bram Moolenaar | 3c2881d | 2017-03-21 19:18:29 +0100 | [diff] [blame] | 106 | g:rustfmt_fail_silently~ |
| 107 | Set this option to 1 to prevent 'rustfmt' from populating the |
| 108 | |location-list| with errors. If not specified it defaults to 0: > |
| 109 | let g:rustfmt_fail_silently = 0 |
| 110 | < |
Bram Moolenaar | 6ebe4f9 | 2022-10-28 20:47:54 +0100 | [diff] [blame] | 111 | *g:rustfmt_options* |
Bram Moolenaar | 3c2881d | 2017-03-21 19:18:29 +0100 | [diff] [blame] | 112 | g:rustfmt_options~ |
| 113 | Set this option to a string of options to pass to 'rustfmt'. The |
| 114 | write-mode is already set to 'overwrite'. If not specified it |
| 115 | defaults to '' : > |
| 116 | let g:rustfmt_options = '' |
| 117 | < |
| 118 | |
Bram Moolenaar | 6ebe4f9 | 2022-10-28 20:47:54 +0100 | [diff] [blame] | 119 | *g:rust_playpen_url* |
Bram Moolenaar | 3c2881d | 2017-03-21 19:18:29 +0100 | [diff] [blame] | 120 | g:rust_playpen_url~ |
Bram Moolenaar | f55e4c8 | 2017-08-01 20:44:53 +0200 | [diff] [blame] | 121 | Set this option to override the URL for the playpen to use: > |
Bram Moolenaar | 3c2881d | 2017-03-21 19:18:29 +0100 | [diff] [blame] | 122 | let g:rust_playpen_url = 'https://play.rust-lang.org/' |
| 123 | < |
| 124 | |
Bram Moolenaar | 6ebe4f9 | 2022-10-28 20:47:54 +0100 | [diff] [blame] | 125 | *g:rust_shortener_url* |
Bram Moolenaar | 3c2881d | 2017-03-21 19:18:29 +0100 | [diff] [blame] | 126 | g:rust_shortener_url~ |
Bram Moolenaar | f55e4c8 | 2017-08-01 20:44:53 +0200 | [diff] [blame] | 127 | Set this option to override the URL for the URL shortener: > |
Bram Moolenaar | 3c2881d | 2017-03-21 19:18:29 +0100 | [diff] [blame] | 128 | let g:rust_shortener_url = 'https://is.gd/' |
| 129 | < |
| 130 | |
| 131 | |
| 132 | ============================================================================== |
Bram Moolenaar | 6ebe4f9 | 2022-10-28 20:47:54 +0100 | [diff] [blame] | 133 | COMMANDS *rust-commands* |
Bram Moolenaar | 3c2881d | 2017-03-21 19:18:29 +0100 | [diff] [blame] | 134 | |
Bram Moolenaar | 6ebe4f9 | 2022-10-28 20:47:54 +0100 | [diff] [blame] | 135 | :RustRun [args] *:RustRun* |
Bram Moolenaar | 3c2881d | 2017-03-21 19:18:29 +0100 | [diff] [blame] | 136 | :RustRun! [rustc-args] [--] [args] |
| 137 | Compiles and runs the current file. If it has unsaved changes, |
| 138 | it will be saved first using |:update|. If the current file is |
| 139 | an unnamed buffer, it will be written to a temporary file |
| 140 | first. The compiled binary is always placed in a temporary |
| 141 | directory, but is run from the current directory. |
| 142 | |
| 143 | The arguments given to |:RustRun| will be passed to the |
| 144 | compiled binary. |
| 145 | |
| 146 | If ! is specified, the arguments are passed to rustc instead. |
| 147 | A "--" argument will separate the rustc arguments from the |
| 148 | arguments passed to the binary. |
| 149 | |
| 150 | If |g:rustc_path| is defined, it is used as the path to rustc. |
| 151 | Otherwise it is assumed rustc can be found in $PATH. |
| 152 | |
Bram Moolenaar | 6ebe4f9 | 2022-10-28 20:47:54 +0100 | [diff] [blame] | 153 | :RustExpand [args] *:RustExpand* |
Bram Moolenaar | 3c2881d | 2017-03-21 19:18:29 +0100 | [diff] [blame] | 154 | :RustExpand! [TYPE] [args] |
| 155 | Expands the current file using --pretty and displays the |
| 156 | results in a new split. If the current file has unsaved |
| 157 | changes, it will be saved first using |:update|. If the |
| 158 | current file is an unnamed buffer, it will be written to a |
| 159 | temporary file first. |
| 160 | |
| 161 | The arguments given to |:RustExpand| will be passed to rustc. |
| 162 | This is largely intended for specifying various --cfg |
| 163 | configurations. |
| 164 | |
| 165 | If ! is specified, the first argument is the expansion type to |
| 166 | pass to rustc --pretty. Otherwise it will default to |
| 167 | "expanded". |
| 168 | |
| 169 | If |g:rustc_path| is defined, it is used as the path to rustc. |
| 170 | Otherwise it is assumed rustc can be found in $PATH. |
| 171 | |
Bram Moolenaar | 6ebe4f9 | 2022-10-28 20:47:54 +0100 | [diff] [blame] | 172 | :RustEmitIr [args] *:RustEmitIr* |
Bram Moolenaar | 3c2881d | 2017-03-21 19:18:29 +0100 | [diff] [blame] | 173 | Compiles the current file to LLVM IR and displays the results |
| 174 | in a new split. If the current file has unsaved changes, it |
| 175 | will be saved first using |:update|. If the current file is an |
| 176 | unnamed buffer, it will be written to a temporary file first. |
| 177 | |
| 178 | The arguments given to |:RustEmitIr| will be passed to rustc. |
| 179 | |
| 180 | If |g:rustc_path| is defined, it is used as the path to rustc. |
| 181 | Otherwise it is assumed rustc can be found in $PATH. |
| 182 | |
Bram Moolenaar | 6ebe4f9 | 2022-10-28 20:47:54 +0100 | [diff] [blame] | 183 | :RustEmitAsm [args] *:RustEmitAsm* |
Bram Moolenaar | 3c2881d | 2017-03-21 19:18:29 +0100 | [diff] [blame] | 184 | Compiles the current file to assembly and displays the results |
| 185 | in a new split. If the current file has unsaved changes, it |
| 186 | will be saved first using |:update|. If the current file is an |
| 187 | unnamed buffer, it will be written to a temporary file first. |
| 188 | |
| 189 | The arguments given to |:RustEmitAsm| will be passed to rustc. |
| 190 | |
| 191 | If |g:rustc_path| is defined, it is used as the path to rustc. |
| 192 | Otherwise it is assumed rustc can be found in $PATH. |
| 193 | |
Bram Moolenaar | 6ebe4f9 | 2022-10-28 20:47:54 +0100 | [diff] [blame] | 194 | :RustPlay *:RustPlay* |
Bram Moolenaar | 3c2881d | 2017-03-21 19:18:29 +0100 | [diff] [blame] | 195 | This command will only work if you have web-api.vim installed |
| 196 | (available at https://github.com/mattn/webapi-vim). It sends the |
| 197 | current selection, or if nothing is selected, the entirety of the |
| 198 | current buffer to the Rust playpen, and emits a message with the |
| 199 | shortened URL to the playpen. |
| 200 | |
| 201 | |g:rust_playpen_url| is the base URL to the playpen, by default |
| 202 | "https://play.rust-lang.org/". |
| 203 | |
Bram Moolenaar | 01164a6 | 2017-11-02 22:58:42 +0100 | [diff] [blame] | 204 | |g:rust_shortener_url| is the base URL for the shortener, by |
Bram Moolenaar | 3c2881d | 2017-03-21 19:18:29 +0100 | [diff] [blame] | 205 | default "https://is.gd/" |
| 206 | |
Bram Moolenaar | 6ebe4f9 | 2022-10-28 20:47:54 +0100 | [diff] [blame] | 207 | :RustFmt *:RustFmt* |
Bram Moolenaar | 3c2881d | 2017-03-21 19:18:29 +0100 | [diff] [blame] | 208 | Runs |g:rustfmt_command| on the current buffer. If |
| 209 | |g:rustfmt_options| is set then those will be passed to the |
| 210 | executable. |
| 211 | |
| 212 | If |g:rustfmt_fail_silently| is 0 (the default) then it |
| 213 | will populate the |location-list| with the errors from |
| 214 | |g:rustfmt_command|. If |g:rustfmt_fail_silently| is set to 1 |
| 215 | then it will not populate the |location-list|. |
| 216 | |
Bram Moolenaar | 6ebe4f9 | 2022-10-28 20:47:54 +0100 | [diff] [blame] | 217 | :RustFmtRange *:RustFmtRange* |
Bram Moolenaar | 3c2881d | 2017-03-21 19:18:29 +0100 | [diff] [blame] | 218 | Runs |g:rustfmt_command| with selected range. See |
| 219 | |:RustFmt| for any other information. |
| 220 | |
| 221 | ============================================================================== |
Bram Moolenaar | 6ebe4f9 | 2022-10-28 20:47:54 +0100 | [diff] [blame] | 222 | MAPPINGS *rust-mappings* |
Bram Moolenaar | 3c2881d | 2017-03-21 19:18:29 +0100 | [diff] [blame] | 223 | |
| 224 | This plugin defines mappings for |[[| and |]]| to support hanging indents. |
| 225 | |
| 226 | It also has a few other mappings: |
| 227 | |
| 228 | *rust_<D-r>* |
| 229 | <D-r> Executes |:RustRun| with no arguments. |
| 230 | Note: This binding is only available in MacVim. |
| 231 | |
| 232 | *rust_<D-R>* |
| 233 | <D-R> Populates the command line with |:RustRun|! using the |
| 234 | arguments given to the last invocation, but does not |
| 235 | execute it. |
| 236 | Note: This binding is only available in MacVim. |
| 237 | |
| 238 | ============================================================================== |
Bram Moolenaar | d473c8c | 2018-08-11 18:00:22 +0200 | [diff] [blame] | 239 | vim:tw=78:sw=4:ts=8:noet:ft=help:norl: |