vim can't open syntax.vim - vim

In my .vimrc I have the following snippet:
if has('autocmd')
filetype plugin indent on
syntax on
but when I start vim it shows the following error:
Can't open file /usr/share/vim/syntax/syntax.vim
error seems to have occurred on syntax on line in .vimrc.
I do not have syntax.vim in path /usr/share/vim/syntax though I have others like clojure.vim cpp.vim java.vim etc...
I searched but can't seem to find the default syntax.vim if it comes with default version of vim.
I've been stuck with this for a while and would like some help.

I use Arch and build vim from the AUR using the vim-git PKGBUILD. For me, it was the case of using vim-git, but vim-runtime from the official repos, not vim-runtime-git from the AUR.
Switching to vim-runtime-git solved this issue for me and provided the syntax file (and colours, and...).

It should be there so there may be other files missing. I would suggest you re-install!.
For a QDF here is what the
syntax.vim file should look like this:-
" Vim syntax support file
" Maintainer: Bram Moolenaar <Bram#vim.org>
" Last Change: 2001 Sep 04
" This file is used for ":syntax on".
" It installs the autocommands and starts highlighting for all buffers.
if !has("syntax")
finish
endif
" If Syntax highlighting appears to be on already, turn it off first, so that
" any leftovers are cleared.
if exists("syntax_on") || exists("syntax_manual")
so <sfile>:p:h/nosyntax.vim
endif
" Load the Syntax autocommands and set the default methods for highlighting.
runtime syntax/synload.vim
" Load the FileType autocommands if not done yet.
if exists("did_load_filetypes")
let s:did_ft = 1
else
filetype on
let s:did_ft = 0
endif
" Set up the connection between FileType and Syntax autocommands.
" This makes the syntax automatically set when the file type is detected.
augroup syntaxset
au! FileType * exe "set syntax=" . expand("<amatch>")
augroup END
" Execute the syntax autocommands for the each buffer.
" If the filetype wasn't detected yet, do that now.
" Always do the syntaxset autocommands, for buffers where the 'filetype'
" already was set manually (e.g., help buffers).
doautoall syntaxset FileType
if !s:did_ft
doautoall filetypedetect BufRead
endif

I had this problem as well after upgrading to 7.3 (I'm using cygwin). Check whether running "vi" instead of "vim" has the same problem. I found that vim was actually the old 7.2 executable, but the syntax files were in the location expected by 7.3; vi was the correct 7.3 executable.

I have been using compiled vim from source without explicitly installing it on my system (due to missing sudo privileges).
I was able to solve the issue by adding the following line to my .bashrc:
export VIMRUNTIME=<path to cloned vim repo>/runtime
Thus: Pointing this env variable to the runtime director in the git tree, makes vim find the needed file(s).

Related

Easy way to get syntax highlighting for Julia in Vim

I am trying to get Julia to have syntax highlighting in Vim. Unfortunately, at the moment, I there is no syntax highlighting (here is a small snippet of my code so you can see what it currently looks like). I tried installing julia-vim and putting it in the .vimrc file and installing it, but it doesn't actually change the highlighting. Below is the .vimrc file:
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
" The following are examples of different formats supported.
" Keep Plugin commands between vundle#begin/end.
" plugin on GitHub repo
Plugin 'tpope/vim-fugitive'
" plugin from http://vim-scripts.org/vim/scripts.html
" Plugin 'L9'
" Git plugin not hosted on GitHub
Plugin 'git://git.wincent.com/command-t.git'
" git repos on your local machine (i.e. when working on your own
plugin)
Plugin 'file:///home/gmarik/path/to/plugin'
" The sparkup vim script is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
" Install L9 and avoid a Naming conflict if you've already installed a
" different version somewhere else.
" Plugin 'ascenator/L9', {'name': 'newL9'}
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList - lists configured plugins
" :PluginInstall - installs plugins; append `!` to update or
just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean - confirms removal of unused plugins; append
`!` to auto-approve removal
"
Plugin 'JuliaEditorSupport/julia-vim'
"
"
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line
I'm also note sure how to fix it after reading the julia-vim documentation. Am I doing anything incorrectly, or is there another way to add some syntax highlighting to Julia?
I have seen from one of the answers to this question asked by #Thomas that it might be how I have set up my terminal, but I'd prefer to keep the terminal with the present color scheme if possible. See here for my current settings.
EDIT: Thanks to #axwr, I was able to get some syntax highlighting by putting
syntax on
at the end of the .vimrc file and then running
:so %
while editing the .vimrc file. However, as you can see here, the color coding seems to be less than ideal. Only certain packages come up as yellow, the majority is still green, and random things (usually numbers) come up as purple. Is this how julia-vim colors things, or am I doing something wrong?
Okay, so.
There are two steps to syntax highlighting in Vim; actually turning it on, and, having the ability to highlight the specific language you want to work in. For most languages vim can do this by default, however some languages, like Julia, require a little help. In this case you have done step two by using vundle to install a Julia plugin.
To acheive step one, you just need the line: syntax on in your vimrc file.
A minimal example vimrc for you, might look like:
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'JuliaEditorSupport/julia-vim'
call vundle#end()
set nocompatible
set backspace=indent,eol,start
set number
set hidden
syntax on
filetype plugin indent on
Given the above settings, and a terminal that has the "solarised" colorscheme, a julia file looks like:
Here is the little fizzbuzz julia snippet so you can compare against your highlighting:
for i in 1:100
if i % 15 == 0
println("FizzBuzz")
elseif i % 3 == 0
println("Fizz")
elseif i % 5 == 0
println("Buzz")
else
println(i)
end
end
So, Step by step:
Add syntax on to your .vimrc
Add filetype plugin indent on to your .vimrc
Install the relevant plugin
Source your .vimrc or close vim.
open a file with the correct extension, i.e: test.jl

