Using ftplugin to tidy my Vim configuration

I’ve used Vim on and off for a long time. I got introduced to it at University
by a lecturer, tried it, didn’t get it, and moved on. I then decided to learn it
more seriously and spent a lot of time configuring it, as my
dotfiles repository shows. It’s…

I’ve used Vim on and off for a long time. I got introduced to it at University
by a lecturer, tried it, didn’t get it, and moved on. I then decided to learn it
more seriously and spent a lot of time configuring it, as my
dotfiles repository shows. It’s on
1203 commits!

Often in Vim you’ll want to have different settings for different filetypes.
Foexample I want to configure Markdown files to have spell-check turned on at
all times, but when I’m coding I don’t care for spell-check being on.

In the past I would have done this with an autocmd:

autocmd FileType markdown setlocal spell spelllang=en_gb

But then your vimrc (or init.vim for Neovim users like me!) gets cluttered
with these and it’s hard to keep up, or find exactly where you configured those
Markdown settings.

Instead, you can use ftplugins for this case! A ftplugin is a file type plugin
that will be run automatically when Vim detects you’re editing a file of that
type.

So instead of cluttering up my vimrc with autocmd lines, I can instead
create ~/.config/nvim/ftplugin/markdown.vim with the settings I want in:

setlocal spell spelllang=en_gb

If you’re using Vim, not Neovim, you can create
~/.vim/ftplugin/markdown.vim.

This keeps my vimrc tidy, and my dotfiles easier to manage. It’s very
straightforward to remember which settings I’ve applied globally (they are in my
vimrc) or per-filetype, in which case I can dive into my ftplugins folder.


Print Share Comment Cite Upload Translate
APA
Jack Franklin | Sciencx (2024-03-29T01:49:25+00:00) » Using ftplugin to tidy my Vim configuration. Retrieved from https://www.scien.cx/2020/05/10/using-ftplugin-to-tidy-my-vim-configuration/.
MLA
" » Using ftplugin to tidy my Vim configuration." Jack Franklin | Sciencx - Sunday May 10, 2020, https://www.scien.cx/2020/05/10/using-ftplugin-to-tidy-my-vim-configuration/
HARVARD
Jack Franklin | Sciencx Sunday May 10, 2020 » Using ftplugin to tidy my Vim configuration., viewed 2024-03-29T01:49:25+00:00,<https://www.scien.cx/2020/05/10/using-ftplugin-to-tidy-my-vim-configuration/>
VANCOUVER
Jack Franklin | Sciencx - » Using ftplugin to tidy my Vim configuration. [Internet]. [Accessed 2024-03-29T01:49:25+00:00]. Available from: https://www.scien.cx/2020/05/10/using-ftplugin-to-tidy-my-vim-configuration/
CHICAGO
" » Using ftplugin to tidy my Vim configuration." Jack Franklin | Sciencx - Accessed 2024-03-29T01:49:25+00:00. https://www.scien.cx/2020/05/10/using-ftplugin-to-tidy-my-vim-configuration/
IEEE
" » Using ftplugin to tidy my Vim configuration." Jack Franklin | Sciencx [Online]. Available: https://www.scien.cx/2020/05/10/using-ftplugin-to-tidy-my-vim-configuration/. [Accessed: 2024-03-29T01:49:25+00:00]
rf:citation
» Using ftplugin to tidy my Vim configuration | Jack Franklin | Sciencx | https://www.scien.cx/2020/05/10/using-ftplugin-to-tidy-my-vim-configuration/ | 2024-03-29T01:49:25+00:00
https://github.com/addpipe/simple-recorderjs-demo