.vimrc "set pastetoggle=<F2>" giving error while running "source .vimrc" - vim

I'm using CentOS 7 and added set pastetoggle=<F2> in .vimrc to toggle the auto-indentation.
While running source .vimrc, it is throwing the below error
-bash: .vimrc: line 4: syntax error near unexpected token `newline'
-bash: .vimrc: line 4: `set pastetoggle=<F2>'
Here's my .vimrc file for reference
set ai
set tabstop=2
set expandtab
set pastetoggle=<F2>
Please help me and let me know, how to resolve the issue?

You are trying to source a vim config file in your shell, which would indeed throw an error. If you are trying to update the vim config on the go, then after updating your ~/.vimrc file(assuming you are using vim to edit the vimrc file) , from vim open the command line mode by pressing : and type in source % (where % denotes current file). Then your new config gets updated on the go.
If you're lazy like me then bind it to a key for sourcing, like so in normal mode :
nnoremap <leader>so :w<cr>:source %<cr>
If you are using some other text editor to edit ~/.vimrc, then save and exit the file, then open a new instance of vim and your changes get updated automatically.

Related

Syntax for .vimrc not being understood by bash

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.

Added new scripts for vim functionality that is not working

I am in a Mac OS and I just added some scripts to get new functionality from my vim editor and when I go back into the vimrc file I continue to get this error:
vim ~/.vimrc
Error detected while processing /Users/danale/.vimrc:
line 12:
E117: Unknown function: pathogen#infect
E15: Invalid expression: pathogen#infect()
I have looked at similar posts here that are not very helpful. Ultimately, I would like to use nerdtree configuration so I can use VIM as my IDE.
If I hit enter anyway, I get this error:
Error detected while processing VimEnter Auto commands for "*":
E492: Not an editor command: NERDTree | endif
and it does not take me to a nerdtree type of view just an empty welcome to vim view.
You need to install pathogen.

syntax error near unexpected token `newline' for my nnoremap in .vimrc?

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.

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