I tried mapping the key to :SyntasticCheck of Syntastic vim in .vimrc
nmap <leader>sc :SyntasticCheck<CR>
but it doesn't work. Also, when I type this command :SyntasticCheck into vim command it doesn't work, but when I save file with :w it works. It checks the syntax & raise errors in bottom window.
Any Ideas?
Syntastic runs the checker on the current file, not the contents of the buffer. If you have a file without syntax errors, add a syntax error, but don't save the file, :SyntasticCheck will not mark the error because you haven't saved the file. Your mapping is probably working fine, but nothing is getting marked by Syntastic because you haven't saved the file.
Related
How do I force open my .vimrc?
I recently made a modification, not certain exactly what I did, but I think I accidentally typed an "x" in my plugins when trying to close. Suddenly neither vim or .vimrc will open.
I get a pause, several blank lines, and then terminal just returns to default command line.
Use vim -u NONE .vimrc to skip reading all startup files and edit .vimrc.
In my ~/.vimrc, I have an if statement that is supposed to determine if the open file is a python file or not:
if (&ft=='python')
map <F9> <esc>:w<enter>:!python3 '%'<enter>
endif
The goal is to bind the python execution command to F9 if the file is a python file, but when I press F9 in a .py file nothing happens. I took out the if statement, and it worked. What is going wrong?
Try something like that instead:
au FileType python map <buffer> <F9> <esc>:w<bar>!python3 '%'<cr>
Your .vimrc config file runs only once on startup. So if you put an if test at this time, it won't work, because no python file is then currently edited.
But you can use .vimrc to setup an automatic behaviour : something that vim will do each time it will encounter a special condition. The condition can be in your case : "A new file is being editing, and its file type is 'python'". See :h :au
In cases like yours, it's useful to add the <buffer> parameter in the :map command : it limits the scope of your mapping to the current buffer only : so when you will press F9 on a non-python buffer, the mapping will not be trigerred.
EDIT:
In my first answer, I also deleted the <esc> in your command, but maybe I'm wrong about this, because it can cause problems in visual mode, so I put it again. You have to test it in visual mode, I didn't do it.
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
I get this error when I source my .vimrc file,
> source ~/.vimrc
bash: /home/dev/.vimrc: line 1: syntax error near unexpected token `('
bash: /home/dev/.vimrc: line 1: `call pathogen#infect()'
The contents of my .vimrc file are,
call pathogen#infect()
syntax on
filetype plugin indent on
set smartindent
set tabstop=4
set shiftwidth=4
set expandtab
set backupdir=~/.vimbackup
set directory=~/.vimdir
I've also tried using 'execute pathogen#infect()' in the chance that it doesn't like the 'call' keyword.. and I've tried passing in the path to my bundle file as follows,
call pathogen#infect('~/.vim/bundle/{}')
I've also tried just putting 'bundle/{}' as the argument to infect... But I don't understand vim/bash well enough to know what direction to go in, would appreciate any help...
The reason I'm trying to source my .vimrc file is because everytime I use vim to edit a file I get litter from the file in the form of files being left that have this format,
.file_i_just_worked_on.un~
which is really annoying making my dir messy. I've read that I need to have
set backupdir=~/.vimbackup
set directory=~/.vimdir
to not have those files being dropped by vim everywhere... Would appreciate any help with this issue.
You're asking bash to read your .vimrc file, but it isn't equipped to parse that.
You instead need to have vim read it. You can either start a new instance of vim, or type :source ~/.vimrc from normal mode within a running vim session.
If vim is still creating backup files in your current directory, that may be because you haven't created the ~/.vimbackup or ~/.vimdir directory.
As qqx mentioned, I need to ":source ~/.vimrc" inside of vim, not use bash...
To get rid of the .file.un~ files I need to have a
set undodir=path/to/dir
in my vimrc
I'm trying to add Pydiction into MacVim, I followed the readme file.
Put python_pydiction.vim in ~/.vim/after/ftplugin/ and write:
let g:pydiction_location = '~/pydiction/complete-dict'
into my .vimrc file. But when I press tab in MacVim, an error will rise:
undefined variable g:pydiction_location
Can anyone tell me where am I wrong ?
As discussed in the comments, you were editing a file that wasn't actually your .vimrc file. You may have typed:
:e vimrc
:e ~/vimrc
:e .vimrc
none of which will probably edit your actual .vimrc file. It must have a dot in front of it AND be located in your home directory. You can also type :pwd in vim to see the current working directory. If you do :e .vimrc it will create a new file in whatever directory you are in if it doesn't exist.
Do you use NERDTree? If so it seems that Pydiction and NERDTree conflict with each other in some way.