Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: run some command when editing specific file

Tags:

vim

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?

like image 884
remy Avatar asked Mar 20 '12 16:03

remy


People also ask

How do I run a .Vim file in Linux?

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.

How do I run a command in Vim?

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.

Can you edit multiple files in 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.


1 Answers

    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
like image 126
perreal Avatar answered Oct 12 '22 21:10

perreal