Vim loading multiple syntax files instead of just one - vim

I have put new javascript syntax and indent files in my 'bundle' directory (I use Pathogen). I noticed that VIM loads both my new files as well as the standard files, in particular it loads the standard files after and I fear it may be overwriting the custom ones.
The VIM docs says it should not load the standard files if it found custom one first so I am not sure why this is happening.
This is what I see with the :scriptnames command, you can see the standard files (line 32, 35) after the customer ones (line 31, 34)
31: /usr/share/vim/vimfiles/bundle/vim-javascript/syntax/javascript.vim
32: /usr/share/vim/vim73/syntax/javascript.vim
33: /usr/share/vim/vim73/ftplugin/javascript.vim
34: /usr/share/vim/vimfiles/bundle/vim-javascript/indent/javascript.vim
35: /usr/share/vim/vim73/indent/javascript.vim

It's fine that both the system-default and your custom syntax files appear in the :scriptnames output. Vim will source all files found in 'runtimepath', but the canonical include guard
if exists("b:current_syntax")
will cause all scripts running after the first to abort immediately after the check.

Related

How do I remove duplicates from vim :scriptnames file?

I'm trying to learn vim. When I open the program I'm met with this:
The airline statusline funcref function('airline#extensions#mundo#statusline') has already been added.The airline statusline funcref function('airline#extensions#mundo#statusline') has already been added.
The owner said:
that error message suggests that you have airline installed twice...
did you install airline globally as well as via vundle or something?
what does :scriptnames tell you? thanks.
Which was the case for the OP and what looks to be for me too. I ran :scriptnames and got the following references to airline:
56: ~/.vim/bundle/vim-airline/plugin/airline.vim
57: ~/.vim/bundle/vim-airline/autoload/airline.vim
58: ~/.vim/bundle/vim-airline/autoload/airline/init.vim
59: ~/.vim/bundle/vim-airline/autoload/airline/parts.vim
60: ~/.vim/bundle/vim-airline-themes/plugin/airline-themes.vim
78: ~/.vim/bundle/vim-airline/autoload/airline/extensions.vim
79: ~/.vim/bundle/vim-airline/autoload/airline/extensions/quickfix.vim
80: ~/.vim/bundle/vim-airline/autoload/airline/extensions/netrw.vim
81: ~/.vim/bundle/vim-airline/autoload/airline/extensions/ctrlp.vim
82: ~/.vim/bundle/vim-airline/autoload/airline/extensions/commandt.vim
83: ~/.vim/bundle/vim-airline/autoload/airline/extensions/branch.vim
84: ~/.vim/bundle/vim-airline/autoload/airline/extensions/syntastic.vim
85: ~/.vim/bundle/vim-airline/autoload/airline/extensions/whitespace.vim
86: ~/.vim/bundle/vim-airline/autoload/airline/extensions/wordcount.vim
87: ~/.vim/bundle/vim-airline/autoload/airline/extensions/tmuxline.vim
88: ~/.vim/bundle/vim-mundo/autoload/airline/extensions/mundo.vim
89: ~/.vim/bundle/vim-airline/autoload/airline/section.vim
90: ~/.vim/bundle/vim-airline/autoload/airline/highlighter.vim
91: ~/.vim/bundle/vim-airline/autoload/airline/themes/dark.vim
92: ~/.vim/bundle/vim-airline/autoload/airline/themes.vim
93: ~/.vim/bundle/vim-airline/autoload/airline/util.vim
99: ~/.vim/bundle/vim-airline/autoload/airline/builder.vim
100: ~/.vim/bundle/vim-airline/autoload/airline/extensions/default.vim
What I don't know (and what I think I need help with) is the location of the file :scriptnames references and how to remove duplicates.
Thanks for your thoughts.
Most Vim plugins consist of several script files. It is therefore normal to see multiple references in :scriptnames. In your output, the base Airline directory is ~/.vim/bundle/vim-airline; all of these base directories have a common substructure under them (usually autoload/... and plugin/...).
What the owner meant was to check for multiple base directories, e.g. both ~/.vim/bundle/vim-airline and ~/.vim/bundle/vim-another-airline. Based on your output, that doesn't seem to be the case. Also, the error is about the Mundo extension for Airline, not Airline itself. Shouldn't you then look for multiple installations of Mundo?!
If you have two same plugins installed, you need to uninstall vim-airline. You will be having two lines of Plugin vim-airlines or something similar in vimrc. The exact names for plugins might be different. Delete any duplicate lines and run
:PluginUpdate
:PluginClean
Hope this helps

Why does vim "cancel out" the last two characters when running `%:8` in an external command?

A simple work flow I often use when running an rspec test I have just been working on, in vim, is as follows:
15: it "my example test" do
16: expect(1 == 1).to be true
17: end
And to run this test, you can do:
!rspec %:15
This runs rspec as an external command. % expands to the current filename, and :15 tells rspec to only run the test line 15, rather than all tests in the file.
This technique works fine under normal circumstances. However, if you try to run a test on lines 80-89 then something strange happens:
84: it "my other test" do
85: expect(4 > 3).to be false
86: end
!rspec %:84
This runs the command rspec [filename]4 - i.e. the :8 characters disappear! (And you get a "file not found" error.)
A workaround to avoid this problem is to press TAB after entering %, which immediately expands % to the full path name.
However, what's the reason behind this strange vim behaviour? Is it a bug, or a feature?
A different, related question led me to finding the answer to this.
You can find the answer, along with more detail, by running :help filename-modifiers in vim. Here is a summary of the key point:
The file name modifiers can be used after "%", "#", "#n", "<cfile>", "<sfile>", "<afile>" or "<abuf>".
:8 Converts the path to 8.3 short format (currently only on MS-Windows). Will act on as much of a path that is an existing path.
8 is the only numerical filename-modifier. If you wish to disable this feature entirely, you can compile vim without the +modify_fname feature.

