Here is the offending autogroup:
augroup EJB
autocmd! EJB
autocmd BufRead,BufNewFile Captain's.log,*.wiki setlocal expandtab shiftwidth=2 softtabstop=2 tabstop=2
autocmd BufRead,BufNewFile Captain's.log,*.wiki syn match Todo "\<\(TODO\|EJB\)"
"autocmd BufRead,BufNewFile Captain's.log,*.wiki setlocal commentstring=// %s
" Scroll to end of file on opening, then find the last non-blank line.
autocmd BufRead Captain's.log,*.wiki :normal! G{}
augroup END
If I now open Captain's.log in a console (openSuSE 13.2 KDE konsole/yakuake) vim session - but not a gvim window - then I get this artifact at the bottom of the vim buffer:
/bin/bash: -c: line 0: unexpected EOF while looking for matching `''
but it disappears as soon as I scroll to that line of the display.
If I add in (uncomment) the commentstring line, then bash gives me a full-on error:
"Captain's.log" 2185L, 157386C
Error detected while processing BufRead Auto commands for "Captain's.log":
/bin/bash: -c: line 0: unexpected EOF while looking for matching `''
/bin/bash: -c: line 1: syntax error: unexpected end of file
Line 2185 is just the end of the file.
I have tried escaping the apostrophe in the filename in the augroup with \' and '' (ie. double single-quotes), and have tried single-/double-quoting the filename, to no avail. The first two don't change the error, and the latter two make the pattern not match.
What am I missing here? Thanks.
UPDATE: As #FDinoff suggests, it appears that bash is trying to execute Captain's.log. But I figure that the problem has still got to be a bug in the parsing of vimrc - I just copied-and-renamed the file to Captains.log and updated the autogroup accordingly, and the error goes away.
So obviously I now have a workaround. But I would nonetheless be interested in a full explanation of and fix for the problem.
Related
How can one detect stdin input in .vimrc?
I have the following command in my ~/.vimrc:
autocmd BufWinEnter * silent loadview
to open a file with a cursor at the last line position. However, if I use vim on stdin, I get the following error message:
Error detected while processing BufWinEnter Autocommands for "*":
E32: No file name
Press ENTER or type command to continue
How can one detect that vim is used on stdin in .vimrc to suppress execution of the command in such cases?
Thank you for your help!
v:argv is a list that begins with the complete path of the program, and contains each argument, if any.
If you call Vim like this:
$ vim
:echo v:argv outputs something like:
['/path/to/vim']
If you call Vim like this:
$ vim foo.txt bar.json
:echo v:argv outputs something like:
['/path/to/vim', 'foo.txt', 'bar.json']
If you call Vim like this:
$ echo 'foo bar baz' | vim -
:echo v:argv outputs something like:
['/path/to/vim', '-']
Therefore, you can condition the execution of :loadview to the content of v:argv[1]. Note that we use get() because the index 1 may not exist:
autocmd BufWinEnter * if get(v:argv, 1, '') != '-' | silent loadview | endif
Reference:
:help :get()
:help v:argv
Need some help on this to explain why I can't call a Plugin command from autocmd in VIM:
autocmd! Syntax * if !empty(&l:filetype) | RainbowToggleOn | endif
Vim detects a syntax error with:
Error detected while processing Syntax Auto commands for "*":
E488: Trailing characters: RainbowToggleOn | endif
I believe this issue caused by a reversed loading order. For some reason my autocmd in vimrc is running before the plugin is loaded. My guess is that it has something to do with the way Rainbow.vim is structured.
According to this answer the loading order is correct: Does Vim load plugins after loading vimrc?
So I was able to solve by delaying the ref lookup of the command:
autocmd! Syntax * if !empty(&l:filetype) | exec 'RainbowToggleOn' | endif
I'm a new user of Neovim and trying to figure out how to enable syntax highlighting for Ruby.
What config should i edit?
edit:
This is my current config:
➜ ~ cat ~/.nvimrc
filetype plugin indent on
syntax on
set tabstop=2
set number
set noswapfile
" Automatically indent on new lines
set autoindent
" Copy the indentation of the previous line if auto indent doesn't know what to do
set copyindent
" Indenting a line with >> or << will indent or un-indent by 2
set shiftwidth=2
" Pressing tab in insert mode will use 4 spaces
set softtabstop=2
" Use spaces instead of tabs
set expandtab
" [SEARCH]
:set incsearch
:set hlsearch
" <Ctrl-l> redraws the screen and removes any search highlighting.
nnoremap <silent> <C-l> :nohl<CR><C-l>
And this is the error i get when loading Neovim:
➜ ~ nvim test.rb
Error detected while processing /Users/user/.nvimrc:
line 2:
E484: Can't open file /usr/local/Cellar/neovim/HEAD/share/vim/syntax/syntax.vim
Press ENTER or type command to continue
Neovim uses the xdg specification for their config files. If you are already using vim. (If you are transferring from an old version of neovim ~/.nvimrc is now $XDG_CONFIG_HOME/nvim/init.vim and ~/.nvim is now $XDG_CONFIG_HOME/nvim)
mkdir -p ${XDG_CONFIG_HOME:=$HOME/.config}
ln -s ~/.vim $XDG_CONFIG_HOME/nvim
ln -s ~/.vimrc $XDG_CONFIG_HOME/nvim/init.vim
should get you close to running with neovim (This might not work for all plugins but its a start).
All you should need in $XDG_CONFIG_HOME/nvim/init.vim is the following
filetype plugin indent on
syntax on
to get syntax highlighting for ruby.
I am using vim together with NERDTree and MiniBufExplorer. My colorscheme is peaksea. If I start vim, no syntax is highlighted in the first buffer. The other buffers have syntax highlighted. I have "syntax enable" in my vimrc. If I type :edit the syntax gets highlighted. So I tried
autocmd VimEnter * edit
but still nothing is highlighted. Did anyone encounter a similar problem or has anyone an idea how to fix this?
I remapped F12 to redo my syntax highlighting in case it gets messed up:
nnoremap <F12> :syntax sync fromstart<cr>
Maybe you can just run it as an autocmd event in your vimrc based on reading a new buffer?
autocmd BufReadPost * :syntax sync fromstart
I have the following lines in my .vimrc:
" UNIX fileformat
au BufRead,BufNewFile * set fileformats=unix,dos
au BufRead,BufNewFile * set fileformat=unix
These are to make any opened file using the unix file format.
It works well in almost all cases except for the help messages. If I type, let's say:
:h help
Vim first complains that:
"helphelp.txt" [readonly] 350L, 13662C Error detected while processing
BufRead Auto commands for "*": E21: Cannot make changes, 'modifiable'
is off: fileformat=unix
Obviously, I am trying to set the fileformat option on a non-modifiable buffer so this error is to be expected. However, what is the cleanest way to get rid of it without removing the feature for other files ?
Is there a way to conditionally apply/not apply autocommands for the help buffers ?
Thank you.
The 'fileformats' is a global setting, it should suffice to set it only once in your .vimrc:
set fileformats=unix,dos
The error will occur for any other unmodifiable file, not just help files. Therefore, it's best to make the setting conditional on the 'modifiable' buffer setting:
au BufRead,BufNewFile * if &l:modifiable | setlocal fileformat=unix | endif
(Alternatively, you could also just :silent! the error, but I regard the conditional as cleaner.)