Skip to content

Commit

Permalink
Set softtabstop, textwidth, and optionally colorcolumn
Browse files Browse the repository at this point in the history
Setting softtabstop makes <Del> delete 4 spaces as if it were a tab.

Setting textwidth allows comments to be wrapped automatically. It's set
at 80, which is the recommended line length for Rust programs. There are
suggestions that it should be 79, but our current style guide says 80 so
that's what we're matching.

A new setting g:rust_colorcolumn sets colorcolumn as well, to +1,101.
This indicates both the textwidth and the second stricter line length of
100 that our style guide lists.
  • Loading branch information
lilyball committed Jul 8, 2014
1 parent c649204 commit 94cfd1b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/etc/vim/doc/rust.txt
@@ -1,7 +1,7 @@
*rust.txt* Filetype plugin for Rust

==============================================================================
CONTENTS *rust*
CONTENTS *rust* *ft-rust*

1. Introduction |rust-intro|
2. Settings |rust-settings|
Expand Down Expand Up @@ -34,6 +34,12 @@ g:rustc_makeprg_no_percent~
let g:rustc_makeprg_no_percent = 1
<

*g:rust_colorcolumn*
g:rust_colorcolumn~
Set this option to use 'colorcolumn' to highlight the text width
indicate the 100 column recommended hard limit on line lengths: >
let g:rust_colorcolumn = 1
<
*g:rust_conceal*
g:rust_conceal~
Set this option to turn on the basic |conceal| support: >
Expand Down
28 changes: 25 additions & 3 deletions src/etc/vim/ftplugin/rust.vim
Expand Up @@ -2,7 +2,7 @@
" Description: Vim syntax file for Rust
" Maintainer: Chris Morgan <me@chrismorgan.info>
" Maintainer: Kevin Ballard <kevin@sb.org>
" Last Change: May 27, 2014
" Last Change: July 06, 2014

if exists("b:did_ftplugin")
finish
Expand Down Expand Up @@ -35,7 +35,24 @@ silent! setlocal formatoptions+=j
" otherwise it's better than nothing.
setlocal smartindent nocindent

setlocal tabstop=4 shiftwidth=4 expandtab
setlocal tabstop=4 shiftwidth=4 softtabstop=4 expandtab

" Line lengths {{{2

" Rust style conventions for line lengths say you SHOULD not go over 80
" columns and MUST not go over 100.
" Without a good 'formatexpr' we can't automatically wrap code, but we can
" still wrap comments just fine with 'textwidth'.
setlocal textwidth=80

" We can also use 'colorcolumn' to highlight both the 80 and 100 limits. Not
" everyone likes this so it's gated.
if exists('g:rust_colorcolumn')
setlocal colorcolumn=+1,101
let b:rust_colorcolumn=1
endif

" }}}2

" This includeexpr isn't perfect, but it's a good start
setlocal includeexpr=substitute(v:fname,'::','/','g')
Expand Down Expand Up @@ -93,7 +110,12 @@ endif
" Cleanup {{{1

let b:undo_ftplugin = "
\setlocal formatoptions< comments< commentstring< includeexpr< suffixesadd<
\ setlocal formatoptions< comments< commentstring< includeexpr< suffixesadd<
\|setlocal tabstop< shiftwidth< softtabstop< expandtab< textwidth<
\|if exists('b:rust_colorcolumn')
\|setlocal colorcolumn<
\|unlet b:rust_colorcolumn
\|endif
\|if exists('b:rust_original_delimitMate_excluded_regions')
\|let b:delimitMate_excluded_regions = b:rust_original_delimitMate_excluded_regions
\|unlet b:rust_original_delimitMate_excluded_regions
Expand Down

0 comments on commit 94cfd1b

Please sign in to comment.