Install Paredit vim plugin on Mac OSX - vim

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()

Related

How to turn on syntax highlighting in VIM 7.3 OSX

System = OSX 10.9.4
I am trying to turn on syntax highlighting in vim while using the terminal. However, I am unable to get it to work properly.
Things I've tried:
located the vimrc file and added the following code:
set ai " auto indenting
set history=100 " keep 100 lines of history
set ruler " show the cursor position
syntax on " syntax highlighting
set hlsearch " highlight the last searched term
filetype plugin on " use the file type plugins
Located vimrc under directory:
cd /usr/share/vim/
The interesting thing is that once I add the code to the vimrc using vim, followed by exiting (x), and re-opening the file again, syntax is correctly highlighted in the vimrc.
However, when I try to make a new vim file called "test", copy the same code, save and exit. Re-open it, the syntax is not highlighted at all.
It appears that syntax highlighting only works when I open the actually vimrc file---and not when I try to create a new one or open another file that should have syntax highlighting.
I've also tried to create a .vimrc (exact copy) under the ~/ (directory). No success.
Made a new file called "test" and tried turning it on while active as well:
vim test
"then within vim"
:syntax on
I am really confused as to why this partially works.
Any help is much appreciated.
Cheers!
p.s. I have followed these instructions as well from: http://geekology.co.za/article/2009/03/how-to-enable-syntax-highlighting-and-other-options-in-vim
*I am aware of macvim, but would like a solution for the native vim in terminal. Thanks.
NEVER do anything in $VIM as it will work only by luck, cause unexpected behaviors and likely be overwritten next time Vim is updated.
What you have put in /usr/share/vim/vimrc should be in ~/.vimrc.
filetype on and syntax on are the bare minimum you need in your ~/.vimrc for syntax highlighting to work.
$ vim ~/.vimrc gives you syntax highlighting because the file is recognized by Vim as a vim file. Filetype detection is mostly dependent on file extensions so you can't expect any syntax highlighting in a file called test.
$ vim test.py, on the other hand, should give you syntax highlighting.
If the filetype is not detected, you can force it with :set filetype=python.
You most probably want to enable indentation along with syntax highlighting, so add these to lines to ~/.vimrc
filetype plugin indent on
syntax on
Steps with screenshots can be found here
http://osxandiosdaily.com/how-to-enable-vim-syntax-highlighting-on-mac-osx/
Inside of your file, enter command mode and enter the command
:syntax on

GoLang Highlighting in vim not working

I've seen multiple places(including here) that to add syntax highlighting you have to add certain lines to the .vimrc:
"Stuff for GoLang"
filetype off
filetype plugin indent off
set runtimepath+=$GOROOT/misc/vim
filetype plugin indent on
syntax on
That is what's currently in my .vimrc
Restarted vim, terminal, system, and still no highlighting. Any suggestions?
Okay guys, I go the answer:
$GOROOT needs to be defined or you can simply put the location of your go installation.
Ensure that the corresponding runtime files are actually there.
$GOROOT must be defined; check with :echo $GOROOT
There must a syntax plugin (syntax/go.vim) below $GOROOT/misc/vim. Check with :echo filereadable($GOROOT . '/misc/vim/syntax/go.vim').
After opening a Go file, you can check again via :scriptnames and :syntax list.

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.

vim can't open syntax.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).

Unable to set syntax highlighting automatically in Vim

I have the following in my .vimrc
syntax on
filetype plugin indent on # Thanks to Jeremy
I run
vim ~/.vimrc
I get the right syntax highlighting.
I source many files in my .vimrc. My .vimrc is a like a roadmap for me where I navigate by
CTRL-W f
The problem occurs when I navigate to a file which I have sourced: no colors.
All my sourced files contain the word Vim in their PATHs.
It may be possible to use this fact in solving the problem.
How can you provide a syntax highlighting automatically for the sourced files?
Do the files in question end in ".vim"? If not, then vim's filetype detection may not be able to determine that these files contain vim-script. You can either rename the files so that they end in .vim, or add an autocommand to set the filetype appropriately.
To do the latter, you can add something like this to your .vimrc:
au! BufNewFile,BufRead PATTERN set filetype=vim
replacing "PATTERN" with a file pattern that will match the files in question.
EDIT:
See :help autocmd-patterns for how the patterns work:
The file pattern {pat} is tested for a match against the file name in one of
two ways:
1. When there is no '/' in the pattern, Vim checks for a match against only
the tail part of the file name (without its leading directory path).
2. When there is a '/' in the pattern, Vim checks for a match against the
both short file name (as you typed it) and the full file name (after
expanding it to a full path and resolving symbolic links).
In particular, note this example:
Note: To match part of a path, but not from the root directory, use a '*' as
the first character. Example: >
:autocmd BufRead */doc/*.txt set tw=78
This autocommand will for example be executed for "/tmp/doc/xx.txt" and
"/usr/home/piet/doc/yy.txt". The number of directories does not matter here.
In your case you probably want something like:
au! BufNewFile,BufRead */Vim/* set filetype=vim
To make vi consider my jQuery (.jq) files are actually javascript (.js) I did: -
Create and/or or edit your vimrc file ...
e#dev3:~$ vi ~/.vimrc
Add the following text (press i to insert) ...
if has("syntax")
syntax on
filetype on
au BufNewFile,BufRead *.jq set filetype=javascript
endif
Save the vimrc file ...
[esc]:wq[enter]
Further, to find supported filetypes look in filetype.vim ...
e#dev3:~$ sudo locate filetype.vim
/usr/share/vim/vim72/filetype.vim
e#dev3:~$ sudo grep "\.js[, ]" `locate filetype.vim`
au BufNewFile,BufRead *.js,*.javascript,*.es,*.jsx setf javascript
... the filetype is the setf arg ...
e#dev3:~$ sudo grep "\.js[, ]" `locate filetype.vim` | cut -d " " -f 4
javascript
Have fun.
What is the extension of the files you source? The extension is the usual way for Vim to detect what syntax highlighting it neds to use, and for source-able files (vimscript) it should be .vim. It sounds like that's not the case, if you only see the problem with the sourced files, and not with any others.
One obvious question is there's no line saying "syntax off" in the files you're sourcing?
It could be:
the "filetype" option
the filetype might not be auto-detected by vim
filetype on sorts the first, and the second is fixable with autocmds based on the file extensions.

Resources