I have mapped gn
to :lnext<cr>
; how can I keep pressing it to cycle thru the location list, i.e. go to first if at last location?
Thanks
Vim makes it easy to navigate previous locations: Ctrl + o navigate to the previous location in the jump list (think o as old) Ctrl + i navigate to the next location in the jump list ( i and o are usually next to each other) g; go to the previous change location.
The quickfix and location lists provide a powerful way to navigate in Vim especially in the context of searching a file or project, and when inspecting errors. Essentially, they are lists of file locations with a built-in set of commands for navigating between them, and they can be populated in a variety of ways.
Open Vim in build directory and invoke make from within it using the command :make . This runs Make and fills up the Quickfix buffer with the error output. To open the Quickfix window, use the command :copen . In the screenshot above, the Quickfix window is visible at the bottom.
The secret is to use :try
and :catch
the same as you would in other languages. You are looking to catch the following errors E553
or E42
.
nnoremap ]l :try<bar>lnext<bar>catch /^Vim\%((\a\+)\)\=:E\%(553\<bar>42\):/<bar>lfirst<bar>endtry<cr>
The command was inspired by Tim Pope's unimpaired.vim plugin.
I would also recommend against mapping of gn
. The gn
command is very handy motion that actions on the search pattern. See :h gn
.
For more information see:
:h :try
:h E553
:h E42
:h :lnext
:h :lfirst
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With