DelimitMate collides with vim-closetag and adds an extra > when closing tags.
I fixed the above issue for .erb files with the fix mentioned here:
https://github.com/alvan/vim-closetag/issues/40
au FileType html let b:delimitMate_matchpairs = "(:),[:],{:}"
But the same fix did not work for a .ejs files, hence when adding the .ejs filetype to the config nothing happens.
If one looks at the file type in the nvim source code there is nothing for .ejs
https://github.com/neovim/neovim/blob/master/runtime/filetype.vim
I solved my issue by changing the .ejs file type to an html filetype my nvim config like this:
autocmd BufNewFile,BufRead *.ejs set filetype=html
Now that my .ejs filetype is recognised as html filetype the same fix will work for my .ejs files.
My vim-closetag plugin config looks like this:
" These are the file extensions where this plugin is enabled.
let g:closetag_filenames = "*.xml,*.html,*.xhtml,*.phtml,*.php,*.erb"
" delimitMate colides with vim-closetag bug fix
au FileType eruby,xml,html,phtml,php,xhtml,js let b:delimitMate_matchpairs = "(:),[:],{:}"
" These are the file types where this plugin is enabled.
let g:closetag_filetypes = 'html,xhtml,phtml,eruby'
This is how one can resolve the issue for all file types including .erb,.ejs and unrecognised file types.
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.
While editing a Sass file, I'd like to be able to use Vim's Omnicompletion (<C-x><C-o>) to complete Sass variables that are present in the project's ctags file.
It seems that my ~/.ctags file is configured correctly, because when I type something like :tag primary, it takes me to the Sass file in which I've defined the variable $primary. But typing color: $prim, followed by <C-x><C-o>, gives me the message "Pattern not found."
To try to make this work, I've added the following lines to my ~/.vimrc:
au FileType scss set omnifunc=csscomplete#CompleteCSS
set tags=tags;
What else do I need to do for Vim to recognize this as the beginning of a Sass variable?
The default CSS omni-completion function, called when you do <C-x><C-o>, doesn't use tags at all.
Try <C-x><C-]> to use your tags file exclusively or <C-n> to complete from a variety of sources, including your tags file.
(Would you mind sharing your ~/.ctags, please?)
When I open a *.tex file with Vim, filetypes is read as plaintex (returned by set ft?) by YCM.
So I added in .vimrc :
let g:ycm_filetype_blacklist = {'plaintex' : 1}
But nothing had changed.
Here I want that filetype .tex is read as tex type (set ft=tex).
How to define it with YCM options?
After research (from vim-latex plugin) I found that I have to add following:
" OPTIONAL: Starting with Vim 7, the filetype of empty .tex files defaults to
" 'plaintex' instead of 'tex', which results in vim-latex not being loaded.
" The following changes the default filetype back to 'tex':
let g:tex_flavor='latex'
Does YCM set the 'filetype' option? If you want it set to tex, then check where it was set:
:verbose set ft?
I bet it is set in $VIMRUNTIME/filetype.vim, in which case it is my fault. Luckily, I made it configurable. According to :help ft-tex-plugin,
If the first line of a *.tex file has the form
%&<format>
then this determined the file type: plaintex (for plain TeX), context (for
ConTeXt), or tex (for LaTeX). Otherwise, the file is searched for keywords to
choose context or tex. If no keywords are found, it defaults to plaintex.
You can change the default by defining the variable g:tex_flavor to the format
(not the file type) you use most. Use one of these:
let g:tex_flavor = "plain"
let g:tex_flavor = "context"
let g:tex_flavor = "latex"
Currently no other formats are recognized.
I think that
:let g:tex_flavor = 'latex'
in your vimrc file will make you happy.
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)
In Vim, I want to use a different colorscheme for each file type.
e.g. I want to use desert256 colorscheme for Python & JavaScript files, and use jellybeans colorscheme for HTML & CSS files.
I've tried putting the following code in my .vimrc, but the colorscheme change happens only when changing buffers for the first time.
i.e. If I open a new Python file, Python's colorscheme is used, and when I open a new CSS *buffer*, indeed the colorscheme changes to CSS's colorscheme. However, Changing back to Python's buffer does not change the colorscheme back.
I've used autocmd WinEnter to try and make this rule happen when changing windows (and buffers), but it doesn't help:
autocmd WinEnter,FileType python,javascript colorscheme desert256
autocmd WinEnter,FileType *,html,css colorscheme jellybeans " This includes default filetype colorscheme.
How can I fix this? In addition, a bonus would be to not change a colorscheme when not needed - i.e. Changing from a Python to a JavaScript buffer won't change the colorscheme to "itself".
EDIT:
If anyone's interested, here is my .vimrc repo in github.com. I'll update it with the solution I find here once given.
I've been looking for the same thing. This inside your .vimrc works reasonably well although not perfect.
autocmd BufEnter * colorscheme default
autocmd BufEnter *.php colorscheme Tomorrow-Night
autocmd BufEnter *.py colorscheme Tomorrow
(Note if you're looking for a good dark color theme Tomorrow-Night looks pretty good. Very similar to theme used on Code Academy.)
What you want are filetype plugins, rather than the autocmds. Run help: ftplugin in vim for more info.
From the vim help page:
A filetype plugin is like a global plugin, except that it sets options and
defines mappings for the current buffer only.
In order to use filetype plugins, first put the line filetype plugin on in your vimrc. Then create the folder ftplugin in your vim folder (on unix it's ~/.vim/, I'm not familiar with windows). Then create a script file for each file type you want to customize. These files must be named a specific way. From the vim help page:
The generic names for the filetype plugins are:
ftplugin/filetype.vim
ftplugin/filetype_name.vim
ftplugin/filetype/name.vim
So, for example, if I wanted to create a script for a python file, I would have three options:
Create a file named python.vim in ftplugin
Create a file named python_whatever.vim in ftplugin
Create a file named whatever.vim in ftplugin/python
This script will then be loaded anytime I open a file that vim recognizes as a python file.
So, in order to accomplish what you want:
Create a file named filetype.vim in the ftplugin directory for every filetype you want.
In each of these files, add the line colorscheme name_of_colorscheme
Add filetype plugin on to your vimrc.
In order to set a default colorscheme, just set it in your vimrc file. If I remember correctly, filetype plugins are loaded after your vimrc.
Edit:
The OP indicated that he had a good reason to avoid using the ftplugin directory. After a bit more diggin, I found this script. It can be placed in the global vimrc and seems intended to solve the same problem as the OP.
I have a hack you may like. It is far from perfect, and it doesn't use a .vimrc, but it works for me. It requires you to type a different command to edit different files. It works using the -c parameter when you call gvim. This argument allows you to run vim commands after loading the file. Add this to your ~/.bashrc ( I guess you are using bash ) :
alias gpy="gvim -c 'colorscheme desert'"
alias gcs="gvim -c 'colorscheme jellybeans'"
Hope this helps
Use BufWinEnter instead of WinEnter, like this:
autocmd BufWinEnter,FileType javascript colorscheme jellybeans