Questions tagged [filetype]

Questions about making Vim to have a defined behavior according the type of the edited file.

Filter by
Sorted by
Tagged with
3
votes
2answers
246 views

write a key command for a markdown comment

I've been messing about with file type specific commands this evening (which is going to be very useful) and I'm trying to write a markdown comment command at the moment. I'm not sure how to go about ...
3
votes
1answer
747 views

Using Pandoc with vim keybindings

I am trying to define a keymapping in vimrc to compile my markdown file with Pandoc. So I am using this: autocmd FileType markdown nmap <F9> :!pandoc % -o %:r.pdf <cr> But, in markdown ...
3
votes
1answer
916 views

Vim never shows line number for Python files even though I have `.vimrc`

I found it strange that I can never have Vim show line number automatically for .py files, even if I have this as my ~/.vimrc set background=dark autocmd FileType py,c set number Strangely enough, ...
3
votes
1answer
803 views

Set formatoptions for a specific file

In my ftplugin/plaintext.vim script, I have the formatoptions set for editing mostly prose: setlocal formatoptions=tcroqan1j However, in very specific instances -- particularly, Python's idiomatic ...
3
votes
2answers
533 views

Are commands in filetype plugins rerun every time the buffer is loaded?

Every time I switch back and forth between two buffers, vim tries to re-load some file specific commands. The error message is E174: Command already exists: add ! to replace it` I am using ...
3
votes
1answer
400 views

Jump to the definition in a scss file

How, in vim, can I jump to the mixin that is @includeed in a SCSS file? For example, I'd like to put the cursor over avatar below and hit some magic key in vim that'll take me to that mixin...but how?...
3
votes
1answer
84 views

Disabling `kana/vim-textobj-entire` by filetype autocommand

kana/vim-textobj-entire creates text-obejcts ae and ie which stand for the entire buffer. But in lervag/vimtex ae and ie stand for an environment in a .tex file. vimtex's ae and ie mappings are much ...
3
votes
1answer
176 views

How to exclude filetype with autocmd to load language specific skeleton

I have the following in order to use a different template per language. But I want English to be the default, if I don't specify .en.adoc in the filename. But the *.adoc,*.en.adoc also picks up *.fr....
3
votes
1answer
50 views

Ask if file extension is missing when opening new file

I use auto completion in my shell (zsh) and I'm often a bit sloppy. Scenario: Imagine I have the files sourcecode.c and sourcecode.h in the current directory. I type vim sour<TAB><ENTER> ...
3
votes
1answer
7k views

Why files in `~/.config/nvim/after/ftplugin/` are not taken into acount?

My neovim doesn't load file type plugins when loading a ruby/eruby file. Here is the corresponding configuration files: for f in ~/.config/nvim/after/ftplugin/* ; do echo "# $f" ; cat $f; done # /...
3
votes
2answers
618 views

How to tell vim to behave the same for file extension .in and .mako

I noticed Vim will choose the correct syntax when I open a file that ends with .c.in or .pl.in. I would like to tell Vim to behave the same with extensions like .c.mako or .pl.mako. How is it ...
3
votes
2answers
1k views

Syntax highlight fail for Prolog files

I'm having trouble configuring Vim on Manjaro: After setting syntax on at .vimrc file, I make a Prolog program (bug.pl) which shows no syntax highlight: But after I append /**/ to top of file (then ...
3
votes
1answer
3k views

In what order does Vim read ftplugin files, syntax files, and the .vimrc when the commands (e.g. set syntax=mysyntax, filetype plugin on) are called?

I've had some issues lately reconciling my .vimrc with files in ftplugin and after/ftplugin. In what order are all these things read? For example: when I call in my .vimrc the command plugin filetype ...
3
votes
1answer
152 views

Automate running SQL filetype scripts when opening a PHP file

When I open a PHP file in Vim I want Vim to provide SQL assistance as well as all the PHP assistance. From :h sql-completion-filetypes: This can be enabled easily with the following steps (assuming ...
3
votes
1answer
121 views

How to set filetype to PKGBUILD when the filename is PKGBUILD?

I want vim to automatically set the filetype to PKGBUILD when I am editing files that are named "PKGBUILD". How can I accomplish this?
3
votes
0answers
232 views

“^[[201~” character being pasted at the end of file

I'm trying to copy-paste by hand this file, but whenever I paste the contents in vim the last line shows this weird character at the end of the line ^[[201~. My guess is that it's one of those wrong ...
3
votes
0answers
452 views

Support for embedded languages

Vim supports syntax highlighting for embedded languages, also called fenced code (:h :syn-include). However, you usually want that other vim settings and mappings are adjusted for embedded languages ...
3
votes
0answers
64 views

Syntax-aware line wrapping

Is there a way to make the automatic line wrapping of vim aware of the syntax of the file instead of just wrapping at the closest whitespace? I am specifically interested in Python but I guess it ...
3
votes
0answers
54 views

Can I apply one file's filetype to another, without actually opening the first file?

For context, see How can I automate filetype detection when using sudoedit? Say filea has filetype foo, which is detected based on varying factors, including the name, the full path or the contents ...
3
votes
0answers
74 views

Filetype changes when using :split and :Explore

Why does using :split and :Explore cause the filetype to change? For example, edit a file named text.man, and the filetype is set to man. Change the filetype to txt, then :split and :Explore in the ...
2
votes
2answers
298 views

How do I elegantly override file type detection patterns with more specific patterns

I have a file in my ~/.vim/ftdetect directory, which includes configuration such as: autocmd BufRead,BufNewFile,BufWritePost .envrc.template set filetype=sh However, I also have the vim-polyglot ...
2
votes
2answers
71 views

Where do filetype-specific autocommands live?

I have a plugin for a specific filetype (*.tex), and I'm wondering where I can find all the commands which are executed when I type :e examplefile.tex? In general, is there a standardized practice for ...
2
votes
1answer
105 views

Vim different colorchemes for different file, but same backgroung color

I'd like to have a colorscheme but keeping my terminal color as a background color. This code achieved that colorscheme MyFavoriteOne autocmd ColorScheme * highlight Normal ctermbg=NONE guibg=NONE I'...
2
votes
1answer
92 views

Share configuration across `ftplugin` files without duplicating code

A lot of languages use curly braces {} to enclose code blocks, so it's nice to have a mapping something like: inoremap <buffer> {<CR> {<CR>}<Esc>O I have this mapping in ...
2
votes
1answer
1k views

Set mappings depending on file type

I'd like to set some file-type dependent mappings to quickly run files. For example, I have some mappings like these: nnoremap <silent><leader>z :w<CR> :!clear; gcc %; ./a.out<cr&...
2
votes
1answer
74 views

Why are nested FileType autocommands triggered even ++nested is not used?

From :h autocmd-nested, it says "By default, autocommands do not nest." But nested FileType events are triggered anyway without using ++nested. As seen in this test: autocmd BufNewFile,...
2
votes
1answer
180 views

How can I write a filetype plugin that evaluates the first lines of the file?

I'm trying to modify my filetype.vim such that it highlights a unified diff file with diff syntax, overriding whatever syntax is normally associated with the file's extension. So far, I'm just trying ...
2
votes
2answers
224 views

Solidity (*.sol) filetype not recognised in neovim

NeoVim is not recognising Solidity filetypes (which end with the extension .sol). When editing a .sol file typing: :set filetype? generates a filetype= (e.g. blank). This is in contrast to html, ...
2
votes
1answer
1k views

How can I prevent the default loading of ftplugin/text.vim for certain *.txt files

I have to edit a bunch of *.txt files for which I want to define a specific filetype. So, in my vimrc, I add a autocmd! BufReadPost bunchOfFiles/*.txt :set ft=bunchOfFilesFT This reads ftplugin/...
2
votes
2answers
44 views

How to re-indent nginx configuration based only on `{` and `}`?

I want to reindent an nginx configuration file with the following simple rudimentary rules: a { increases indentation a } decreases indentation The idea is cindent is just enough to do it. I have ...
2
votes
1answer
37 views

Is there a filetype in Vim when opening the a file containing output/errors from g++ so that I can see those files with the original coloring?

Sometimes, when faulty outputs from compilations of C++ files/projects are to long, I like to redirect that output to a file, so that I can inspect it side-by-side with each of the offending files in ...
2
votes
1answer
154 views

How do I test ftplugin scripts efficiently

Say I am writing a plugin and constantly editing scripts in ftplugin. How do I efficiently test the changes? I can't simply source the editted file because they are filetype-specific. For example, if ...
2
votes
1answer
40 views

How to set the background color for colored items in the statusline to the background color of the statusline?

I am experimenting with creating a statusline and have opted for coloring different parts of it. The problem is that while the item's foreground color is changed, the background is black and doensn't ...
2
votes
1answer
32 views

Position Dependent Custom Syntax Error Checking

I am trying to design a custom syntax file that performs some basic error checking for an ascii input file. The input is broken up into sections, and there are input cards specific to each section. ...
2
votes
0answers
54 views

Minimum window width will not change when using specific filetype

With most filetypes, I can resize font and my GVIM application window just fine. However, when I open a specific file type (.tex), the font is easily changed, but I am unable to shrink the application ...
2
votes
0answers
15 views

What pattern could I use to set a filetype for files ending in '.ot.txt' [duplicate]

I'd like to use VimOutliner with files ending in .ol.txt. This entry in ~/.vim/ftdetect/votl.vim doesn't do that au! BufRead,BufNewFile *.ol.txt setfiletype votl Is there a [pattern] for this?
2
votes
0answers
448 views

How to fix this `Omni completion (^O^N^P) Pattern not found` error?

I am trying to set up syntax keyword based omnicompletion in vim. I have defined a few syntax keyword Constants in ~/.config/nvim/syntax/spl.vim They are correctly detected and highlighted. They are ...
2
votes
0answers
551 views

Vim not recognizing markdown and tex files

Here is a sample of my .vimrc, that doesn't do a thing (the autocmd does not work) when I open a .md or .tex file, but works fine for .py files: augroup filetype_python autocmd FileType python ...
2
votes
0answers
385 views

in-line math equation rendering/preview for macvim/vim for filetypes other than RMarkdown

I recently installed vim-rmarkdown package, and found that the package allows me to see the rendered math equation in macvim, and when move cursor over, the line will render back to latex equation ...
1
vote
2answers
196 views

Linking a filetype to a syntax file of a different name

I’ve created a new filetype, “usenet,” for Usenet messages. I would like files with this filetype to be highlighted exactly as if they had the “mail” filetype. Is it possible to tell Vim that I want ...
1
vote
2answers
171 views

Tab completion for filetypes in the commandline

If I want to set the filetype manually in vim, I would like to tab complete filetypes vim recognizes. However, right now vim just inserts a literal ^I :set ft=markd^I Is this possible?
1
vote
1answer
299 views

Is it possible to have vim run a command every time save `:w` is invoked?

I am editting typescript now, and I'd like to be able to have it so, whenever :w is invoked, the shell runs tsc compiling my new save. This beats having to !tsc every time. Does something like this ...
1
vote
1answer
395 views

How do I use regular expressions in ternary statements / keymappings?

I'd like to create a keymapping with a conditional statement, so that it behaves differently when a given line is blank. This thread gave me the following snippet, which is great – except that it ...
1
vote
1answer
43 views

Combine FileType with other events

I'd like to combine two events: FileType and TextChangedI. According to this awesome book I can do that, by adding a comma between both events like this: :autocmd BufWritePre,BufRead *.html :normal gg=...
1
vote
1answer
105 views

How can I make vim ignore a filetype plugin's makeprg setting?

I am using a plugin that sets makeprg to some value specific to the filetype's programming language. I want to use my global setting instead, because I also use Makefiles. How can I do this? Thank you!...
1
vote
2answers
29 views

Assign a filetype when editing any file from a directory

The context I store all my shell scripts insde the $HOME/.bin directory. Because of this, I've been looking for a way to set the sh filetype whenever I open a file located in that directory. So, I'...
1
vote
1answer
170 views

How to disable intelligent indent for text/markdown files?

Since ever in my configuration of vim text and markdown-files are indented on following lines to align with open parenthesis. Text Text Text (e.g. Hello World) More Text This happens ...
1
vote
3answers
1k views

How to remove every second column in Vim?

I have a CSV file where I want to remove every second column. Each column value are separated by quotes and the column values can contain field separators: this means that convenient solutions such as ...
1
vote
2answers
328 views

Set folding method for c and cpp files, but not h and hpp

I am in the process of customizing my vim setup, and since I write a lot in C, I have a whole function dedicated just for those files, which I call with autocmd filetype c,cpp,h,hpp call C_syntax(). ...
1
vote
2answers
912 views

Setting foldmethod=expr when re-sourcing vimrc?

I have the following on my vimrc file to handle custom folding: " ++ Folding set foldenable " enable folding ...