Skip to content

Commit 6c38a6b

Browse files
author
Akshay Hegde
committed
Conform to existing conventions for Vim ftplugin
This commit adds standard conventions for Vim filetype plugins: - Allows users to opt out of using the provided ftplugin file, if they choose to install and use another set of runtime files for Swift (which offers its own version of ftplugin for Swift), It also prevents this ftplugin file from being sourced again if a ftplugin file for Swift was already sourced. Vim's documentation on this recommends offering users this option as well, under the "DISABLING" section of `:help write-filetype-plugin`). - Adds the `b:undo_ftplugin` buffer local variable, which is used to undo the filetype settings when the `:setfiletype` command is used (See :help `undo_ftplugin`). Also prefer using the full names for Vim settings instead of short ones as they are more readable. The above conventions are in place in many of the ftplugin files shipped with Vim, so they can be used as a reference, as well.
1 parent 949b0c0 commit 6c38a6b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

utils/vim/ftplugin/swift.vim

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,16 @@
66
" See https://swift.org/LICENSE.txt for license information
77
" See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
88

9+
" Only do this when not done yet for this buffer
10+
if exists("b:did_ftplugin")
11+
finish
12+
endif
13+
14+
let b:did_ftplugin = 1
15+
let b:undo_ftplugin = "setlocal comments< expandtab< tabstop< shiftwidth< smartindent<"
16+
917
setlocal comments=s1:/*,mb:*,ex:*/,:///,://
1018
setlocal expandtab
11-
setlocal ts=2
12-
setlocal sw=2
19+
setlocal tabstop=2
20+
setlocal shiftwidth=2
1321
setlocal smartindent

0 commit comments

Comments
 (0)