Skip to content

Commit 94cfd1b

Browse files
committed
Set softtabstop, textwidth, and optionally colorcolumn
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.
1 parent c649204 commit 94cfd1b

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

src/etc/vim/doc/rust.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
*rust.txt* Filetype plugin for Rust
22

33
==============================================================================
4-
CONTENTS *rust*
4+
CONTENTS *rust* *ft-rust*
55

66
1. Introduction |rust-intro|
77
2. Settings |rust-settings|
@@ -34,6 +34,12 @@ g:rustc_makeprg_no_percent~
3434
let g:rustc_makeprg_no_percent = 1
3535
<
3636

37+
*g:rust_colorcolumn*
38+
g:rust_colorcolumn~
39+
Set this option to use 'colorcolumn' to highlight the text width
40+
indicate the 100 column recommended hard limit on line lengths: >
41+
let g:rust_colorcolumn = 1
42+
<
3743
*g:rust_conceal*
3844
g:rust_conceal~
3945
Set this option to turn on the basic |conceal| support: >

src/etc/vim/ftplugin/rust.vim

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
" Description: Vim syntax file for Rust
33
" Maintainer: Chris Morgan <[email protected]>
44
" Maintainer: Kevin Ballard <[email protected]>
5-
" Last Change: May 27, 2014
5+
" Last Change: July 06, 2014
66

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

38-
setlocal tabstop=4 shiftwidth=4 expandtab
38+
setlocal tabstop=4 shiftwidth=4 softtabstop=4 expandtab
39+
40+
" Line lengths {{{2
41+
42+
" Rust style conventions for line lengths say you SHOULD not go over 80
43+
" columns and MUST not go over 100.
44+
" Without a good 'formatexpr' we can't automatically wrap code, but we can
45+
" still wrap comments just fine with 'textwidth'.
46+
setlocal textwidth=80
47+
48+
" We can also use 'colorcolumn' to highlight both the 80 and 100 limits. Not
49+
" everyone likes this so it's gated.
50+
if exists('g:rust_colorcolumn')
51+
setlocal colorcolumn=+1,101
52+
let b:rust_colorcolumn=1
53+
endif
54+
55+
" }}}2
3956

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

95112
let b:undo_ftplugin = "
96-
\setlocal formatoptions< comments< commentstring< includeexpr< suffixesadd<
113+
\ setlocal formatoptions< comments< commentstring< includeexpr< suffixesadd<
114+
\|setlocal tabstop< shiftwidth< softtabstop< expandtab< textwidth<
115+
\|if exists('b:rust_colorcolumn')
116+
\|setlocal colorcolumn<
117+
\|unlet b:rust_colorcolumn
118+
\|endif
97119
\|if exists('b:rust_original_delimitMate_excluded_regions')
98120
\|let b:delimitMate_excluded_regions = b:rust_original_delimitMate_excluded_regions
99121
\|unlet b:rust_original_delimitMate_excluded_regions

0 commit comments

Comments
 (0)