ft_rust.txt Filetypeplugin for Rust==============================================================================CONTENTSrust1. Introductionrust-intro2. Settingsrust-settings3. Commandsrust-commands4. Mappingsrust-mappings==============================================================================INTRODUCTIONrust-introThisplugin providessyntax and supporting functionality for the Rustfiletype. It requires Vim 8 or higher for full functionality. Some commandswill not work on earlier versions.==============================================================================SETTINGSrust-settingsThisplugin hasa fewvariables you can define in yourvimrc that change thebehavior of the plugin.Somevariables can be set buffer local (`:b` prefix), and the buffer localwill take precedence over the globalg: counterpart.g:rustc_pathg:rustc_pathSet this option to the path to rustc for use in the:RustRun and:RustExpand commands. If unset, "rustc" will be located in $PATH: let g:rustc_path = $HOME."/bin/rustc"g:rustc_makeprg_no_percentg:rustc_makeprg_no_percentSet this option to 1 to have'makeprg' default to "rustc" instead of"rustc%": let g:rustc_makeprg_no_percent = 1g:rust_concealg:rust_concealSet this option to turn on the basicconceal support: let g:rust_conceal = 1g:rust_conceal_mod_pathg:rust_conceal_mod_pathSet this option to turn onconceal for the path connecting token"::": let g:rust_conceal_mod_path = 1g:rust_conceal_pubg:rust_conceal_pubSet this option to turn onconceal for the "pub" token: let g:rust_conceal_pub = 1g:rust_recommended_styleg:rust_recommended_style Set this option to enable vim indentation and textwidth settings to conform to style conventions of the Rust style guide (i.e. use 4 spaces for indents and set'textwidth' to 100). This optionis enabledby default. To disable it: let g:rust_recommended_style = 0g:rust_foldg:rust_foldSet this option to turn onfolding: let g:rust_fold = 1ValueEffect0Nofolding1Braced blocks are folded. Allfolds are open bydefault.2Braced blocks are folded.'foldlevel'is leftat theglobal value (allfolds are closed by default).g:rust_bang_comment_leaderg:rust_bang_comment_leaderSet this option to 1 to preserve the leader on multi-line doc commentsusing the/*! syntax: let g:rust_bang_comment_leader = 1g:rust_use_custom_ctags_defsg:rust_use_custom_ctags_defsSet this option to 1 if you have customizedctagsdefinitions for Rustanddo not wish for those included with rust.vim to be used: let g:rust_use_custom_ctags_defs = 1NOTE: rust.vim's built-indefinitions are only used for the Tagbar Vimplugin, if you haveit installed, AND if Universal Ctagsis notdetected. Thisis because Universal Ctags already has built-insupport for Rust when used with Tagbar.Also,note that when usingctags other than Universal Ctags,itis notautomatically used when generatingtags files that Vim can use tonavigate todefinitions across different source files. Feel free tocopyrust.vim/ctags/rust.ctags into your own~/.ctags if you wishto generatetags files.g:ftplugin_rust_source_pathg:ftplugin_rust_source_pathSet this option toa path that should be prepended to'path' for Rustsource files: let g:ftplugin_rust_source_path = $HOME.'/dev/rust'g:rustfmt_commandg:rustfmt_commandSet this option to the name of the'rustfmt' executable in your $PATH. Ifnot specifiedit defaults to'rustfmt': let g:rustfmt_command = 'rustfmt'g:rustfmt_autosaveg:rustfmt_autosaveSet this option to 1 to run:RustFmt automatically when savingabuffer. If not specifiedit defaults to0: let g:rustfmt_autosave = 0Thereis alsoa buffer-localb:rustfmt_autosave that can be set forthe same purpose, and can override the global setting.g:rustfmt_autosave_if_config_presentg:rustfmt_autosave_if_config_presentSet this option to 1 to haveb:rustfmt_autosave be set automaticallyifarustfmt.toml fileis present in any parent directly leading tothe file being edited. If not set, default to 0: let g:rustfmt_autosave_if_config_present = 0Thisis useful to haverustfmt only execute on save, on projectsthat haverustfmt.toml configuration.Thereis alsoa buffer-local b:rustfmt_autosave_if_config_presentthat can be set for the same purpose, which can overrides the globalsetting.g:rustfmt_fail_silentlyg:rustfmt_fail_silentlySet this option to 1 to prevent'rustfmt' from populating thelocation-list with errors. If not specifiedit defaults to 0: let g:rustfmt_fail_silently = 0g:rustfmt_optionsg:rustfmt_optionsSet this option toastring ofoptions to pass to'rustfmt'. Thewrite-modeis already set to'overwrite'. If not specifieditdefaults to'': let g:rustfmt_options = ''g:rustfmt_emit_filesg:rustfmt_emit_filesIf not specified rust.vim tries to detect the right parameter topass to rustfmt based on its reported version. Otherwise,itdetermines whether to run rustfmt with '--emit=files' (when 1isprovided) instead of '--write-mode=overwrite'. let g:rustfmt_emit_files = 0g:rustfmt_detect_versiong:rustfmt_detect_versionWhen set to 1, will try to parse the version output from "rustfmt".Disabled by default for performance reasons let g:rustfmt_detect_version = 1g:rustfmt_find_tomlg:rustfmt_find_tomlWhen set to 1, will try to findrustfmt.toml file by searching fromcurrent path upwards. Disabled by default for performance reasons let g:rustfmt_find_toml = 1g:rust_playpen_urlg:rust_playpen_urlSet this option to override the url for the playpen to use: let g:rust_playpen_url = 'https://play.rust-lang.org/'g:rust_shortener_urlg:rust_shortener_urlSet this option to override the url for the url shortener: let g:rust_shortener_url = 'https://is.gd/'g:rust_clip_commandg:rust_clip_commandSet this option to the command used in your OS to copy the Rust Playurl to the clipboard: let g:rust_clip_command = 'xclip -selection clipboard'g:cargo_makeprg_paramsg:cargo_makeprg_paramsSet this option to thestring of parameters to pass to cargo. If notspecifiedit defaults to '$*': let g:cargo_makeprg_params = 'build'g:cargo_shell_command_runnerg:cargo_shell_command_runnerSet this option to change how to run shell commands for cargo commands:Cargo,:Cbuild,:Crun,...By default,:terminalis used to run shell command interminalwindowasynchronously. But if you prefer:! for running the commands,it canbe specified: let g:cargo_shell_command_runner = '!'Integration with Syntasticrust-syntastic--------------------------Thisplugin automatically integrates with the Syntastic checker. There are twocheckers provided:'rustc', and'cargo'. The latter invokes 'Cargo' in order tobuild code, and the former deliversa single edited '.rs' fileasa compilationtarget directly to the Rust compiler,rustc.Because Cargois almost exclusively being used for building Rust code thesedays,'cargo'is the default checker. let g:syntastic_rust_checkers = ['cargo']If you would like to change it, you can setg:syntastic_rust_checkers toadifferent value.g:rust_cargo_avoid_whole_workspaceb:rust_cargo_avoid_whole_workspaceg:rust_cargo_avoid_whole_workspaceWhen editinga crate thatis part ofa Cargo workspace, and thisoptionis set to 1 (the default), then'cargo' will be executeddirectly in that crate directory instead of in the workspacedirectory. Setting0 prevents this behavior- however be aware that ifyou are working in large workspace, Cargo commands may take more time,plus the Syntastic errorlist may include all the crates in theworkspace. let g:rust_cargo_avoid_whole_workspace = 0g:rust_cargo_check_all_targetsb:rust_cargo_check_all_targetsg:rust_cargo_check_all_targetsWhen set to 1, the--all-targets option will be passed to cargo whenSyntastic executes it, allowing the linting of all targets under thepackage.The defaultis 0.g:rust_cargo_check_all_featuresb:rust_cargo_check_all_featuresg:rust_cargo_check_all_featuresWhen set to 1, the--all-features option will be passed to cargo whenSyntastic executes it, allowing the linting of all features of thepackage.The defaultis 0.g:rust_cargo_check_examplesb:rust_cargo_check_examplesg:rust_cargo_check_examplesWhen set to 1, the--examples option will be passed to cargo whenSyntastic executes it, to prevent the exclusion of examples fromlinting. The examples are normally under theexamples/ directory ofthe crate.The defaultis 0.g:rust_cargo_check_testsb:rust_cargo_check_testsg:rust_cargo_check_testsWhen set to 1, the--tests option will be passed to cargo whenSyntastic executes it, to prevent the exclusion of tests from linting.The tests are normally under thetests/ directory of the crate.The defaultis 0.g:rust_cargo_check_benchesb:rust_cargo_check_benchesg:rust_cargo_check_benchesWhen set to 1, the--benches option will be passed to cargo whenSyntastic executes it. The benches are normally under thebenches/directory of the crate.The defaultis 0.Integration with auto-pairsrust-auto-pairs---------------------------Thisplugin automatically configures the auto-pairsplugin not to duplicatesingle quotes, which are used more often for lifetime annotations than forsingle character literals.g:rust_keep_autopairs_defaultg:rust_keep_autopairs_defaultDon't override auto-pairs default for the Rust filetype. The defaultis 0.==============================================================================COMMANDSrust-commandsInvoking Cargo--------------This plug defines very simple shortcuts for invoking Cargo from with Vim.:Cargo<args>:Cargo Runs'cargo' with the provided arguments.:Cbuild<args>:Cbuild Shortcut for 'cargo build`.:Cclean<args>:Cclean Shortcut for 'cargo clean`.:Cdoc<args>:Cdoc Shortcut for 'cargo doc`.:Cinit<args>:Cinit Shortcut for 'cargo init`.:Crun<args>:Crun Shortcut for 'cargo run`.:Ctest<args>:Ctest Shortcut for 'cargo test`.:Cupdate<args>:Cupdate Shortcut for 'cargo update`.:Cbench<args>:Cbench Shortcut for 'cargo bench`.:Csearch<args>:Csearch Shortcut for 'cargo search`.:Cpublish<args>:Cpublish Shortcut for 'cargo publish`.:Cinstall<args>:Cinstall Shortcut for 'cargo install`.:Cruntarget<args>:Cruntarget Shortcut for 'cargo run --bin' or 'cargo run --example', depending on the currently open buffer.Formatting----------:RustFmt:RustFmtRunsg:rustfmt_command on the current buffer. Ifg:rustfmt_optionsis set then those will be passed to theexecutable.Ifg:rustfmt_fail_silentlyis0 (the default) thenitwill populate thelocation-list with theerrors fromg:rustfmt_command. Ifg:rustfmt_fail_silentlyis set to 1thenit will not populate thelocation-list.:RustFmtRange:RustFmtRangeRunsg:rustfmt_command with selected range. See:RustFmt for any other information.Playpen integration-------------------:RustPlay:RustPlayThis command will only work if you have web-api.vim installed(availableathttps://github.com/mattn/webapi-vim). It sends thecurrent selection, or if nothingis selected, the entirety of thecurrent buffer to the Rust playpen, and emitsa message with theshortened URL to the playpen.g:rust_playpen_urlis the base URL to the playpen, by default"https://play.rust-lang.org/".g:rust_shortener_urlis the base url for the shorterner, bydefault "https://is.gd/"g:rust_clip_commandis the command to run to copy theplaypen url to theclipboard of your system.Evaluation ofa single Rust file--------------------------------NOTE: These commands are useful only when working with standalone Rust files,whichis usually not thecase for common Rust development. If you wish tobuilding Rust crates from with Vim can should use Vim's make, Syntastic, orfunctionality from other plugins.:RustRun[args]:RustRun:RustRun![rustc-args][--][args]Compiles and runs the current file. Ifit has unsaved changes,it will be saved first using:update. If the current fileisan unnamed buffer,it will be written toa temporary filefirst. The compiled binaryis always placed ina temporarydirectory, butis run from the current directory.The arguments given to:RustRun will be passed to thecompiled binary.If!is specified, the arguments are passed to rustc instead.A "--" argument will separate the rustc arguments from thearguments passed to the binary.Ifg:rustc_pathis defined,itis usedas the path to rustc.Otherwiseitis assumed rustc can be found in $PATH.:RustExpand[args]:RustExpand:RustExpand![TYPE][args]Expands the current file using --pretty and displays theresults ina new split. If the current file has unsavedchanges,it will be saved first using:update. If thecurrent fileis an unnamed buffer,it will be written toatemporary file first.The arguments given to:RustExpand will be passed to rustc.Thisis largely intended for specifyingvarious --cfgconfigurations.If!is specified, the first argumentis the expansion type topass to rustc --pretty. Otherwiseit will default to"expanded".Ifg:rustc_pathis defined,itis usedas the path to rustc.Otherwiseitis assumed rustc can be found in $PATH.:RustEmitIr[args]:RustEmitIrCompiles the current file to LLVM IR and displays the resultsina new split. If the current file has unsaved changes,itwill be saved first using:update. If the current fileis anunnamed buffer,it will be written toa temporary file first.The arguments given to:RustEmitIr will be passed to rustc.Ifg:rustc_pathis defined,itis usedas the path to rustc.Otherwiseitis assumed rustc can be found in $PATH.:RustEmitAsm[args]:RustEmitAsmCompiles the current file to assembly and displays the resultsina new split. If the current file has unsaved changes,itwill be saved first using:update. If the current fileis anunnamed buffer,it will be written toa temporary file first.The arguments given to:RustEmitAsm will be passed to rustc.Ifg:rustc_pathis defined,itis usedas the path to rustc.Otherwiseitis assumed rustc can be found in $PATH.Running test(s)---------------:[N]RustTest[!][options]:RustTestRunsa test under the cursor when the current bufferis inacargo project with "cargo test" command. If the command didnot find any test function under the cursor,it stops with anerror message.WhenNis given, adjust the size of the newwindow toN linesor columns.When!is given, runs all tests regardless of current cursorposition.When[options]is given,itis passed to "cargo" commandarguments.When the current bufferis outside cargo project, the commandruns "rustc --test" command instead of "cargo test"asfallback. All tests are run regardless of adding! since thereis no way to run specific test function with rustc.[options]is passed to "rustc" command arguments in the case.Takes optional modifiers (see<mods>): :tab RustTest :belowright 16RustTest :leftabove vert 80RustTestrust.vim Debugging------------------:RustInfo:RustInfoEmits debugging info of the Vim Rust plugin.:RustInfoToClipboard:RustInfoClipboardSaves debugging info of the Vim Rustplugin to the defaultregister.:RustInfoToFile[filename]:RustInfoToFileSaves debugging info of the Vim Rustplugin to the given file,overwriting it.==============================================================================MAPPINGSrust-mappingsThisplugin defines mappings for[[ and]] to support hanging indents.============================================================================== vim:tw=78:sw=4:noet:ts=8:ft=help:norl: