This question already has answers here:
error while running "source .vimrc"
(2 answers)
Closed 2 years ago.
I have the following written in my .vimrc file
set number
set hlsearch
set mouse=a
map F2 :bprev CR
Getting follwoing error while sourcing .vimrc file
-bash: .vimrc: line 4: syntax error near unexpected token `newline'
-bash: .vimrc: line 4: `map <F2> :bprev <CR>'
.vimrc isn't a shell script; it's a vim script. Both programs have a set command (though each does something very different than the other), which is how you get to line 4 at all. The problem here is that the shell sees the < and > as redirection operators, and the final > is followed by a newline, not a file name; hence, the syntax error.
Related
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
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.
I am trying to install vim-plug and I followed your instructions in your tutorial. I have written in .vimrc like so:
call plug#begin('~/.vim/autoload')
call plug#end()
but I get the following errors:
-bash: /Users/user/.vimrc: line 18: syntax error near unexpected token `('
-bash: /Users/user/.vimrc: line 18: `call plug#begin('~/.vim/autoload')'
Do you know what I am doing wrong?
Note how the error messages you're receiving start with -bash:, which indicates these lines are being parsed by bash, not Vim.
Can you somehow explain how that is happening?
Are you by any chance sourcing this file from your shell? Are you referring to .vimrc from somewhere? How are you starting Vim exactly? Do you have some commands in your .vimrc around these lines that would cause them to be passed to a shell?
Figuring out how this is happening should make it easy for you to figure out how to fix it.
This question already has answers here:
error while running "source .vimrc"
(2 answers)
Closed 4 years ago.
Below is my .vimrc file
set nocompatible
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'tomlion/vim-solidity'
Plugin 'othreaa/yajs.vim'
call vundle#end()
filetype plugin indent on
set autoindent
set wrap
set nobackup
set ruler
syntax on
set number
set tabstop=4
colo desert
syntax on
when I type 'source .vimrc' to activate the configuration file, i got the following error message
-bash: .vimrc: line 6: syntax error near unexpected
token `('
-bash: .vimrc: line 6: `call vundle#begin()'
I cannot see what is wrong. Can I help?
Bash cannot parse that. You need to use Vim instead, to parse. Open up Vim and type :source ~/.vimrc in Normal mode.
Here is the configuration of my .vimrc.
For the 12 th line.
nnoremap <F12> :!/opt/google/chrome/chrome '%:p'<CR>
source .vimrc
bash: /home/debian9/.vimrc: line 12: syntax error near unexpected token `newline'
bash: /home/debian9/.vimrc: line 12: `nnoremap <F12> :!/opt/google/chrome/chrome '%:p'<CR>'
How to fix it ?
Don't use source in your Bash shell; the right command is :source .vimrc inside Vim!
Please note that reloading your Vim configuration may work, or not (depending what you do, how you define :autocmds, whether the changed configuration affects already loaded plugins). If in doubt, it's easier to just :quit Vim and restart it; the new .vimrc will then be loaded automatically.
The syntax of your Vim configuration in ~/.vimrc is Vimscript; this is only understood by Vim itself. Your shell configuration would be put in (for example) ~/.bashrc; you can source that in your shell.