5

Does something like this exist? In Vim this is called an autocommand. The relevant help topic can be found by typing :h autocommand (sic!) An example code to put into vimrc: augroup typescript_save | au! autocmd BufWritePost *.ts execute '!tsc' expand("<afile>:p:S") augroup end


3

You could try something like the following: #!/bin/bash file=$1 cat $file | vim -c "doautocmd BufRead $file" - This will run the autocommands that would normally run, when you would open a file with the given name. This includes filetype detection. To my surprise, this also works when the file name contains a space. The name is only used to run the ...


3

You can use multiple filetype names separated with . # in your personal filetype.vim augroup filetypedetect au! BufRead,BufNewFile *.usenet setfiletype mail.usenet augroup END All mail filetype plugins and syntax files will be applied before usenet filetype plugins and syntax files. All mail related stuff (abbreviations, snippets, balabalas) should work ...


3

To enable filetype detection, add the following command to your vimrc: filetype on Then, for each filetype you want settings for, create a Vimscript file in the following location: ~/.vim/after/ftplugin/ Name the file with the filetype you want it to apply to, so for e.g. a Python settings file, create: ~/.vim/after/ftplugin/python.vim For more details,...


3

As discussed in the comments, this behaviour is caused by cindent. You can check what's setting this with the command: :verbose set cindent?


2

Change your FileType autocommand to autocmd Filetype txt ++nested colorscheme NiceTheme to allow for nesting (by default, they do not nest). See :h autocmd-nested (and thanks to Matt for the tip).


2

What you are missing is the (highly subjective) organization. Ideally each of the lines would be in separate files, which makes debugging easier and helps you to group things together. In other words, do you immediately know what filetypes you overrule by looking at the name ftdetect/mine.vim? What about ftdetect/vim_test.vim and ftdetect/h_test.vim? As ...


2

First as a general advice, :h :verbose is a good way to debug stuff with Vim: *:verb* *:verbose* :[count]verb[ose] {command} Execute {command} with 'verbose' set to [count]. If [count] is omitted one is used. ":0verbose" can be used to set 'verbose' to zero. So using :verbose set ft? in the ...


2

Create a syntax/usenet.vim with the contents: " Quit when a syntax file was already loaded if exists("b:current_syntax") finish endif runtime! syntax/mail.vim let b:current_syntax = "usenet" In short, just source the file you want to inherit syntax from. If you want any customizations for usenet, just make them after you've sourced syntax/mail.vim.


2

Add to ~/.vim/ftdetect/sage.vim (create if not present): au BufNewFile,BufRead *.sage setfiletype python cf. Learn Vimscript the Hard Way, which directs to appropriate help pages.


1

Thanks to D. Ben Knoble above. Moving the file from ~/.config/nvim/ftplugins/pandoc.vim to ~/.config/nvim/after/ftplugins/pandoc.vim made it work. Not that it explains why it didn't work before.


1

To avoid false positives with a pattern like *markdown*, use * and then filter in the code that you run from the autocmd: autocmd FileType * call s:CheckMarkdown() function s:CheckMarkdown() if match(&filetype, '\v<markdown>') != -1 return endif " ... run your desired side-effects endfunction


Only top voted, non community-wiki answers of a minimum length are eligible