Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim location-list: how to go to first location if at last location

Tags:

vim

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

like image 306
wangzq Avatar asked Nov 29 '14 03:11

wangzq


People also ask

How do I go back to previous location in Vim?

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.

What is Quick Fix list?

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.

How use quickfix window in Vim?

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.


1 Answers

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
like image 157
Peter Rincker Avatar answered Sep 28 '22 00:09

Peter Rincker