Skip to content

Commit

Permalink
Extract filetype-specific setups to ftplugin
Browse files Browse the repository at this point in the history
Vim's documentation advises that buffer-specific configuration based on
a filetype should be performed via a file in `$HOME/.vim/ftplugin`:
http://vimdoc.sourceforge.net/htmldoc/usr_41.html#41.12

This change moves CSS/Sass-, Git commit message-, and Markdown-related
editor settings into `ftplugin/gitcommit.vim` and
`ftplugin/markdown.vim`, and rewrites those settings to avoid using
`autocmd`, letting Vim execute `setlocal` when a file of the filetype is
determined or set.
  • Loading branch information
geoffharcourt committed Dec 18, 2015
1 parent 2d9e8bf commit f02eab0
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 13 deletions.
1 change: 1 addition & 0 deletions vim/ftplugin/css.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
setlocal iskeyword+=-
3 changes: 3 additions & 0 deletions vim/ftplugin/gitcommit.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
" Automatically wrap at 72 characters and spell check commit messages
setlocal textwidth=72
setlocal spell
5 changes: 5 additions & 0 deletions vim/ftplugin/markdown.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
" Enable spellchecking
setlocal spell

" Automatically wrap at 80 characters
setlocal textwidth=80
1 change: 1 addition & 0 deletions vim/ftplugin/sass.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
setlocal iskeyword+=-
1 change: 1 addition & 0 deletions vim/ftplugin/scss.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
setlocal iskeyword+=-
13 changes: 0 additions & 13 deletions vimrc
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,6 @@ augroup vimrcEx
autocmd BufRead,BufNewFile Appraisals set filetype=ruby
autocmd BufRead,BufNewFile *.md set filetype=markdown
autocmd BufRead,BufNewFile .{jscs,jshint,eslint}rc set filetype=json

" Enable spellchecking for Markdown
autocmd FileType markdown setlocal spell

" Automatically wrap at 80 characters for Markdown
autocmd BufRead,BufNewFile *.md setlocal textwidth=80

" Automatically wrap at 72 characters and spell check git commit messages
autocmd FileType gitcommit setlocal textwidth=72
autocmd FileType gitcommit setlocal spell

" Allow stylesheets to autocomplete hyphenated words
autocmd FileType css,scss,sass setlocal iskeyword+=-
augroup END

" Softtabs, 2 spaces
Expand Down

0 comments on commit f02eab0

Please sign in to comment.