I want my Vim to run some commands, such as setlocal spell spelllang=en_us
when I edit a file with extension of en
, e.g. abc.en
. How can I implement this?
If you're on a Linux system right now, open up a terminal and type vim filename. Enter insert mode and type a bit (or copy some of the text from this article into Vim) and then hit Escape to start practicing movement around the file.
You can run commands in Vim by entering the command mode with : . Then you can execute external shell commands by pre-pending an exclamation mark ( ! ). For example, type :! ls , and Vim will run the shell's ls command from within Vim.
By default, Vim starts with a single window, which is enough for editing a single file. But sometimes, you may have to work on multiple files. Vim makes it easier to work with multiple files at once with its window management system, allowing you to work on multiple files at the same time within a single Vim session.
augroup spell_settings
au!
" set en_us as default language (unknown extension):
au BufEnter * setlocal spell spelllang=en_us
" set en_us for en files specifically:
au BufEnter *.en setlocal spell spelllang=en_us
" to add multiple commands just append:
au BufEnter *.en setlocal syntax on
augroup END
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With