5

I have a makefile that looks like:

default:
  lua blah.lua

Now, in Vim, I type ":make".

There's an error in my Lua code; it gives a file name + line number. I would like Vim to jump to the right file/line. How do I make this happen?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
anon
  • 41,035
  • 53
  • 197
  • 293

1 Answers1

7

You can set the error-format string to recognise the lua interpreter's output. For example, add this to your .vimrc file:

autocmd BufRead *.lua setlocal efm=%s:\ %f:%l:%m

That assumes the errors in your version of Lua look like this:

lua: blah.lua:2: '=' expected near 'var'

Bonus tip: rather than use a makefile, you can use the makeprg setting:

autocmd BufRead *.lua setlocal makeprg=lua\ %

That will run the current file through lua when you type :make.

richq
  • 55,548
  • 20
  • 150
  • 144
  • Nice. Thanks! I understand the %f:%l part. Care to explain how "%.%#" matches "lua" ? – anon May 05 '10 at 11:17
  • 1
    `%.%#` is the error format equivalent to a `.*` in a regular regex. IOW it matches anything at all (e.g. /usr/bin/lua). Bit of a hack maybe, but gets the job done! – richq May 05 '10 at 11:32
  • is there a way to make it say "lua: " instead of "%.%#" ? that seems more intuitive/clearer for me, but I don't know how to express taht in the error-format – anon May 05 '10 at 23:03
  • 1
    I've changed the %.%# thing to just %s, which matches any string (RTFM FTW!), but to hardcode it for just lua, you'd use `autocmd BufRead *.lua setlocal efm=lua:\ %f:%l:%m` – richq May 06 '10 at 07:40
  • @richq: Using %s instead of %.%# makes vim search for the captured string ("lua") instead of jumping to the line number. vimdoc says, "The "%s" conversion specifies the text to search for to locate the error line." Using `efm=%s:\ %f:%m` makes this more apparent because it shows the jump text in the line numbers spot. (vim 8.0.596 doesn't jump to the line number if that search text isn't found.) – idbrii May 17 '17 at 21:45