sponsor Vim development Vim logo Vim Book Ad

vim-loclist-follow : automated selection of location list item based on cursor position

 script karma  Rating 0/0, Downloaded by 866  Comments, bugs, improvements  Vim wiki

created by
Pete Beardmore
 
script type
utility
 
description
# summary
Use this plugin to enable automatic updating of the selected location list item based on the current cursor position. The item selected is determined by the target type which by default selects the nearest item. Both window local, and global 'quickfix' location lists are supported.

Tested against Syntastic and Ale setups with dozens of unique / split buffer windows opened (and their respective location list windows open (and closed) and populated) with no noticeable lag. Please report any issues.

# usage
To enable this plugin's functionality the global `g:loclist_follow` variable *must* be explicitly set either on/off, likely through an rc file entry e.g.:

    let g:loclist_follow = 1

Then there are two variables which control the ultimate on/off per buffer state of this functionality, namely `g:loclist_follow` and `b:loclist_follow`, and these can be toggled via commands `:LoclistFollowGlobalToggle` and `:LoclistFollowToggle` respectively.

When globally enabled, any opened/read buffers will have the appropriate hook installed on the `CursorMoved(I)` event(s) (this can be verified via `:autocmd loclist_follow`). The events correspond to *normal* and *insert* modes and both are hooked by default. The global `g:loclist_follow_modes` variable can be configured to modify this behaviour by setting any combination of the mode mappings `n -> normal` and `i -> insert` e.g.:

    let g:loclist_follow_modes = 'n'            "[default: 'ni']

When globally toggled, all buffers will be toggled unless they have been locally toggled off (via `:LoclistFollowToggle` / `let b:loclist_follow = 0`) - this buffer local variable state removes the buffer from the influence of global toggling. When globally disabled, locally enabling a buffer *will* enable the functionality locally and will not change the global state.

The global `g:loclist_follow_target` variable and its corresponding command for toggling `LoclistFollowTargetToggle` can be used to switch the target type between the following values:

- `nearest`  : targets the closest item to the cursor on a line basis
- `previous`  : targets the item under cursor, else the previous item in the list
- `next`  : targets the item under cursor, else the next item in the list
- `towards`  : targets the item under cursor, else the *next* item given the direction of your cursor movement
- `away`  : inverts the behaviour described for `towards`
- `last`  : where possible targets / retains the last *hit* item

# development

https://github.com/elbeardmorez/vim-loclist-follow
 
install details
# autoload

  $ cp plugin/vim-loclist-follow.vim ~/.vim/autoload/

# VimPlug

  Plug 'elbeardmorez/vim-loclist-follow'
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
vim-loclist-follow-0.4.0.tar.gz 0.4.0 2019-06-24 7.0 Pete Beardmore [add] 'last' target type
[fix] 'previous' target type extents
[add] quickfix list support
[mod] support heterogenous list items
vim-loclist-follow-0.3.0.tar.gz 0.3.0 2019-06-23 7.0 Pete Beardmore [add] dynamic target types
[add] loclist target type
[add] configurable hook events
vim-loclist-follow-0.2.0.tar.gz 0.2.0 2019-06-19 7.0 Pete Beardmore [mod] refactor automation
[add] 'LoclistFollowGlobalToggle'
vim-loclist-follow-0.1.1.tar.gz 0.1.1 2019-06-19 7.0 Pete Beardmore [fix] bufname path comparison
vim-loclist-follow-0.1.0.tar.gz 0.1.0 2019-06-19 7.0 Pete Beardmore initial release
ip used for rating: 3.129.19.251

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Vim at Github