Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
rust.vim244 linesDownload Raw Back to ftplugin
1" Language:	Rust2" Description:	Vim ftplugin for Rust3" Maintainer:	Chris Morgan <me@chrismorgan.info>4" Last Change:	2024 Mar 175"		2024 May 23 by Riley Bruins <ribru17@gmail.com ('commentstring')6"		2025 Dec 09 update 'textwidth# to 100 #188927" For bugs, patches and license go to https://github.com/rust-lang/rust.vim8 9if exists("b:did_ftplugin")10    finish11endif12let b:did_ftplugin = 113 14" vint: -ProhibitAbbreviationOption15let s:save_cpo = &cpo16set cpo&vim17" vint: +ProhibitAbbreviationOption18 19if get(b:, 'current_compiler', '') ==# ''20    if strlen(findfile('Cargo.toml', '.;')) > 021        compiler cargo22    else23        compiler rustc24    endif25endif26 27" Variables {{{128 29" The rust source code at present seems to typically omit a leader on /*!30" comments, so we'll use that as our default, but make it easy to switch.31" This does not affect indentation at all (I tested it with and without32" leader), merely whether a leader is inserted by default or not.33if get(g:, 'rust_bang_comment_leader', 0)34    " Why is the `,s0:/*,mb:\ ,ex:*/` there, you ask? I don't understand why,35    " but without it, */ gets indented one space even if there were no36    " leaders. I'm fairly sure that's a Vim bug.37    setlocal comments=s1:/*,mb:*,ex:*/,s0:/*,mb:\ ,ex:*/,:///,://!,://38else39    setlocal comments=s0:/*!,ex:*/,s1:/*,mb:*,ex:*/,:///,://!,://40endif41setlocal commentstring=//\ %s42setlocal formatoptions-=t formatoptions+=croqnl43" j was only added in 7.3.541, so stop complaints about its nonexistence44silent! setlocal formatoptions+=j45 46" smartindent will be overridden by indentexpr if filetype indent is on, but47" otherwise it's better than nothing.48setlocal smartindent nocindent49 50if get(g:, 'rust_recommended_style', 1)51    let b:rust_set_style = 152    setlocal shiftwidth=4 softtabstop=4 expandtab53    setlocal textwidth=10054endif55 56setlocal include=\\v^\\s*(pub\\s+)?use\\s+\\zs(\\f\|:)+57setlocal includeexpr=rust#IncludeExpr(v:fname)58 59setlocal suffixesadd=.rs60 61if exists("g:ftplugin_rust_source_path")62    let &l:path=g:ftplugin_rust_source_path . ',' . &l:path63endif64 65if exists("g:loaded_delimitMate")66    if exists("b:delimitMate_excluded_regions")67        let b:rust_original_delimitMate_excluded_regions = b:delimitMate_excluded_regions68    endif69 70    augroup rust.vim.DelimitMate71        autocmd!72 73        autocmd User delimitMate_map   :call rust#delimitmate#onMap()74        autocmd User delimitMate_unmap :call rust#delimitmate#onUnmap()75    augroup END76endif77 78" Integration with auto-pairs (https://github.com/jiangmiao/auto-pairs)79if exists("g:AutoPairsLoaded") && !get(g:, 'rust_keep_autopairs_default', 0)80    let b:AutoPairs = {'(':')', '[':']', '{':'}','"':'"', '`':'`'}81endif82 83if has("folding") && get(g:, 'rust_fold', 0)84    let b:rust_set_foldmethod=185    setlocal foldmethod=syntax86    if g:rust_fold == 287        setlocal foldlevel<88    else89        setlocal foldlevel=9990    endif91endif92 93if has('conceal') && get(g:, 'rust_conceal', 0)94    let b:rust_set_conceallevel=195    setlocal conceallevel=296endif97 98" Motion Commands {{{199if !exists("g:no_plugin_maps") && !exists("g:no_rust_maps")100    " Bind motion commands to support hanging indents101    nnoremap <silent> <buffer> [[ :call rust#Jump('n', 'Back')<CR>102    nnoremap <silent> <buffer> ]] :call rust#Jump('n', 'Forward')<CR>103    xnoremap <silent> <buffer> [[ :call rust#Jump('v', 'Back')<CR>104    xnoremap <silent> <buffer> ]] :call rust#Jump('v', 'Forward')<CR>105    onoremap <silent> <buffer> [[ :call rust#Jump('o', 'Back')<CR>106    onoremap <silent> <buffer> ]] :call rust#Jump('o', 'Forward')<CR>107endif108 109" Commands {{{1110 111" See |:RustRun| for docs112command! -nargs=* -complete=file -bang -buffer RustRun call rust#Run(<bang>0, <q-args>)113 114" See |:RustExpand| for docs115command! -nargs=* -complete=customlist,rust#CompleteExpand -bang -buffer RustExpand call rust#Expand(<bang>0, <q-args>)116 117" See |:RustEmitIr| for docs118command! -nargs=* -buffer RustEmitIr call rust#Emit("llvm-ir", <q-args>)119 120" See |:RustEmitAsm| for docs121command! -nargs=* -buffer RustEmitAsm call rust#Emit("asm", <q-args>)122 123" See |:RustPlay| for docs124command! -range=% -buffer RustPlay :call rust#Play(<count>, <line1>, <line2>, <f-args>)125 126" See |:RustFmt| for docs127command! -bar -buffer RustFmt call rustfmt#Format()128 129" See |:RustFmtRange| for docs130command! -range -buffer RustFmtRange call rustfmt#FormatRange(<line1>, <line2>)131 132" See |:RustInfo| for docs133command! -bar -buffer RustInfo call rust#debugging#Info()134 135" See |:RustInfoToClipboard| for docs136command! -bar -buffer RustInfoToClipboard call rust#debugging#InfoToClipboard()137 138" See |:RustInfoToFile| for docs139command! -bar -nargs=1 -buffer RustInfoToFile call rust#debugging#InfoToFile(<f-args>)140 141" See |:RustTest| for docs142command! -buffer -nargs=* -count -bang RustTest call rust#Test(<q-mods>, <count>, <bang>0, <q-args>)143 144if !exists("b:rust_last_rustc_args") || !exists("b:rust_last_args")145    let b:rust_last_rustc_args = []146    let b:rust_last_args = []147endif148 149" Cleanup {{{1150 151let b:undo_ftplugin = "152            \ compiler make |153            \ setlocal formatoptions< comments< commentstring< include< includeexpr< suffixesadd<154            \|if exists('b:rust_set_style')155                \|setlocal tabstop< shiftwidth< softtabstop< expandtab< textwidth<156                \|endif157                \|if exists('b:rust_original_delimitMate_excluded_regions')158                    \|let b:delimitMate_excluded_regions = b:rust_original_delimitMate_excluded_regions159                    \|unlet b:rust_original_delimitMate_excluded_regions160                    \|else161                        \|unlet! b:delimitMate_excluded_regions162                        \|endif163                        \|if exists('b:rust_set_foldmethod')164                            \|setlocal foldmethod< foldlevel<165                            \|unlet b:rust_set_foldmethod166                            \|endif167                            \|if exists('b:rust_set_conceallevel')168                                \|setlocal conceallevel<169                                \|unlet b:rust_set_conceallevel170                                \|endif171                                \|unlet! b:rust_last_rustc_args b:rust_last_args172                                \|delcommand -buffer RustRun173                                \|delcommand -buffer RustExpand174                                \|delcommand -buffer RustEmitIr175                                \|delcommand -buffer RustEmitAsm176                                \|delcommand -buffer RustPlay177                                \|delcommand -buffer RustFmt178                                \|delcommand -buffer RustFmtRange179                                \|delcommand -buffer RustInfo180                                \|delcommand -buffer RustInfoToClipboard181                                \|delcommand -buffer RustInfoToFile182                                \|delcommand -buffer RustTest183                                \|silent! nunmap <buffer> [[184                                \|silent! nunmap <buffer> ]]185                                \|silent! xunmap <buffer> [[186                                \|silent! xunmap <buffer> ]]187                                \|silent! ounmap <buffer> [[188                                \|silent! ounmap <buffer> ]]189                                \|setlocal matchpairs-=<:>190                                \|unlet b:match_skip191                                \"192 193" }}}1194 195" Code formatting on save196augroup rust.vim.PreWrite197    autocmd!198    autocmd BufWritePre *.rs silent! call rustfmt#PreWrite()199augroup END200 201setlocal matchpairs+=<:>202" For matchit.vim (rustArrow stops `Fn() -> X` messing things up)203let b:match_skip = 's:comment\|string\|rustCharacter\|rustArrow'204 205command! -buffer -nargs=+ Cargo call cargo#cmd(<q-args>)206command! -buffer -nargs=* Cbuild call cargo#build(<q-args>)207command! -buffer -nargs=* Ccheck call cargo#check(<q-args>)208command! -buffer -nargs=* Cclean call cargo#clean(<q-args>)209command! -buffer -nargs=* Cdoc call cargo#doc(<q-args>)210command! -buffer -nargs=+ Cnew call cargo#new(<q-args>)211command! -buffer -nargs=* Cinit call cargo#init(<q-args>)212command! -buffer -nargs=* Crun call cargo#run(<q-args>)213command! -buffer -nargs=* Ctest call cargo#test(<q-args>)214command! -buffer -nargs=* Cbench call cargo#bench(<q-args>)215command! -buffer -nargs=* Cupdate call cargo#update(<q-args>)216command! -buffer -nargs=* Csearch  call cargo#search(<q-args>)217command! -buffer -nargs=* Cpublish call cargo#publish(<q-args>)218command! -buffer -nargs=* Cinstall call cargo#install(<q-args>)219command! -buffer -nargs=* Cruntarget call cargo#runtarget(<q-args>)220 221let b:undo_ftplugin .= '222            \|delcommand -buffer Cargo223            \|delcommand -buffer Cbuild224            \|delcommand -buffer Ccheck225            \|delcommand -buffer Cclean226            \|delcommand -buffer Cdoc227            \|delcommand -buffer Cnew228            \|delcommand -buffer Cinit229            \|delcommand -buffer Crun230            \|delcommand -buffer Ctest231            \|delcommand -buffer Cbench232            \|delcommand -buffer Cupdate233            \|delcommand -buffer Csearch234            \|delcommand -buffer Cpublish235            \|delcommand -buffer Cinstall236            \|delcommand -buffer Cruntarget'237 238" vint: -ProhibitAbbreviationOption239let &cpo = s:save_cpo240unlet s:save_cpo241" vint: +ProhibitAbbreviationOption242 243" vim: set et sw=4 sts=4 ts=8:244 
codekingpro/portable-devtools · Team Ai