Vim auto-source vimrc on save with symlink

I have a symlink which points my .vimrc to the one from my repo.
Vim loads that just fine, but I can't get it to auto-source upon it being changed.
I have the typical:
if has("autocmd")
autocmd! BufWritePost .vimrc source $MYVIMRC
endif
Which works if the vimrc is not symlinked.
I have a similar setup where ~/.vimrc is just a symlink to a git repository. The following autocommand works for me:
autocmd! bufwritepost .vimrc source %
I don't like symlinks in general and Vim doesn't really like them either.
The layout I use is probably similar to yours:
~/.vimrc
~/.vim/vimrc
with a big difference: ~/.vimrc is a real file, not a symlink, and it contains only one line:
runtime vimrc
that executes my real ~/.vim/vimrc. Because it is a Vim command and it doesn't use a file path, that line can be the same on every system.
Because $MYVIMRC points to a real file, :so $MYVIMRC always works.
I solved that problem that way that all my configuration I am keeping in dotfiles folder
https://github.com/lis2/dotfiles
Then I have small and simple ruby script which I running when I am changing something in configuration
#!/usr/bin/env ruby
require "fileutils"
config_hash = { "tmux.conf" => ".tmux.conf", "vimrc" => ".vimrc", "vim" => ".vim", "gitconfig" => ".gitconfig", "gitignore" => ".gitignore"}
config_hash.each do |k,v|
FileUtils.rm_rf(File.dirname(__FILE__) + "/../#{v}")
FileUtils.ln_s(File.dirname(__FILE__) + "/#{k}", File.dirname(__FILE__) + "/../#{v}")
end
I recommend you to built same configuration. On all computers (private/work) I just clone my repo, run symlink.rb and my simple environment is ready for work.
cheers!
I have both .vimrc and .gvimrc symlinked to a git repo like you are describing. I'm running MacVim macOS.
I found a great answer to the question progressively-slower-reloading-time-of-vimrc.
I modified it a bit to reload both vimrc and gvimrc when any of them changes. I have been using it for months now without issues.
Here it is. You need just this and just in .vimrc. You don't have to add anything to .gvimrc.
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Autoreload vimrc
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
augroup configsGroup
autocmd!
" Make changes effective after saving .vimrc. Beware that autocommands are
" duplicated if .vimrc gets sourced again, unless they are wrapped in an
" augroup and the autocommands are cleared first using 'autocmd!'
autocmd! bufwritepost *\<vimrc\> call OnSavingConfigs()
autocmd! bufwritepost *\<gvimrc\> call OnSavingConfigs()
augroup END
" Avoid infinite loops
if !exists("*OnSavingConfigs")
function! OnSavingConfigs()
" Clear previous mappings, they don't go away automatically when
" sourcing vimrc.
mapclear
source $MYGVIMRC
source $MYVIMRC
redraw
echo "Reloaded " . $MYVIMRC . " and " . $MYGVIMRC . "."
endfunction
endif

Install Paredit vim plugin on Mac OSX

I recently download the paredit plugin for vim on my mac osx. I placed the paredit.vim in my ~/.vim directory.
The docs says:
When you enter a '(' then a matching ')' is automatically inserted.
If needed, spaces before and/or after the '()' pair are added.
...
Paredit mode is set by default for .lisp, .cl, .clj, cljs, .scm and .rkt files,
but it is possible to switch it off by putting the following statement in the
.vimrc file:
However when I open vim and enter a "(" no closing ")" is inserted. Is there something else extra I need to do?
This did it for .clj files
syntax on
au BufNewFile,BufRead *.clj setfiletype clojure
au BufNewFile,BufRead *.clj call PareditInitBuffer()

snipMate only working on empty buffer?

