When editing HTML files I have
indentexpr=HtmlIndent()
Last set from /usr/share/vim/vim74/indent/html.vim
I want to disable it. setlocal indentexpr= in ~/.vim/after/ftplugin/html.vim don't work. What more can I do?
Vim 7.4.
Related
I install vim-markdown,but this plugin detect markdown file as mkd(by ftdetect/mkd.vim), while vim detect it as markdown.
Also some my plugin and config depends markdonw.
So how to use it harmonious, without change vim-markdown, and vim filetype.vim?
You can add the following to your .vimrc
autocmd BufRead,BufNewFile *.md,*.markdown setlocal filetype=markdown " Automatically set filetype for Markdown files"
also, if you use markdown a lot, I could give a try to pandoc markdown and use vim-pandoc plugin
To do this without changing the plugin itself and without file system-level tricks like links, you can create redirection scripts for the ftplugin/, indent/ etc. For example, ~/.vim/ftplugin/markdown.vim with the following contents:
runtime! ftplugin/mkd.vim
But of course, the best solution would be the mentioned change in the plugin itself.
For some reason I don't have syntax color highlighting for certain configuration files.
Namely, for /etc/nginx/nginx.conf
At the same time, nginx configuration files in /etc/nginx/sites-available/ directory do have color highlighting.
Any ideas?
Thanks.
P.S. It worked after some changes in .vimrc:
filetype on
au BufNewFile,BufRead *.conf set filetype=conf
Thanks for everyone's help!
For that file that's properly highlighted,
:verbose setlocal filetype?
will tell you the filetype, and also from where it is set. Apparently, that filetype detection rules doesn't cover the other file pattern / location. You can easily add that, though, so that in the future, these files will be properly detected, too. :help new-filetype has all the information.
I use vim to write my Mercurial commit messages and I would like it to automatically wrap my text when it hits a specific limit, say 80 characters. My git setup already does this, but I'm not sure how to make hg behave in the same way.
How do you set the textwidth used in vim when writing hg commit messages?
You can define the command to run when you do a commit by setting the editor option inside the [ui] section of your .hgrc config file. To set the textwidth in vim you could do:
[ui]
...
editor = vim -c ":set textwidth=80"
Vim should already recognize hg commit messages. To set specific options for that filetype, create a file $HOME/.vim/after/ftplugin/hgcommit.vim (create non-existing directories) and set your option there:
setlocal textwidth=80
Then Vim should pick up your new settings, provided that your .vimrc enables filetype plugins by e.g. filetype plugin on or similar.
See also the faq Question 26.3 and Question 26.6
I like to enable spell check and set my text width to 72 for hg commit messages.
Modify your .vimrc file to include a line like the following:
autocmd BufNewFile,BufRead hg-editor-*.txt setlocal spell textwidth=72
This works with pre-7.4 versions of Vim (I'm currently on 7.2).
Most modern Vim installations will know about the hgcommit filetype. In that case, you can simply add the following to your .vimrc file:
autocmd Filetype hgcommit setlocal textwidth=72
Note
This solution supports other Vim settings as well. For example, I use the following line, which also turns on spellchecking:
autocmd Filetype hgcommit setlocal spell textwidth=72
I want to change the filetype based on file extension in vim.
I have the following code in the my .vimrc
autocmd BufNew,BufNewFile,BufRead *.txt,*.text,*.md,*.markdown setlocal ft=markdown
But when I open a file with the extention .md file, the filetype is not changed. I run :set ft command and it shows the output as filetype=modula2.
Am I doing anything wrong?
Edit:
I started to debug by renaming my old .vimrc file and created a new one with just this line. It was working properly. Then I replaced my old .vimrc file and everything seems to be working fine. Guess it was because of some issues in some addon which I am using.
But accepting ZyX's answer, since it thought me an alternate way to do this.
I created a ~/vim/ftdetect/markdown.vim file with this line
autocmd BufNewFile,BufRead *.md,*.mkdn,*.markdown :set filetype=markdown
Reading the docs for filetype, setfiletype only sets if filetype is unset. So you need to use set for an unconditional change to a filetype.
Wondering whether this line goes before or after filetype … on. In the former case you should try putting it (your autocommand) after this line. Better if you put it into ~/.vim/ftdetect/markdown.vim and use setfiletype markdown instead of setlocal ft=markdown:
augroup filetypedetect
autocmd BufNew,BufNewFile,BufRead *.txt,*.text,*.md,*.markdown :setfiletype markdown
augroup END
: it is the default way of doing such things. ~/.vim must go before /usr/share/vim/* paths in 'runtimepath' option in this case (it does by default).
I was able to get syntax highlighting for alternate file extensions by creating renamed copies of the target syntax file in the Vim\vim74\syntax directory.
To make *.md open as a .markdown:
copy markdown.vim md.vim
or paste a copy of markdown.vim to the syntax folder, then rename the copy md.vim.
(Running vim74 on win7)
I'm working on a PHP project where all files are given the extension '.shtml'. Unfortunately Vim doesn't know to highlight PHP in these files. Is there as way to force Vim to highlight these files as PHP instead of shtml?
You can add this to your .vimrc
au BufNewFile,BufRead *.shtml set filetype=php
also... the quick-fix when you're already in vim:
:set filetype=php
You can also add something like
<?php /* vim:set ft=php: */
in the beginning of your file. That would make it more or less independent of the local vim settings.