I have the jslint installed with npm on my system.
It produces error messages in the following format:
1 1,9: Missing name in function statement.
function() {
2 2,11: Use '===' to compare with '0'.
if (x == 0) {
3 4,2: Unnecessary semicolon.
};
I wrote a compiler plugin for Vim to parse the error messages, but I could not figure out the problem with the errorformat. I have the following now in my compiler file:
CompilerSet makeprg=jslint
\\ $*
\\ %
CompilerSet errorformat=
\%*[\ ]%n\ %l\,%c:\ %m,
\%-G%.%#
Which AFAIK should do the following:
%*[\ ] -- skip the whitespaces in the beginning of the line
%n -- match the error number
\ -- skip a space
%l -- match for the line number
\, -- skip the comma
%c -- match the column number
: -- skip the colon
\ -- skip the space again
%m -- match the error message
, -- new line
%-G%.%# -- skip all the others
It runs the jslint which shows the messages but the :clist command does not show any errors.
What am I missing?
The problem was with the \,, the skip comma, the correct format is:
CompilerSet errorformat=
\%*[\ ]%n\ %l%.%c:\ %m,
\%-G%.%#
The comma must be escaped with \\, since , is a special char in errorformat, and \ is a special char in vim config file, which must itself be escaped.
To vim, your error format is then %*[ ]%n %l\,%c: %m,%-G%.%#, since the \ at the beginning of the line or before spaces are escapes for vim, not for the error format.
Related
I have a file which is as following
!J INCé0001438823
#1 A LIFESAFER HOLDINGS, INC.é0001509607
#1 ARIZONA DISCOUNT PROPERTIES LLCé0001457512
#1 PAINTBALL CORPé0001433777
$ LLCé0001427189
$AVY, INC.é0001655250
& S MEDIA GROUP LLCé0001447162
I just want to keep the last 10 characters of each line so that it becomes as following:-
0001438823
0001509607
0001457512
0001433777
0001427189
0001655250
:%s/.*\(.\{10\}\)/\1
: ex-commaned
% entire file
s/ substitute
.* anything (greedy)
. followed by any character
\{10\} exactly 10 of them
\( \) put them in a match group
/ replace with
\1 said match group
I would treat this as a shell script problem. Enter the following in vim:
:%! rev|cut -c1-10|rev
The :%! will pipe the entire buffer through the following filter, and then the filter comes straight from here.
for a single line you could use:
$9hd0
$ go to end of line
9h go 9 characters left
d0 delete to beginning of line
Assuming the é character appears only once in a line, and only before your target ten digits, then this would seem to work:
:% s/^.*é//
: command
% all lines
s/ / substitute (i.e., search-and-replace) the stuff between / and /
^ search from beginning of line,
. including any character (wildcard),
* any number of the preceding character,
é finding "é";
// replace with the stuff between / and / (i.e., nothing)
Note that you can type the é character by using ctrl-k e' (control-k, then e, then apostrophe, without spaces). On my system at least, this works in insert mode and when typing the "substitute" command. (To see the list of characters you can invoke with the ctrl-k "digraph" feature, use :dig or :digraph.
A common idiom for bash is is to use \ to escape the newline at the end of the line,
If a \<newline> pair appears, and the backslash is not itself quoted, the \<newline> is treated as a line continuation (that is, it is removed from the input stream and effectively ignored).
Such that
FOO \
BAR
is the same as,
FOO BAR
How would I write this grammar into pest.rs? Note this means that NEWLINE is significant in my grammar, and I can't merely ignore it.
One method is to set your
WHITESPACE = { ( " "* ~ "\\" ~ NEWLINE ~ " "* ) }
This keeps regular newlines significant unless they're prefixed by \.
Is same question as
How can I have a newline in a string in sh?
but in fish shell.
In bash we have:
$'this is line\nthis is another line'
who produces the expected result, but in fish this doesnt works.
fish has a similar way to do this?
Edit 1:
has the literal method wisely mentioned by the faho:
'this is line
this is another line'
But i'm really curious about the existence of a method keeping reference for \n as line break like in shell.
I want to know if I can use this string "this is a line\nthis is another line" making sure that the fish will consider \n as a line break and not a literal.
Fish replaces \n outside of quotes with a newline, so you can stop and restart the quotes (note no "$" before the quotes):
'this is line'\n'this is another line'
Fish follows quotes across lines, so you can include a literal newline:
'this is line
this is another line'
You can use echo -e (Enable interpretation of backslash escapes), as pointed out by #faho in his comment:
$ echo -e "## Foo\nBar"
## Foo
Bar
From man echo:
Escape sequences
If -e is used, the following sequences are recognized:
o \ backslash
o \a alert (BEL)
o \b backspace
o \c produce no further output
o \e escape
o \f form feed
o \n new line
o \r carriage return
o \t horizontal tab
o \v vertical tab
o \0NNN byte with octal value NNN (1 to 3 digits)
o \xHH byte with hexadecimal value HH (1 to 2 digits)
Edit your config.fish file.
Example in Ubuntu sudo nano /etc/fish/config.fish
Prompt function is what controls the appearance of the fish terminal. Paste this code:
# Put system-wide fish configuration entries here
# or in .fish files in conf.d/
# Files in conf.d can be overridden by the user
# by files with the same name in $XDG_CONFIG_HOME/fish/conf.d
# This file is run by all fish instances.
# To include configuration only for login shells, use
# if status --is-login
# ...
# end
# To include configuration only for interactive shells, use
# if status --is-interactive
# ...
# end
#
function fish_prompt -d "Write out the prompt"
# change output color
set -U fish_color_command '2cff8f' -o
# Aliases
alias cls='clear'
# Prompt
printf '%s#%s%s%s%s\n#>' (whoami) (hostname | cut -d . -f 1) \
(set_color $fish_color_cwd) (prompt_pwd) (set_color normal)
end
According to the f-args documentation, the command line arguments passed to a user defined function, will be automatically split at white-space or tabs as the help shows:
*<f-args>*
To allow commands to pass their arguments on to a user-defined function, there
is a special form <f-args> ("function args"). This splits the command
arguments at spaces and tabs, quotes each argument individually, and the
<f-args> sequence is replaced by the comma-separated list of quoted arguments.
See the Mycmd example below. If no arguments are given <f-args> is removed.
To embed whitespace into an argument of <f-args>, prepend a backslash.
<f-args> replaces every pair of backslashes (\\) with one backslash. A
backslash followed by a character other than white space or a backslash
remains unmodified. Overview:
command <f-args> ~
XX ab 'ab'
XX a\b 'a\b'
XX a\ b 'a b'
XX a\ b 'a ', 'b'
XX a\\b 'a\b'
....
However the most basic example does not work:
function! TestFunc(...)
echo a:0
echo a:000
endfunction
command! -nargs=? TestFunc call TestFunc(<f-args>)
-------------------------------------------------
> :TestFunc foo bar bla bla, fooo
> 1
> ['foo bar bla bla, fooo']
> :TestFunc foo\ bar
> 1
> ['foo\ bar']
I have a bunch of arguments split by whitespaces but vim sees it as one. Why does that happen?
Side question ( can it be somehow configured to actually split arguments at comma? )
You specified -nargs=?.
The documentation says:
-nargs=? 0 or 1 arguments are allowed
-nargs=1 Exactly one argument is required, it includes spaces
and
Arguments are considered to be separated by (unescaped) spaces or tabs in this
context, except when there is one argument, then the white space is part of
the argument.
(Emphasis mine.)
If you use -nargs=* instead, you get the normal behavior.
I read the docs, but got even more confused.
I have the following error generated by the compiler:
rot;
^
"cpp\c1.cpp", line 13: error(114): identifier
"rot" is undefined
1 error detected in the compilation of "c1.cpp".
I know how to detect the line where the error line is given, but I get loads of extra useless info in my errorlist, and the error message is split in two lines, whcih i would prefer to merge.
My starting errorformat is:
:set efm=\"%f\"\\,\ line\ %l:\ error(%n):\ %m
Since we are at it, is there a quick way of testing the efm without resorting to run make all the time?
First of all, I talk about debugging. Unfortunately, there's no particularly easy way of doing it, but one useful possibility is to run make and spit the output into a file and then:
:let &makeprg="cat ~/outputfile.log"
:make
Regarding making the errorformat, this does require a bit of trial and error. You can use %A, %C and %Z for multiline messages and you can use %-G to ignore stuff. The order is very important and note that sometimes the %C or even %Z come before the %A! In your case, you may be able to get somewhere with the efm below. I tend to use let &efm = and let &efm .= rather than set as you don't have to escape every space or quotation mark and you can build it up gradually. It's also much more readable.
" Start of the multi-line error message (%A),
" %p^ means a string of spaces and then a ^ to
" get the column number
let &efm = '%A%p^' . ','
" Next is the main bit: continuation of the error line (%C)
" followed by the filename in quotes, a comma (\,)
" then the rest of the details
let &efm .= '%C"%f"\, line %l: error(%n): %m' . ','
" Next is the last line of the error message, any number
" of spaces (' %#': equivalent to ' *') followed by a bit
" more error message
let &efm .= '%Z %#%m' . ','
" This just ignores any other lines (must be last!)
let &efm .= '%-G%.%#'