Vim loads multiple files as described in
ftplugin/, you can add files like
rust.vim where you define options for this filetype only.
You may need to put the config in
after/ftplugin to overwrite options set by other config files.
Considering this, a basic approach for your problem is to drop everything you rust-specific config in
However, you can go further and use
(after/)compiler/ and so on, to organize your config even more.
Note that the options you set are not automatically restored. This can be a problem when the buffer's filetype changes: an option set for the first filetype will be preserved if it's not set for the second.
To avoid this problem, it's recommended to set the
b:undo_ftplugin variable, to a value that resets each option you changed to its default.
indent plugin, use
Putting it all together, you could have this in
" set options locally
" get a pre-existing `undo_indent` variable
let b:undo_ftplugin = get(b:, 'undo_indent', '')
" add a '|' to chain commands if `undo_indent` was set
if ! empty('b:undo_indent')
let b:undo_indent .= ' | '
" `set option< `restores `option` to its global value
" `.=` appends to the string
let b:undo_indent .= "setlocal colorcolumn< foldmethod< suffixesadd< path<"