Syntax for .vimrc not being understood by bash - linux

I've written multiple .vimrc files before, and every one of them has worked great - until this one. I'm currently running LMDE 4 (Linux Mint Debian Edition 4), and some very odd behavior is coming up. Here's a few examples of some test cases:
~/.vimrc
" Test comment
Terminal
usr#computer:~$ source ~/.vimrc
bash: /home/usr/.vimrc: line 1: unexpected EOF while looking for matching ':'
bash: /home/usr/.vimrc: line 2: syntax error: unexpected end of file
usr#computer:~$
In other words, even if the .vimrc is nothing but a single comment line, it doesn't seem to be understood.
Here's another fun example...
.vimrc
" Test comment 1
set number
" Test comment 2
set expandtab
Terminal
usr#computer:~$ source .vimrc
Test comment 1
set number
: command not found
usr#computer:~$
And, finally, if I exclude all comments...
.vimrc
set colorscheme default
Terminal
usr#computer:~$ source .vimrc
usr#computer:~$ vim .vimrc
Error detected while processing /home/usr/.vimrc:
line 1:
E518: Unknown option: colorscheme
Press ENTER or type command to continue
Note that it seems to source fine here, but when I go to reopen the file with vim, it spews out this error. Also note that this seems to potentially be specific to colorscheme (does not happen if I were to do set number or set expandtab, presumably some other commands are also readable).
Any thoughts/ideas? I'm seriously stumped. Thanks in advance.

.vimrc is a Vim script, not a shell script. Both Vim and shell have separate source commands which executes the commands in a file in Vim or shell, respectively.
.vimrc is sourced by Vim when Vim starts; it has nothing to do with the shell.

Related

Errors while sourcing .vimrc

I am using bash terminal and in my .vimrc I have the following lines:
set number
"set tags+=/users/vinod/ctags_related/tags
imap 2s <SPACE><SPACE>
When I save and then try to source my .vimrc, I get the following errors:
bash: /users/vinod/.vimrc: line 2: unexpected EOF while looking for matching `"'
bash: /users/vinod/.vimrc: line 4: syntax error: unexpected end of file
The line number shown in the second error doesn't exist in my .vimrc
Why am I getting these errors? How can I fix them?
TIA
Vinod
If you are doing source ~/.vimrc from the terminal prompt, then you are getting errors you should expect. The .vimrc file contains vimscript, which only the vim program understands. Bash is giving you errors because it is not supposed to source that file. When you start vim, normally by just typing vim and hitting enter, vim will automatically source your .vimrc

Why is properly commented line in vimrc giving error for Missing quote?

I've been trying to add comments to my vimrc file and for some reason it is not allowing me to comment after the execute pathogen line.
4: execute pathogen#infect() "Enable Pathogen
5:
6: syntax on "*Syntax color highlighting*
With vimrc like this, saving and exiting and reentering vim, it gives me an error 'Line 4: Missing quote: "Enable pathogen'
I have syntax highlighting on, and all other comments I make show up as comments, but anything after () on that line doesn't. I don't know if it's something simple I'm missing or if anyone else has seen this, but it seems strange that it's just this one line giving me problems.
I am running Mac OS X 10.13.6 and Vim 8.2.600
Please, read :h :comment carefully
It is not possible to add a comment to a shell command ":!cmd" or to the
":map" command and a few others (mainly commands that expect expressions)
that see the '"' as part of their argument:
...
execute
...
syntax
Also note that if the command does not take "bar" as part of argument (see :h :bar), you still can do
execute pathogen#infect() | "Enable Pathogen
Here you have two commands in a row, and the second one is a pure comment.
However, I suggest always write comments on separate lines and not to mess with this stuff at all.

How to jump back to netrw when splitbelow is on

If I open a file in a current directory using netrw and then reopen the netrw using :Sexplore the netrw window opens below (I have splitbelow set), but the cursor remains in the file being edited and I cannot move to the netrw window using CTRL-W combinations.
Am I doing something wrong or is this a bug?
Steps to reproduce
run vim .
netrw opens, highlight a file in the current directory (let's say test.txt) and press Return, file test.txt opens
run :Sexplore cmd
netrw opens below but the cursor remains in the file opened previously.
My .vimrc
set nocompatible
set splitbelow
VIM version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Dec 8 2015 23:11:08)
MacOS X (unix) version
Included patches: 1-944
This is how it looks like:
I cannot reproduce with version 154a (use :echo g:loaded_netrwPlugin to check your netrw version).
Try with the latest version.
Edit:
It is possible that the problem is cause by some other plugin interference or settings. You could try following the approach described at Vim FAQ 2.5:
2.5. I have a "xyz" (some) problem with Vim. How do I determine it is a
problem with my setup or with Vim? / Have I found a bug in Vim?
First, you need to find out, whether the error is in the actual
runtime files or any plugin that is distributed with Vim or whether it
is a simple side effect of any configuration option from your .vimrc
or .gvimrc. So first, start vim like this:
vim -u NONE -U NONE -N -i NONE
This starts Vim in nocompatible mode (-N), without reading your
viminfo file (-i NONE), without reading any configuration file (-u
NONE for not reading .vimrc file and -U NONE for not reading a .gvimrc
file) or even plugin.
(...)
If the error does not occur when starting Vim this way, then the
problem is either related to some plugin of yours or some setting in
one of your local setup files. You need to find out, what triggers the
error, you try starting Vim this way:
vim -u NONE -U NONE -N
If the error occurs, the problem is your .viminfo file. Simply delete
the viminfo file then. If the error does not occur, try:
vim -u ~/.vimrc --noplugin -N -i NONE
This will simply use your .vimrc as configuration file, but not load
any plugins. If the error occurs this time, the error is possibly
caused by some configuration option inside your .vimrc file. Depending
on the length of your vimrc file, it can be quite hard to trace the
origin within that file.
The best way is to add :finish command in the middle of your .vimrc.
Then restart again using the same command line. If the error still
occurs, the bug must be caused because of a setting in the first half
of your .vimrc. If it doesn't happen, the problematic setting must be
in the second half of your .vimrc. So move the :finish command to the
middle of that half, of which you know that triggers the error and
move your way along, until you find the problematic option. If your
.vimrc is 350 lines long, you need at a maximum 9 tries to find the
offending line (in practise, this can often be further reduced, since
often lines depend on each other).
Obviously you will have to load netrw manually (which can be done by sourcing plugin/netrwPlugin.vim -- if you are using some plugin manager you will have to move the plugin to ~/.vim/ or change your runtime path due to the autoload functions) and set nocompatible and splitbelow.
Actually there is an adapted version of this procedure in :help netrw-debug:
Step 2: assuming that you've installed the latest version of netrw,
check that your problem is really due to netrw. Create a file called
netrw.vimrc with the following contents:
set nocp
so $HOME/.vim/plugin/netrwPlugin.vim
Then run netrw as follows:
vim -u netrw.vimrc --noplugins [some path here]
Perform whatever
netrw commands you need to, and check that the problem is still
present. This procedure sidesteps any issues due to personal .vimrc
settings and other plugins. If the problem does not appear, then you
need to determine what setting in your .vimrc is causing the conflict
with netrw or which plugin.
Step 3: If the problem still is present, then get a debugging trace
from netrw:
(...)

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

Error after 'source ~/.vimrc' after setting up pathogen

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

Resources