Home

Awesome

QFEnter

QFEnter allows you to open items from Vim's quickfix or location list wherever you wish.

You can set a target window by giving it focus just before jumping to the quickfix (or location list) window , or you can open items in new splits, vsplits, and tabs. You can even open multiple items at once by visual selection!

A normal mode example: qfenter

A visual mode example: qfentervisualopt

Motivation

Vim's default means of opening items from the quickfix list are limited and inconvenient:

These are confusing and bothered me every time, so I wrote a simple plugin to make up for these weak points. Its name comes from the most basic way to open a file from the quickfix window -- the <Enter> key.

Installation

Usage

In the quickfix (or location list) window,

Key mapping

You can change the key mappings in your .vimrc in the following format:

let g:qfenter_keymap = {}
let g:qfenter_keymap.predefined_command = shortcut_key_list

The default setting is,

let g:qfenter_keymap = {}
let g:qfenter_keymap.open = ['<CR>', '<2-LeftMouse>']
let g:qfenter_keymap.vopen = ['<Leader><CR>']
let g:qfenter_keymap.hopen = ['<Leader><Space>']
let g:qfenter_keymap.topen = ['<Leader><Tab>']

If you're a CtrlP user, for instance, you might like these for familiarity:

let g:qfenter_keymap = {}
let g:qfenter_keymap.vopen = ['<C-v>']
let g:qfenter_keymap.hopen = ['<C-CR>', '<C-s>', '<C-x>']
let g:qfenter_keymap.topen = ['<C-t>']

Predefined commands

CommandsMeaning
openOpen items under cursor or in visual block in a previously focused window.
vopenOpen items under cursor or in visual block in new vertical splits from a previously focused window.
hopenOpen items under cursor or in visual block in new horizontal splits from a previously focused window.
topenOpen items under cursor or in visual block in new tabs.
cnextOpen items using :cnext command in a previously focused window.
vcnextOpen items using :cnext command in new vertical splits from a previously focused window.
hcnextOpen items using :cnext command in new horizontal splits from a previously focused window.
tcnextOpen items using :cnext command in new tabs.
cprevOpen items using :cprev command in a previously focused window.
vcprevOpen items using :cprev command in new vertical splits from a previously focused window.
hcprevOpen items using :cprev command in new horizontal splits from a previously focused window.
tcprevOpen items using :cprev command in new tabs.
open_keepSame as open, but the quickfix (or location list) window keeps focus after opening items.
vopen_keepSame as vopen, but the quickfix (or location list) window keeps focus after opening items.
hopen_keepSame as hopen, but the quickfix (or location list) window keeps focus after opening items.
topen_keepSame as topen, but the quickfix (or location list) window keeps focus after opening items.
cnext_keepSame as cnext, but the quickfix (or location list) window keeps focus after opening items.
vcnext_keepSame as vcnext, but the quickfix (or location list) window keeps focus after opening items.
hcnext_keepSame as hcnext, but the quickfix (or location list) window keeps focus after opening items.
tcnext_keepSame as tcnext, but the quickfix (or location list) window keeps focus after opening items.
cprev_keepSame as cprev, but the quickfix (or location list) window keeps focus after opening items.
vcprev_keepSame as vcprev, but the quickfix (or location list) window keeps focus after opening items.
hcprev_keepSame as hcprev, but the quickfix (or location list) window keeps focus after opening items.
tcprev_keepSame as tcprev, but the quickfix (or location list) window keeps focus after opening items.

For example, to open a next quickfix item in a previously focused window while keeping focus in the quickfix window by typing <Leader>n, you can use these:

let g:qfenter_keymap = {}
let g:qfenter_keymap.cnext_keep = ['<Leader>n']

Preventing opening items in windows of certain filetypes

Use g:qfenter_exclude_filetypes to prevent quickfix items from opening in windows of certain filetypes. For example, you can prevent opening items in NERDTree and Tagbar windows using the following code in your .vimrc:

let g:qfenter_exclude_filetypes = ['nerdtree', 'tagbar']

You can check filetype of the current window using :echo &filetype.

Policy to determine the previous window / tab

Use g:qfenter_prevtabwin_policy to determine which window on which tab should have focus when the wincmd p is executed after opening a quickfix item.

The default setting is,

let g:qfenter_prevtabwin_policy = 'qf'

Use of custom functions to specify a target window (for advanced users)

You can use your custom function, instead of the predefined commands, to specify the window to jump to.

For this, use g:qfenter_custom_map_list in your .vimrc. Each item in g:qfenter_custom_map_list should have four key-value pairs:

For example, with the following code in .vimrc,

let g:qfenter_custom_map_list = []
call add(g:qfenter_custom_map_list, {
			\'tabwinfunc': 'QFEnter#GetTabWinNR_Open',
			\'qfopencmd': 'cn',
			\'keepfocus': 1,
			\'keys': ['<Leader>n'],
			\})
call add(g:qfenter_custom_map_list, {
			\'tabwinfunc': 'TestTab1Win1_Open',
			\'qfopencmd': 'cc',
			\'keepfocus': 0,
			\'keys': ['<Leader>f'],
			\})
func! TestTab1Win1_Open()
	return [1, 1, 0, '']
endfunc
<!-- vim:set et sw=4 ts=4 tw=78: -->