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 !tsc <afile>:p:S augroup end


4

You're in luck: the after directory exists for exactly this reason. ~/.vim/after is usually the last entry of 'runtimepath', so that whatever a user puts there overrides anything before it. Since it can house a full runtime, you can put anything you would put in ~/.vim in ~/.vim/after! I use this commonly for ~/.vim/after/ftplugin to override previous ...


4

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,...


4

Create ~/.vim/ftdetect/SOME_EXTENSION.vim and add this line to it: autocmd BufNewFile,BufRead *.SOME_EXTENSION set filetype=SOME_FILETYPE So if you wanted vim to use the filetype html for all files with an .Rhtml extension you would add this to ~/.vim/ftdetect/rhtml.vim: autocmd BufNewFile,BufRead *.Rhtml set filetype=html


4

Vim will load filetype-specific commands from an ftplugin. See :help ftplugin. In short, you can create a file under ~/.vim/ftplugin (or %HOME%\vimfiles\ftplugin on Windows), or better ~/.vim/after/ftplugin (or %HOME%\vimfiles\after\ftplugin) named after the filetype for which it should be loaded. For example, when a file is detected with filetype=tex, Vim ...


3

Put this into ~/.vim/ftdetect/dist.vim autocmd BufNewFile,BufRead ?\+.dist \ execute 'doautocmd filetypedetect BufRead' fnameescape(expand('<afile>:r')) Basically we strip the .dist extension and re-execute the filetype-detection routine. A similar code is used in $VIMRUNTIME/filetype.vim to detect filetype for *.bak, *.old and a few other "...


3

The reason for this is that both *.adoc and *.fr.adoc match for foo.fr.adoc, so both autocmds are run. The documentation for autocmd patterns is at :help file-pattern; looking at it, doing a robust "match *.adoc but not fr.adoc" is a bit tricky (though not impossible). Personally, I would opt for just an if: autocmd BufNewFile *.adoc \ if ...


3

Just use :h map-<expr> instead of auto-commands. let FT_IGNORE_QUOTES = ['vim', 'markdown', 'help'] inoremap <expr>' index(FT_IGNORE_QUOTES, &ft) < 0 ? "''<left>" : "'" inoremap <expr>" index(FT_IGNORE_QUOTES, &ft) < 0 ? '""<left>' : '"'


3

Your problem is due to :setf[iletype] command. From :h :setf Set the 'filetype' option to {filetype}, but only if not done yet in a sequence of (nested) autocommands. As your autocmd is surely run after all the bundled stuff, the filetype for the current buffer might be set already. Then your command has no effect. Use plain :set filetype=sh if you're ...


3

UPDATE: Latest vimtex includes PR #1711 which allows you to configure vimtex to override existing mappings by setting this global variable from your vimrc: let g:vimtex_mappings_override_existing = 1 So the recommended solution for this problem is update your vimtex to latest and include this variable setting in your vimrc. OLDER UPDATE: It turns out ...


2

Ftplugin As mentioned do put settings pertaining to a certain file type in ftplugin. Separate into Files Break up code into different files. For example where my vimrc file is, there is a sub init/ dir which contains other files I wish to load at startup. To load them I use the below code. <sfile> evaulates to the current file (init.vim or .vimrc in ...


2

One simple tweak is to use \%^ which only matches at the start of the file. You'll also want to pass search() a 'c' flag, to match at the current cursor position (which should be the start of the file.) au BufRead,BufNewFile * \ if search('\%^---', "cn") | \ set filetype=diff | \ endif Another option would be to use getline(1) to get the contents ...


2

So the whole point is that if &filetype is of the form x.y then Vim automatically loads indents and syntaxes from both x.vim and y.vim. Then the code in syntax/y.vim must take this into account and keep the previous value of b:current_syntax. So instead of usual: if exists('b:current_syntax') | finish | endif, or unlet b:current_syntax it should start ...


2

[Thanks to @DBenKnoble for his insight. It led me right to the solution.] When using "views" to store vim sessions snapshots, watch for the value(s) of the vop option parameter. For more info :h vop. Its default is: set viewoptions=cursor,folds,options,curdir Use of folds in the above conflicts with the use of ~/.vim/after/ftplugin/*.vim files. You can ...


2

I did find an alternative approach, which is to put my autocmds instead in ~/.vim/filetype.vim. They seem to be evaluated first over autocmds in plugins.


2

Vim 8.1.2250 does not ship with filetype detection for solidity. (One can confirm with :edit $VIMRUNTIME/filetype.vim and then :global /sol/.) ALE has Solidity linters, but they require the filetype to be set. The simplest solution is to create ~/.vim/ftdetect/solidity.vim and add au BufNewFile,BufRead *.sol setfiletype solidity However, this plugin ...


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

Assuming1 that the plugin is using the standard scheme for filetype specific configuration... Probably the simplest way to override is by creating a file in $MYVIMDIR/after/ftplugin with filename that matches the filetype (aka ft) setting when such a file is loaded. The plugin likely has a file of the same name and it will either be in directory ftplugin ...


1

A couple of other tips-n-tricks: with tpope/scriptease, you can use :Vedit (and other variants) to fill the location list with all runtimepath entries matching the provided file (e.g., :Vedit ftplugin/tex.vim) to actually put an autocommand on a specific filetype, such as "automatically run :Require on clojure files when they save," you can use a &...


1

Your Vundle configuration looks incorrect. You should call vundle#begin() at the start, before the Bundle commands. And you should call vundle#end() at the end of that section, before you re-enable filetype detection and plug-ins. (The vundle#rc() function is an old way to initialize Vundle, it's deprecated now in favor of vundle#begin().) See the Vundle ...


1

The problem you're having happens because you have two mappings that conflict with each other, in that you have a second longer mapping that starts with ,c, so when you type ,c Vim doesn't know right away whether you want to invoke the commenting mapping (which is ,c) or whether you are about to type the additional keys to invoke the longer mapping. The ...


1

One way to do it is just force the filetype: vim <(script | ...) -c 'set filetype=html' Or inside vim :set filetype=javascript (For example)


1

It turns out, there is a subtle interaction between FileType events and the actual ftplugin mechanism. When the filetype is changed, all matching FileType events are run. As near as I can tell, this is one of the first things to be done. So the current "state" would include both the buffer-local mapping and the b:undo_ftplugin necessary to undo it. This ...


1

Explaining the steps you can use to troubleshoot such issues. First, you can use a command such as :au BufRead *.mm to inspect which autocmds exist for that particular extension. You can use that to double check that your configuration actually took effect. (Which it did in your case.) Second, you can use command :verbose set ft? to inspect the filetype ...


1

If in specific you would like to avoid the mklink on Windows or symlinks on Linux/Unix/Mac, you can use small files for the specific languages that simply load base.vim. The technique is recommended in :help :syn-files: When a language is a superset of another language, it may include the other one, for example, the cpp.vim file could include the c.vim ...


1

The fact that you are getting this message on your verbose log file is expected. The Vim source code has an explicit comment about that: /* * When using ":silent! cmd" ignore error messages. * But do write it to the redirection file. */ I linked to the code in Vim 7.4, but Vim 8.2 still has the same exact snippet and exhibits the same behavior. I ...


1

Within cpp.vim put: source <sfile>:h/c.vim <sfile> expands to the currently sourced file, and :h means the head of it.


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