"Unclosed expression sequence" error in VimScript - vim

I have the following in order to set my statusline:
set stl=%<\ [Buf:\ %n]%m\ %f\ [
set stl+=%{empty(&filetype) ? \"" : \"," . toupper(&filetype) . \", \"}
set stl+=%{(&fenc!=''?&fenc:&enc)}]
set stl+=%=[0x\%02.2B]\ [Line:\ %04l/%04L\ \|\ Col:\ %c%V]\ (%P)
I personally don't see anything wrong with it, but it just keeps giving me the following error:
E540: Unclosed expression sequence: stl+=%{empty(&filetype)
Does anybody know what this error means? I've been forever trying to solve it, but I just can't understand what it means.
Thanks for all your help. :)

With :set, all spaces in the value must be escaped with a backslash, too. Therefore, it's recommended to do away with any unnecessary whitespace there, or use :let &stl = '...' instead (where only contained ' characters must be doubled).

Related

vimrc how to invoke unix find?

i want to set the tags variable to the set of all gotags files i generated in specific folder(s) using exuberant Ctags. (gotags is nothing but the tags file renamed).
i put following lines in my .vimrc file.
set tags+=/usr/local/go/src/gotags
set tags+=`find /home/vimal/gowork/src -name gotags`
but it doesnt work and i get the following error
$ vi ~/.vimrc
Error detected while processing /home/vimal/.vimrc:
line 157:
E518: Unknown option: /home/vimal/gowork/src
Press ENTER or type command to continue
how can i fix the error and set the tags variable with the value: list of all the gotags files under one directory tree.
Inventing new syntax tends not to work that well in practice. Use system() to run external commands from Vim, not backticks. Also set in Vim is weird, it doesn't evaluate RHS the way you expect. Most of the time it's a lot simpler to use let &option = ... instead of set option=....
Anyway, to answer your question, you don't need to run find(1) for that, plain Vim functions are enough for what you want:
let &tags = join(extend([&tags, '/usr/local/go/src/gotags'],
\ findfile('gotags', '/home/vimal/gowork/src', -1)), ',')

Forcefully quit vim even if pattern not found

I am using command :%s/foo/bar/g | wq to find and replace using vim. It works fine if pattern is available but if pattern isn't available it Error detected while processing command line:
E486: Pattern not found: foo
How can I forcefully exit even if pattern isn't found? I tried wq! in above command but didn't help
The problem is with substitute issuing the error. You can set the flag e
:%s/foo/bar/ge | wq
which should prevent the "No match" error from breaking a mapping or commands.
:h :s_flags
Every time I tried to exit with :q it gave me an error message "E486: Pattern not found:..."
If I press ":" it appears "?" and instead of :q appeared ?q and gave me the error message: "E486: Pattern not found:..."
Cause? Instead of the US keyboard, I had set the Romanian (Standard) keyboard.
And instead of ":" type "ș" (special Romanian character).
I set back to US keyboard and everything was solved.

function failed when call it from a command in vim

When I find the word in the current file, I need to first type "/keyword", but I can't see all the matched rows, So I tried to use the following command to do a shortcut, but it doesn't work, could you please help check why it failed?
function! FindCurrentFile(pattern)
echo a:pattern
execute ":vimgrep" . a:pattern . " %"
execute ":cw"
endfunction
command! -nargs=1 Fi call FindCurrentFile(<args>)
By the way, if you just need a quick overview over the matches you can simply use
:g//print
or
:g//p
(You may even leave out the p completely, since :print is the default operation for the :global command.)
When the current buffer has line numbers turned off, the results produced by :g//p can be difficult to take in fast. In that case use :g//# to show the matches with the line numbers.
Another trick that works for keywords is the normal mode command [I. It shows a quick overview of all the instances of the keyword under the cursor in the current buffer. See :h [I.
try to change the line in your function into this:
execute ':vimgrep "' . a:pattern . '" ' . expand("%")
<args> is replace with the command argument as is - that means that if you write:
Fi keyword
the command will run:
call FindCurrentFile(keyword)
which is wrong - because you want to pass the string "keyword", not a variable named keyword.
What you need is <q-args>, which quotes the argument.
BTW, if you wanted more than one argument, you had to use <f-args>, which quotes multiple arguments and separates them with ,.

please help to make it work of vimscript

why I can't set path success.
let s:WORKDIR = getcwd()
set path += ".," . s:WORKDIR . "/**"
echo &path
and the echo result is, my current directory is "/home/myname/example", my expected result is
".,/home/myname/example/**", but what i get is,
.,/usr/include,,
it seems this didn't work in my .vimrc script; please help, thanks.
Your syntax of the :set command is wrong; you should be getting errors, too. The += must not be surrounded by whitespace, and you cannot use an expression on the right-hand side. Better use the :let command; it can also modify Vim options (&optionname), not just variables:
let &path .= ",.," . s:WORKDIR . "/**"

issue with setting up vim errorformat

My compiler and lint tools put out errors in two different formats. I decided to incrementally setup my errorformat, first for lint and then add a pattern for a compiler.
Here is the lint output line I'm trying to match to
"C:\Documents and Settings\user\Projects\MyProject\trunk\src\myfile.c",126 Info 754: local structure member 'myStructMember' (line 126, file C:\Documents and Settings\user\Projects\MyProject\trunk\src\myfile.c) not referenced
My first attempt was
set errorformat=\"%f\"\\,%l\ \ %t%s
And it worked.
Then I tried to set it up as follows
set errorformat=\"%f\"\\,%l\ \ %t\ %s
And it stopped working.
Does anybody know what is the issue?
I did read through the documentation but it didn't help.
Any help is appreciated.
" Match the filename and line number
let &errorformat = '"%f"\,%l'
" Match white space, first character of error type, the rest of the characters
" of the error type, and white space again.
let &errorformat .= '%*\s%t%*\w%*\s'
"Match error number, whitespace and error message.
let &errorformat .= '%n:%*\s%m'

Resources