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


4

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


4

Function defined in ftplugins In ftplugins we can define script local functions and global functions that are defined only when a buffer of the given filtetype is loaded. In the second case, the function is still global and can be hidden by any other script. In both cases, the functions will be redefined every time a new buffer of the same filetype is opened,...


3

There are, in fact, some predefined build scripts, and it is relatively straightforward to create your own. These are known as compiler plugins or scripts, and live in the compiler directory of runtimepath. You can switch to a compiler with the :compiler command, or by setting makeprg and errorformat (which is what most of these scripts do). You then build ...


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


3

As Martin mentions in the comments, the two events match on different things. It would be simpler to make a function and use two autocommands (the combined form works best when both match on the same types of things): function DoIt() abort endfunction augroup my_c_stuff autocmd! autocmd FileType c call DoIt() autocmd TextChangedI *.c call DoIt() ...


3

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


2

Yes, setting some options in Vim may have various side effects (see source code). In particular, setting &filetype and &syntax triggers the corresponding autocommands, even if invoked from inside another autocommand and no nested attribute is provided. I'm not sure if it's documented anywhere, but standard Vim scripts, such as filetype.vim etc., ...


2

Most “core” filetype features are covered by autocommands, so disabling them will have the effect that you want. But we only want to disable them when opening a particular file, so :noautocmd edit {file} I’ll update with more information on the autocommands and features when I get to my laptop.


1

The error you are seeing looks more like a Bash error than a Vim error. For example, here is what I get when I run your command from Bash: $ filetype plugin indent on -bash: filetype: command not found Note that error identifier (i.e., EXXX) characteristic of Vim error messages does not appear in the output. Here is what I get when I try to run an invalid ...


1

The most accurate and compliant way is to extend filetypes with after/ftplugin/{text,markdown}.vim. Your "no extension" files can probably be detected as "text" filetype as well (or create a completely new filetype if you like). Then the actual functionality should be shared by a common autoloaded script. But if you don't care then a ...


1

You can use the value of &filetype to determine if you are in a buffer without a filetype or with one of the filetype you want to target. One example could be like this: function! DoStuff() if (exists('b:StuffDone') || index(['', 'text', 'markdown'], &ft) < 0) return endif let b:StuffDone = 1 echo "Doing stuff for&...


1

'wildignore' is a list of file patterns which be ignored for completing (among other things as well) set wildignore+=*.class 'suffixes' is a list of file suffixes which will lower the priority of filename in completion set suffixes+= class For more help see: :h 'wildignore' :h 'suffixes'


1

autocmd FileType man wincmd _ should work okay. Most probably you have a typo (e.g. in your post it's "dash" instead of "underscore"). Concerning auto-events, not all of them are bound to follow specific sequence. For example, FileType is triggered right after 'filetype' option was set. For whatever reason.


1

Caveat: I don't have the :Man command which you have presumably defined yourself, but this should work: autocmd BufEnter * if &filetype ==# "man" | wincmd _ | endif


1

As Matt notes, smartindent is enough. Not only this, but cindent is actively harmful! Many years ago, when I first got started with vim, I had these both set globally in my vimrc. Eventually, through spurious indenting issues such as these, I came to realize that in fact they make bad global settings. cindent is too specific; it works for C stuff. Don't set ...


1

One solution is to use a filetype plugin (:h ftplugin). First, you need to enable them with filetype plugin on (in your vimrc). Then, you can add a file in vim/after/ftplugin/FILETYPE.vim, replacing FILETYPE with what's needed. This file will then be sourced by vim for each file matching the filetype, allowing them to use whatever is in your plugin. Drop ...


1

I'm using a workaround on this topic. I have a function in my library plugin where I register all the filetypes I've encountered that relates to text, IOW they are non-programming filetypes. " Function: lh#ft#is_text(...) {{{3 function! lh#ft#is_text(...) let ft = a:0 == 0 ? &ft : (a:1) return ft =~ '^$\|text\|latex\|tex\|html\|docbk\|help\|mail\...


1

When in doubt look into the standard Vim runtime files. ts sts et sw should be set by after/ftplugin. sta is basically no-op, as you have &sw == &sts anyway. si ai are basically no-op as you have &cindent on. And also, in general, there's nothing in setting ai si on if you have any meaningful indent/xyz.vim. cino should probably be set by after/...


1

It is not quite answering the question, but you can run :make to compile from vim, and will allow you to jump to the location of the first error. Then, you can run :cwindow to display the quickfix window, to have the list of errors in a split. The quickfix will have some color highlight: Bringing your cursor on an error line and pressing return will make ...


1

I solved this problem by using neovim instead of vim. Neovim gave me a better error message: unkown option: --layout=reverse-list from there i realized that I was using an outdated version of fzf, and neovim updated and problem solved!


1

When you paste something in insert mode, paste option makes a huge difference. And if you don't want to toggle it then try using normal mode pasting invoked from insert mode mapping. This is the naive attempt to solve your pasting issue: inoremap <S-Insert> <ESC>"*p`]a go to normal mode with <ESC> paste from * register with "*p ...


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

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

using the command runtime! syntax/java.vim will execute all the commands from the specified syntax file. It does the trick but the syntax variable is still set to the filetype as explained by the answer of mMontu


1

A More Modern (2020) Answer for Vim 8+ Because it's been a few years I figured that there's might be a better solution to this question for Vim 8+, so I asked over here: How to autoload multiple rc-style files in Vim 8+ And it turns out that there is!! Create a vimrc "plugin" (easy) I don't know if this is the "best" way to do it, but it ...


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