1

In Neovim I want to jump through Python traceback in the quickfix list.

To do that, I set the following option

:set errorformat+=%.%#File\ \"%f\"\\,\ line\ %l%.%#

and this works well.

What I would like now is to add this command in my init.lua, But when I add the previous line, neovim raises errors when I populate the quickfix List. This is my COMPLETE init.lua file:

vim.opt.errorformat:append { "%.%#File \"%f\"\\, line %l%.%#" }

With this config file, when I populate a quickfix list with a command:

:cex system('ls -al')

Neovim raises the following error:

E377: Invalid %- in format string

It seems neovim doesn't like the '%' character because when I set the following line vim.opt.errorformat:append('foo%f') in my init.lua, neovim raises the same error.

Do you know how to append a new string to errorformat?

edit: rephrased my message

7
  • I can't reproduce your problem with Neovim 0.9.5. Could you tell us what is the version of Neovim you are using (:version)? Commented Apr 5, 2024 at 12:57
  • Hello, I am using neovim v0.8.2. I will try with a newer version. Commented Apr 7, 2024 at 20:49
  • 1
    I tried with 0.9.5 and I still have this issue. Commented Apr 7, 2024 at 21:19
  • Thanks for the feedback. It seems we are stuck. I have tried different approach to reproduce the problem but I fail. Could you share a minimal init.lua file where the problem occurs? Commented Apr 8, 2024 at 8:52
  • Thank you for helping me. My config:(neovim 0.9.4) I deleted everything in ~/.local/share/nvim and in ~/.config/nvim. I created a simple init.lua with : vim.opt.errorformat:append { "%.%#File \"%f\"\\, line %l%.%#" } When I open nvim I execute the following command: :cex system('ls -al') When I press Enter, neovim prints: E377: Invalid %- in format string When I open quickfix list it is empty Of course, if I execute the same ex-command with nvim --noplugin --clean, the command works perfectly. Commented Apr 9, 2024 at 7:32

2 Answers 2

0

The conversion requires to know how how both call convert the string to the option:

set errorformat+=%.%#File\ \"%f\"\\,\ line\ %l%.%#

Set the errorformat to: %.%#File "%f"\, line %l%.%#

  • The needs to be escaped
  • The " needs to be escaped
  • The \ needs to be escaped

To set the errorformat to the same value in lua you have to do:

vim.opt.errorformat="%.%#File \"%f\"\\, line %l%.%#"
  • The " needs to be escaped
  • The \ needs to be escaped

For parsing Python stack I personally use:

set errorformat=%A\ %#File\ \"%f\"\\,\ line\ %l\\,\ in\ %o,%Z\ %#%m
5
  • 1
    Hello, Thank you. It's working, Unfortunately I don't want to set a new value to errorformat variable, I want to append a new value to errorformat. Commented Apr 15, 2024 at 7:20
  • I can't reproduce your problem :-/ Now I'm suspecting it is is because I don't have the same initial value. Maybe could you add it to the question? I'm also interested about why you want to append? What do you expect from the original value in this context? Commented Apr 15, 2024 at 8:16
  • Hello, What happens if you create a init.lua with only this line vim.opt.errorformat:append {"%.%#File \"%f\"\\, line %l%.%#"} and then you execute the following ex-command : :cex system('ls -al') ? Does neovim raise an error E377 ? Commented Apr 16, 2024 at 20:28
  • I run on Windows 10 so I can't reproduce the exact same setup. But if I use MSYS64 to get access to ls no, indeed, I can't reproduce your behavior :-| Commented Apr 17, 2024 at 6:46
  • 1
    Hi ! Thank you for your answers, Ok, I am not going further on this issue, I think I will use :compiler pyunit or just setting errorformat instead of appending errorformat Commented Apr 18, 2024 at 19:37
0

This is an unfixed bug in neovim, see https://github.com/neovim/neovim/issues/29061

The workaround is to keep it as vimscript for now as I understand it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.