Override syntax highlighting in vim file

I am trying to override a markdown file syntax by placing the following file md.vim in my after/syntax directory. md.vim contains the following code:
syntax region mdNote start=/\<\cNOTE\>/ end=/\r/
highlight def link mdNote Todo
I have tested that the code works by sourcing it directly but when I launch a file with an extension .md, the mdNote syntax does not work. For example, given the following markdown file:
# Main Heading
Note: This is a note
If I put the cursor inside the word Note and get the syntax group, I get:
mkdNonListingItemBlock which comes from the plasticboy/markdown plugin that I have installed.
Does anyone know why my syntax file is not working?
Markdown files will reference the markdown.vim file in after/syntax. To get this information for any file, you can open a file of the desired format and run :set syntax?. Rename your file to markdown.vim and it should work.

Vim tries to jump to nonexistent file after :make

I'm using :make from vim and ending up jumping to the file with issues.
Recently, at least I noticed with gcc 4.6.1, vim jumps to incorrect file/line because it goes to the first reported line which has "In file included from ABC.h|5| 0," and there is no file called "In file included from ABC.h".
There is a solution to extract just the file name from the above line, ABC.h in this case, but that does not solve the problem as the problematic file is only included there.
Usually the next line indicates where the issue is and that's where I would like to jump:
MyDir/FGH.h|56 col 32| error: 'bad bad thing happened here'
Is there a known fix for this in vim?
This a bug that is solved on new versions of Vim: Bug report logs - #62169.
You can use the following setting to solve the problem without upgrading Vim:
set errorformat^=%-GIn\ file\ included\ from\ %f:%l:%c:,%-GIn\ file
\\ included\ from\ %f:%l:%c\\,,%-GIn\ file\ included\ from\ %f
\:%l:%c,%-GIn\ file\ included\ from\ %f:%l
(setting extracted from latest Vim source code, from file src/option.h)
:make! doesn't jump to the first result.
The problem is with slight differences in the errorformat required for recent versions of gcc.
I believe this was mentioned in C++ Lounge (chat) the other day, and an errorformat was posted that supposedly works better. I haven't tested that it does:
https://chat.stackoverflow.com/search?q=errorformat&room=10
errorformat=%*[^"]"%f"%*\D%l: %m,"%f"%*\D%l: %m,%-G%f:%l: (Each undeclared identifier is reported only once,%-G%f:%l: for each function it appears in.),%-GInfile included from %f:%l:%c:,%-GIn file included from %f:%l:%c\,,%-GIn file included from %f:%l:%c,%-GIn file included from %f:%l,%-G%*[ ]from %f:%l:%c,%-G%*[ ]from %f:%l:,%-G%*[ ]from %f:%l\,,%-G%*[ ]from %f:%l,%f:%l:%c:%m,%f(%l):%m,%f:%l:%m,"%f"\, line %l%*\D%c%*[^ ] %m,%D%*\a[%*\d]: Entering directory `%f',%X%*\a[%*\d]: Leaving directory `%f',%D%*\a: Entering directory `%f',%X%*\a: Leaving directory `%f',%DMaking %*\a in %f,%f|%l| %m

Removing a character from 'iskeyword' in vim

In my vimrc, I have included a script (say, otherscript.vim, which I need to include for work reasons) that says:
autocmd FileType php setlocal iskeyword+=$
and I don't want this behaviour. So, sometime later in the vimrc, I say:
autocmd FileType php setlocal iskeyword-=$
(I also tried using set instead of setlocal.) But, when I open a php file, iskeyword still contains the $ symbol in it. I am using vim 7.2. The output of ':verbose set iskeyword' is
iskeyword=#,48-57,_,192-255,$
Last set from /path/to/otherscript.vim
The output of ':scriptnames' is:
...
7: /usr/share/vim/vim72/ftplugin.vim
8: /home/yogeshwer/.vimrc
...
74: /path/to/otherscript.vim
...
Can somebody help me how I can revert the changes to 'iskeyword' made by the other script? Thanks a bunch.
I like to avoid autocmds when I can and use the after directory structure.
$ mkdir -p ~/.vim/after/{ftplugin,syntax,indent}
$ echo 'setlocal iskeyword-=$' >> ~/.vim/after/ftplugin/php.vim
This sets up a basic after directory in your user-specific vim config folder. Whereas ~/.vim/ftplugin/$FILETYPE.vim would be used in lieu of vim's standard $FILETYPE.vim file, files in an after directory get executed after, allowing you to override or change the behavior of your ftplugins, syntax definitions, and indent commands.
As an additional example to show you how these work, I'll include part of my local after/syntax/python.vim file here. I like all the "structural punctuation" of my code to stand out when I read it, so I do this:
syn match pythonParen /[()]/
syn match pythonBrack /[][]/
syn match pythonCurly /[{}]/
hi def link pythonParen Paren
hi def link pythonBrack Brack
hi def link pythonCurly Curly
I've also got an after/indent/php.vim file that was supposed to fix some of the annoying indent issues I ran into with the indent behavior when switching in and out of <?php ?> regions in a template file, but the code is a mess and never really worked in the first place, so I won't reproduce it here. I mention it only to give you an example of what can be done with the after hooks.

Resources