I'm attempting to use snipMate with sql files, however it doesn't seem to work when editing an existing file.
If I create a new empty buffer (no file; e.g. launch gvim from the start menu), and set the filetype to sql (:set ft=sql), it works. However, if I then try to open a sql file (e.g. :e c:\blah.sql) and edit it, snipMate no longer works. What gives!?
Setup:
gvim
vim 7.3
Windows 7
snipMate 0.84
Also, I do in fact have filetype plugin on in my .vimrc file.
edit
Apparently if I open an empty buffer, set the filetype to sql, then save to file using w c:\blah.sql, I now have a sql file open AND snipMate continues to work.
edit
Here's a gist of my current .vimrc in case it helps: https://gist.github.com/3946877
I have tried your .vimrc on my computer and it works fine. There's a filetype.vim file in $VIMRUNTIME which detects filetypes on startup and most likely you have some problem within that file. These are the relevant lines from mine:
" SQL
au BufNewFile,BufRead *.sql call s:SQL()
func! s:SQL()
if exists("g:filetype_sql")
exe "setf " . g:filetype_sql
else
setf sql
endif
endfunc
You can copy these to $VIMRUNTIME/filetype.vim or just to your .vimrc and that should solve the problem but then again you shouldn't have this problem in the first place.
Let me know how you progress..
NOTE $VIMRUNTIME is /usr/share/vim/vim73 in my machine, you can find yours by running :echo $VIMRUNTIME in a vim session
It looks like vim doesn't recognize the sql filetype from the extension. Try putting this into your .vimrc:
augroup filetypedetect
au! BufRead,Bufnewfile *.sql setfiletype sql
augroup END
Uggggh, I'm an idiot!
I decided to remove all plugins except snipMate, and then I slowly added my plugins back in. I didn't realize it when I was hooking up snipMate, but I had already added a plugin previously for doing code completion called code complete. Apparently this nerd and snipMate were at war, so once I removed code complete snipMate miraculously began to work!
Hopefully this might help someone in the future.

MacVim: slimv does not start

I'm using MacVim (kind of gvim for OSX) and try to get the slimv plugin running.
Sadly it's not working out of the box. In fact, it does not start up at all.
My setup:
MacVim (32bit cause of this) (vim 7.3)
:scriptnames does not list ftplugin/slimv.vim while plugin/paredit.vim is listed
:set ft? shows filetype=lisp for .lisp files
:messages shows no errors
:filetype filetype detection:ON plugin:ON indent:ON
:echo g:paredit_loaded 1
:echo g:slimv_loaded E121: Undefined variable: g:slimv_loaded \ E15: Invalid expression: g:slimv_loaded
compiled with +python (2.7)
SBCL and slime are installed - works flawless with emacs.
I tried it with and without let g:slimv_swank_cmd = ... in .vimrc and changed the line recommended on the plugin page from
let g:slimv_swank_cmd = '!osascript -e "tell application \"Terminal\" to do script \"sbcl --load ~/.vim/slime/start-swank.lisp\""'
to
let g:slimv_swank_cmd = '!sh -c "sbcl --load /Applications/MacVim.app/Contents/Resources/vim/runtime/slime/start-swank.lisp" &'
since the osascript was not working and I don't know how to fix it. But a similar call to xterm is sufficient for Linux so my sh call should be fine.
Well, I got no idea what to try next. :/
The problem got solved by installing slimv to ~/.vim instead of the vim ebedded in MacVim. Maybe some kind of bug? However, Common Lisp + vim - I just love it.
Because moving the slimv plugin to ~/.vim fixed it, I suspect the problem is that MacVim's default /Applications/MacVim.app/Contents/Resources/vim/runtime/ftplugin/lisp.vim is being sourced before the ftplugin/lisp/slimv-lisp.vim file provided with slimv.
Both of those files (lisp.vim and slimv-lisp.vim) start with code like this:
" Only do this when not done yet for this buffer
if exists("b:did_ftplugin")
finish
endif
" Don't load another plugin for this buffer
let b:did_ftplugin = 1
and so whichever file gets sourced first will prevent the other file from running since vim does finish (exits the script) if it detects that another *lisp*.vim script was run previously and therefore set the b:did_ftplugin buffer-local variable.
You can tell this is happening by running MacVim from the command line with the arguments:
-V20macvim-log.txt hello.lisp
Then quit the MacVim session that starts up, and look at the macvim-log.txt file it created.
Search for b:did_ftplugin and you'll see it referenced each time lisp.vim or slimv-lisp.vim runs, and you can see that lisp.vim runs first, which prevents slimv-lisp.vim from working.
Moving your slimv install from the /Applications/MacVim.app/ dir to your ~/.vim dir will change the order so that slimv-lisp.vim is sourced before lisp.vim, and then slimv will work.
If slimv.vim is not listed in :scriptnames and g:slimv_loaded is undefined then you don't have the plugin loaded at all. I guess you don't have filetype plugins enabled. Paredit is a general plugin but slimv.vim is a filetype plugin and filetype/indent plugins must explicitly be enabled. Try to add these lines to your .vimrc:
filetype plugin on
filetype indent on
The problem got solved by installing slimv to ~/.vim instead of the vim ebedded in MacVim. Maybe some kind of bug?
However, Common Lisp + vim - I just love it.

Resources