├── .gitignore ├── README.md ├── autoload └── QFEnter.vim ├── doc └── QFEnter.txt └── plugin └── QFEnter.vim /.gitignore: -------------------------------------------------------------------------------- 1 | tags 2 | video/* 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # QFEnter 2 | 3 | QFEnter allows you to open items from Vim's quickfix or location list wherever you wish. 4 | 5 | You can set a target window by giving it focus just before jumping to the 6 | quickfix (or location list) window , or you can open items in new splits, vsplits, and tabs. 7 | You can even open multiple items at once by visual selection! 8 | 9 | A normal mode example: 10 | ![qfenter](https://f.cloud.github.com/assets/5915359/1632228/bb76dc72-5774-11e3-83d1-2933b95d5b81.gif) 11 | 12 | A visual mode example: 13 | ![qfentervisualopt](https://f.cloud.github.com/assets/5915359/2006385/61c6f720-8717-11e3-806b-d0f276af3ef9.gif) 14 | 15 | 16 | ## Motivation 17 | 18 | Vim's default means of opening items from the quickfix list are limited and 19 | inconvenient: 20 | 21 | - You cannot select a window in which to open a file when you press ``: 22 | 23 | > Hitting the \ key or double-clicking the mouse on a line has the 24 | > same effect. The file containing the error is opened **in the window above 25 | > the quickfix window**. 26 | > *-- from `:help quickfix`* 27 | 28 | It is inconsistent with other Quickfix commands like `:cnext` and `:cprev` 29 | which open a file in a previously focused window. 30 | 31 | - You cannot decide where a horizontal split will be created when using `Ctrl-W 32 | `, Vim always creates the new split window above the quickfix window. 33 | 34 | - There is no command at all for 'open in a new vertical split window'. 35 | 36 | These are confusing and bothered me every time, so I wrote a simple plugin to 37 | make up for these weak points. Its name comes from the most basic way to open 38 | a file from the quickfix window -- the `` key. 39 | 40 | 41 | ## Installation 42 | 43 | - Using plugin managers (recommended) 44 | - [Vundle] : Add `Plugin 'yssl/QFEnter'` to .vimrc & `:PluginInstall` 45 | - [NeoBundle] : Add `NeoBundle 'yssl/QFEnter'` to .vimrc & `:NeoBundleInstall` 46 | - [vim-plug] : Add `Plug 'yssl/QFEnter'` to .vimrc & `:PlugInstall` 47 | - Using [Pathogen] 48 | - `cd ~/.vim/bundle; git clone https://github.com/yssl/QFEnter.git` 49 | - Manual install (not recommended) 50 | - Download this plugin and extract it in `~/.vim/` 51 | 52 | ## Usage 53 | 54 | In the quickfix (or location list) window, 55 | 56 | * **\**, **\<2-LeftMouse\>** 57 | * *Normal mode* : Open an item under cursor in the previously focused window. 58 | * *Visual mode* : Open items in visual selection in the previously focused 59 | window. As a result, the last item appears in the window. 60 | 61 | * **\\** 62 | * *Normal mode* : Open an item under cursor in a new vertical split of the 63 | previously focused window. 64 | * *Visual mode* : Open items in visual selection in a sequence of new vertical 65 | splits from the previously focused window. 66 | 67 | * **\\** 68 | * *Normal mode* : Open an item under cursor in a new horizontal split from the 69 | previously focused window. 70 | * *Visual mode* : Open items in visual selection in a sequence of new horizontal 71 | splits of the previously focused window. 72 | 73 | * **\\** 74 | * *Normal mode* : Open an item under cursor in a new tab. 75 | * *Visual mode* : Open items in visual selection in a sequence of new tabs. 76 | * By default, the quickfix window is automatically opened in the 77 | new tab to help you open other quickfix items. This behavior 78 | can be changed with the `g:qfenter_enable_autoquickfix` option. 79 | 80 | ## Key mapping 81 | 82 | You can change the key mappings in your .vimrc in the following format: 83 | 84 | let g:qfenter_keymap = {} 85 | let g:qfenter_keymap.*predefined_command* = *shortcut_key_list* 86 | 87 | The default setting is, 88 | ```vim 89 | let g:qfenter_keymap = {} 90 | let g:qfenter_keymap.open = ['', '<2-LeftMouse>'] 91 | let g:qfenter_keymap.vopen = [''] 92 | let g:qfenter_keymap.hopen = [''] 93 | let g:qfenter_keymap.topen = [''] 94 | ``` 95 | 96 | If you're a [CtrlP] user, for instance, you might like these for familiarity: 97 | 98 | ```vim 99 | let g:qfenter_keymap = {} 100 | let g:qfenter_keymap.vopen = [''] 101 | let g:qfenter_keymap.hopen = ['', '', ''] 102 | let g:qfenter_keymap.topen = [''] 103 | ``` 104 | 105 | ## Predefined commands 106 | 107 | | Commands | Meaning | 108 | | -------------------------- | -------------------------| 109 | | **open** | Open items under cursor or in visual block in a previously focused window.| 110 | | **vopen** | Open items under cursor or in visual block in new vertical splits from a previously focused window.| 111 | | **hopen** | Open items under cursor or in visual block in new horizontal splits from a previously focused window.| 112 | | **topen** | Open items under cursor or in visual block in new tabs.| 113 | | | | 114 | | **cnext** | Open items using `:cnext` command in a previously focused window.| 115 | | **vcnext** | Open items using `:cnext` command in new vertical splits from a previously focused window.| 116 | | **hcnext** | Open items using `:cnext` command in new horizontal splits from a previously focused window.| 117 | | **tcnext** | Open items using `:cnext` command in new tabs.| 118 | | | | 119 | | **cprev** | Open items using `:cprev` command in a previously focused window.| 120 | | **vcprev** | Open items using `:cprev` command in new vertical splits from a previously focused window.| 121 | | **hcprev** | Open items using `:cprev` command in new horizontal splits from a previously focused window.| 122 | | **tcprev** | Open items using `:cprev` command in new tabs.| 123 | | | | 124 | | **open_keep** | Same as **open**, but the quickfix (or location list) window keeps focus after opening items.| 125 | | **vopen_keep** | Same as **vopen**, but the quickfix (or location list) window keeps focus after opening items.| 126 | | **hopen_keep** | Same as **hopen**, but the quickfix (or location list) window keeps focus after opening items.| 127 | | **topen_keep** | Same as **topen**, but the quickfix (or location list) window keeps focus after opening items.| 128 | | | | 129 | | **cnext_keep** | Same as **cnext**, but the quickfix (or location list) window keeps focus after opening items.| 130 | | **vcnext_keep** | Same as **vcnext**, but the quickfix (or location list) window keeps focus after opening items.| 131 | | **hcnext_keep** | Same as **hcnext**, but the quickfix (or location list) window keeps focus after opening items.| 132 | | **tcnext_keep** | Same as **tcnext**, but the quickfix (or location list) window keeps focus after opening items.| 133 | | | | 134 | | **cprev_keep** | Same as **cprev**, but the quickfix (or location list) window keeps focus after opening items.| 135 | | **vcprev_keep** | Same as **vcprev**, but the quickfix (or location list) window keeps focus after opening items.| 136 | | **hcprev_keep** | Same as **hcprev**, but the quickfix (or location list) window keeps focus after opening items.| 137 | | **tcprev_keep** | Same as **tcprev**, but the quickfix (or location list) window keeps focus after opening items.| 138 | 139 | For example, to open a next quickfix item in a previously focused window while keeping focus in the quickfix window by typing `n`, you can use these: 140 | ```vim 141 | let g:qfenter_keymap = {} 142 | let g:qfenter_keymap.cnext_keep = ['n'] 143 | ``` 144 | 145 | ## Preventing opening items in windows of certain filetypes 146 | 147 | Use `g:qfenter_exclude_filetypes` to prevent quickfix items from opening in windows of certain *filetypes*. 148 | For example, you can prevent opening items in NERDTree and Tagbar windows using the following code in your .vimrc: 149 | ```vim 150 | let g:qfenter_exclude_filetypes = ['nerdtree', 'tagbar'] 151 | ``` 152 | You can check *filetype* of the current window using `:echo &filetype`. 153 | 154 | ## Policy to determine the previous window / tab 155 | 156 | 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. 157 | 158 | * `'qf'`: The previous window and tab are set to the quickfix window from which the QFEnter open command is invoked and the tab the window belongs to. 159 | * `'none'`: Do nothing for the previous window and tab. The previous window is the window that previously had focus before the target window, in the process of `tabwinfunc`. 160 | * For `v*` and `h*` predefined commands, the previous window is the window focused before the quickfix window. 161 | * For `t*` predefined commands, the previous window and tab are the window focused before the quickfix window and the tab it belongs to. 162 | * `'legacy'`: The option for legacy behavior prior to QFEnter 2.4.1. 163 | * For `t*` predefined commands, follow the `'qf'` policy. 164 | * Otherwise, follow the `'none'` policy. 165 | 166 | The default setting is, 167 | ```vim 168 | let g:qfenter_prevtabwin_policy = 'qf' 169 | ``` 170 | 171 | ## Use of custom functions to specify a target window (for advanced users) 172 | 173 | You can use your custom function, instead of the predefined commands, 174 | to specify the window to jump to. 175 | 176 | For this, use `g:qfenter_custom_map_list` in your .vimrc. 177 | Each item in `g:qfenter_custom_map_list` should have four key-value pairs: 178 | 179 | * **tabwinfunc**: The name of your custom function to specify the target window, 180 | which should not have any parameters. 181 | Its return value should be a list of [*tabpagenr*, *winnr*, *hasfocus*, *isnewtabwin*]. 182 | * *tabpagenr*: tabpage number of the target window 183 | * *winnr*: window number of the target window 184 | * *hasfocus*: whether the target window already has focus or not 185 | * *isnewtabwin*: 186 | * `'nt'`: the target window is in a newly created tab 187 | * `'nw'`: the target window is a newly created window 188 | * otherwise: the target window is one of existing windows 189 | * **qfopencmd**: One of the following values 190 | * `'cc'`: Open a quickfix item using `:cc`. 191 | * `'cn'`: Open a quickfix item using `:cnext`. 192 | * `'cp'`: Open a quickfix item using `:cprev`. 193 | * **keepfocus**: `1` to keep focus in the quickfix (or location list) window after opening an item, otherwise `0`. 194 | * **keys**: shortcut key list 195 | 196 | For example, with the following code in .vimrc, 197 | * You can open a next quickfix item in a 198 | previously focused window while keeping focus in the quickfix window by typing `n` 199 | (identical effect to `let g:qfenter_keymap.cnext_keep = ['n']`). 200 | * You can open a quickfix item under cursor in the first window (`winnr`==1) in the first tab (`tabpagenr`==1) by typing `f`. 201 | 202 | ``` 203 | let g:qfenter_custom_map_list = [] 204 | call add(g:qfenter_custom_map_list, { 205 | \'tabwinfunc': 'QFEnter#GetTabWinNR_Open', 206 | \'qfopencmd': 'cn', 207 | \'keepfocus': 1, 208 | \'keys': ['n'], 209 | \}) 210 | call add(g:qfenter_custom_map_list, { 211 | \'tabwinfunc': 'TestTab1Win1_Open', 212 | \'qfopencmd': 'cc', 213 | \'keepfocus': 0, 214 | \'keys': ['f'], 215 | \}) 216 | func! TestTab1Win1_Open() 217 | return [1, 1, 0, ''] 218 | endfunc 219 | ``` 220 | 221 | [Vundle]: https://github.com/gmarik/Vundle.vim 222 | [NeoBundle]: https://github.com/Shougo/neobundle.vim 223 | [vim-plug]: https://github.com/junegunn/vim-plug 224 | [Pathogen]: https://github.com/tpope/vim-pathogen 225 | [CtrlP]: https://github.com/ctrlpvim/ctrlp.vim 226 | 227 | 228 | -------------------------------------------------------------------------------- /autoload/QFEnter.vim: -------------------------------------------------------------------------------- 1 | " File: autoload/QFEnter.vim 2 | " Description: Open a Quickfix item in a window you choose. 3 | " Author: yssl 4 | " License: MIT License 5 | 6 | " functions 7 | function! s:ExecuteCC(lnumqf, isloclist) 8 | if a:isloclist 9 | let cmd = g:qfenter_ll_cmd 10 | else 11 | let cmd = g:qfenter_cc_cmd 12 | endif 13 | let cc_cmd = substitute(cmd, '##', a:lnumqf, "") 14 | execute cc_cmd 15 | endfunction 16 | 17 | function! s:ExecuteCN(count, isloclist) 18 | if a:isloclist 19 | let cmd = g:qfenter_lne_cmd 20 | else 21 | let cmd = g:qfenter_cn_cmd 22 | endif 23 | try 24 | execute cmd 25 | catch /E553/ 26 | echo 'QFEnter: cnext: No more items' 27 | endtry 28 | endfunction 29 | 30 | function! s:ExecuteCP(count, isloclist) 31 | if a:isloclist 32 | let cmd = g:qfenter_lp_cmd 33 | else 34 | let cmd = g:qfenter_cp_cmd 35 | endif 36 | try 37 | execute cmd 38 | catch /E553/ 39 | echo 'QFEnter: cprev: No more items' 40 | endtry 41 | endfunction 42 | 43 | " GetTabWinNR* functions 44 | " return value: [tabpagenr, winnr, hasfocus, isnewtabwin] 45 | " tabpagenr: tabpage number of the target window 46 | " winnr: window number of the target window 47 | " hasfocus: whether the target window already has focus or not 48 | " isnewtabwin: 49 | " - 'nt': the target window is in a newly created tab 50 | " - 'nw': the target window is a newly created window 51 | " - otherwise: the target window is one of existing windows 52 | 53 | function! QFEnter#GetTabWinNR_Open() 54 | wincmd p 55 | return [tabpagenr(), winnr(), 1, ''] 56 | endfunction 57 | 58 | function! QFEnter#GetTabWinNR_VOpen() 59 | wincmd p 60 | vnew 61 | return [tabpagenr(), winnr(), 1, 'nw'] 62 | endfunction 63 | 64 | function! QFEnter#GetTabWinNR_HOpen() 65 | wincmd p 66 | new 67 | return [tabpagenr(), winnr(), 1, 'nw'] 68 | endfunction 69 | 70 | function! QFEnter#GetTabWinNR_TOpen() 71 | let s:qfview = winsaveview() 72 | 73 | let s:modifier = '' 74 | let widthratio = winwidth(0)*&lines 75 | let heightratio = winheight(0)*&columns 76 | if widthratio > heightratio 77 | let s:modifier = s:modifier.'' 78 | let s:qfresize = 'resize '.winheight(0) 79 | else 80 | let s:modifier = s:modifier.'vert' 81 | let s:qfresize = 'vert resize '.winwidth(0) 82 | endif 83 | 84 | if winnr() <= winnr('$')/2 85 | let s:modifier = s:modifier.' topleft' 86 | else 87 | let s:modifier = s:modifier.' botright' 88 | endif 89 | 90 | " add this line to match the behavior of VOpen() and HOpen() 91 | wincmd p 92 | 93 | tabnew 94 | 95 | return [tabpagenr(), winnr(), 1, 'nt'] 96 | endfunction 97 | 98 | "qfopencmd: 'cc', 'cn', 'cp' 99 | function! s:OpenQFItem(tabwinfunc, qfopencmd, qflnum) 100 | let lnumqf = a:qflnum 101 | 102 | if len(getloclist(0)) > 0 103 | let isloclist = 1 104 | else 105 | let isloclist = 0 106 | endif 107 | 108 | " for g:qfenter_prevtabwin_policy 109 | let prev_qf_tabnr = tabpagenr() 110 | let prev_qf_winnr = winnr() 111 | let orig_prev_qf_winnr = prev_qf_winnr 112 | 113 | " jump to a window or tab in which quickfix item to be opened 114 | exec 'let ret = '.a:tabwinfunc.'()' 115 | let target_tabnr = ret[0] 116 | let target_winnr = ret[1] 117 | let hasfocus = ret[2] 118 | let target_newtabwin = ret[3] 119 | if !hasfocus 120 | call s:JumpToTab(target_tabnr) 121 | call s:JumpToWin(target_winnr) 122 | endif 123 | 124 | if g:qfenter_prevtabwin_policy==#'qf' 125 | if target_newtabwin==#'nt' 126 | if prev_qf_tabnr >= target_tabnr 127 | let prev_qf_tabnr += 1 128 | endif 129 | call s:JumpToTab(prev_qf_tabnr) 130 | call s:JumpToWin(prev_qf_winnr) 131 | call s:JumpToTab(target_tabnr) 132 | else 133 | if target_newtabwin==#'nw' && prev_qf_winnr >= target_winnr 134 | let prev_qf_winnr += 1 135 | endif 136 | call s:JumpToWin(prev_qf_winnr) 137 | call s:JumpToWin(target_winnr) 138 | endif 139 | elseif g:qfenter_prevtabwin_policy==#'none' 140 | " do nothing 141 | elseif g:qfenter_prevtabwin_policy==#'legacy' 142 | if target_newtabwin==#'nt' 143 | if prev_qf_tabnr >= target_tabnr 144 | let prev_qf_tabnr += 1 145 | endif 146 | call s:JumpToTab(prev_qf_tabnr) 147 | call s:JumpToWin(prev_qf_winnr) 148 | call s:JumpToTab(target_tabnr) 149 | endif 150 | else 151 | echoerr 'QFEnter: '''.g:qfenter_prevtabwin_policy.''' is an undefined value for g:qfenter_prevtabwin_policy.' 152 | call s:JumpToTab(prev_qf_tabnr) 153 | call s:JumpToWin(prev_qf_winnr) 154 | return 155 | endif 156 | 157 | if g:qfenter_excluded_action==#'next' 158 | " if the selected window contains an excluded filetype, move to next usable window if possible 159 | let c = 0 160 | let wincount = winnr('$') 161 | while ( index(g:qfenter_exclude_filetypes, &filetype) >= 0 && c < wincount ) 162 | wincmd w 163 | let c = c + 1 164 | endwhile 165 | elseif g:qfenter_excluded_action==#'error' 166 | " if the selected window contains an excluded filetype, show an error message and do not open the file. 167 | if index(g:qfenter_exclude_filetypes, &filetype) >= 0 168 | echo "QFEnter: Quickfix items cannot be opened in a '".&filetype."' window" 169 | wincmd p 170 | return 171 | endif 172 | else 173 | echoerr 'QFEnter: '''.g:qfenter_excluded_action.''' is an undefined value for g:qfenter_excluded_action.' 174 | call s:JumpToTab(prev_qf_tabnr) 175 | call s:JumpToWin(prev_qf_winnr) 176 | return 177 | endif 178 | 179 | " execute vim quickfix open commands 180 | if a:qfopencmd==#'cc' 181 | call s:ExecuteCC(lnumqf, isloclist) 182 | elseif a:qfopencmd==#'cn' 183 | call s:ExecuteCN(lnumqf, isloclist) 184 | elseif a:qfopencmd==#'cp' 185 | call s:ExecuteCP(lnumqf, isloclist) 186 | endif 187 | 188 | " check if switchbuf applied. 189 | " if useopen or usetab are applied with new window or tab command, close 190 | " the newly opened tab or window. 191 | let qfopened_tabnr = tabpagenr() 192 | let qfopened_winnr = winnr() 193 | if (match(&switchbuf,'useopen')>-1 || match(&switchbuf,'usetab')>-1) 194 | if target_newtabwin==#'nt' 195 | if target_tabnr!=qfopened_tabnr 196 | call s:JumpToTab(target_tabnr) 197 | call s:CloseCurrentTabAndJumpTo(qfopened_tabnr) 198 | endif 199 | elseif target_newtabwin==#'nw' 200 | if target_tabnr!=qfopened_tabnr |"when 'usetab' applied 201 | call s:JumpToTab(target_tabnr) 202 | 203 | " Close The empty, newly created target window and jump to the quickfix window. 204 | " When returning from the tab containing the selecte item window to original tab, 205 | if g:qfenter_prevtabwin_policy==#'qf' || g:qfenter_prevtabwin_policy==#'leagcy' 206 | " the quickfix window should have a focus. 207 | call s:CloseCurrentWinAndJumpTo(prev_qf_winnr) 208 | else 209 | " the original 'wincmd p' window of quickfix should have a focus. 210 | " Just 'quit' makes the right or bottom window of the window close which has been newly created, 211 | " ti works correctly. 212 | quit 213 | endif 214 | 215 | call s:JumpToTab(qfopened_tabnr) 216 | 217 | elseif target_winnr!=qfopened_winnr 218 | call s:JumpToWin(target_winnr) 219 | call s:CloseCurrentWinAndJumpTo(qfopened_winnr) 220 | 221 | " To set quickfix window as a prevous window. 222 | " 223 | " Let's say we have opened an item with some 'nw' command which had already opened in a window A. 224 | " During the opening process, a new window N is created and 'cc' (or other) command 225 | " make the focus jump to A due to the switchbuf option. So window history is quickfix Q - N - A. 226 | " Then N is closed. So it should be Q - A, meaning that 'wincmd p' in A make a jump to Q. 227 | " BUT the default behavior of vim is not like this. 'wincmd p' in A just stays in A. 228 | " This code reconnects Q and A in terms of prev win history. 229 | " 230 | " Note that checking if g:qfenter_prevtabwin_policy==#'qf' in not necessary 231 | " beause the prev window still should be the quickfix window even if the option is 'none' 232 | " becuase not a new window but one of existing windows is focused. 233 | call s:JumpToWin(orig_prev_qf_winnr) 234 | wincmd p 235 | endif 236 | " if the target window is one of existing windows, do nothing 237 | " because the target window had focused and qfopencmd (such as cc) has moved the focus 238 | " to the right window, so there are no remaining artifacts. 239 | endif 240 | endif 241 | 242 | " restore quickfix window when tab mode 243 | if target_newtabwin==#'nt' 244 | if exists('g:qfenter_enable_autoquickfix') 245 | echom "QFEnter: 'g:qfenter_enable_autoquickfix' is deprecated and will be removed from 2.5.0. Now the default setting of the new option g:qfenter_autoclose=0 will open a quickfix in a new tab (if g:qfenter_enable_autoquickfix is not 0 before 2.5.0). Please refer :help g:qfenter_autoclose." 246 | if g:qfenter_enable_autoquickfix 247 | if isloclist 248 | exec s:modifier 'lopen' 249 | else 250 | exec s:modifier 'copen' 251 | endif 252 | exec s:qfresize 253 | call winrestview(s:qfview) 254 | wincmd p 255 | endif 256 | else 257 | if !g:qfenter_autoclose 258 | if isloclist 259 | exec s:modifier 'lopen' 260 | else 261 | exec s:modifier 'copen' 262 | endif 263 | exec s:qfresize 264 | call winrestview(s:qfview) 265 | wincmd p 266 | endif 267 | endif 268 | endif 269 | endfunction 270 | 271 | function! QFEnter#OpenQFItem(tabwinfunc, qfopencmd, keepfocus, isvisual) 272 | let qfbufnr = bufnr('%') 273 | let qflnum = line('.') 274 | 275 | if a:isvisual 276 | let vblnum2 = getpos("'>")[1] 277 | endif 278 | 279 | call s:OpenQFItem(a:tabwinfunc, a:qfopencmd, qflnum) 280 | 281 | " keepfocus 282 | if a:isvisual 283 | if qflnum==vblnum2 284 | if a:keepfocus 285 | redraw 286 | let qfwinnr = bufwinnr(qfbufnr) 287 | exec qfwinnr.'wincmd w' 288 | endif 289 | else 290 | let qfwinnr = bufwinnr(qfbufnr) 291 | exec qfwinnr.'wincmd w' 292 | endif 293 | else 294 | if a:keepfocus 295 | redraw 296 | let qfwinnr = bufwinnr(qfbufnr) 297 | exec qfwinnr.'wincmd w' 298 | endif 299 | endif 300 | 301 | " g:qfenter_autoclose 302 | if len(getloclist(0)) > 0 303 | let isloclist = 1 304 | else 305 | let isloclist = 0 306 | endif 307 | if g:qfenter_autoclose 308 | if isloclist 309 | lclose 310 | else 311 | cclose 312 | endif 313 | endif 314 | 315 | endfunction 316 | 317 | fun! s:CloseCurrentWinAndJumpTo(return_winnr) 318 | let prevwinnr = a:return_winnr 319 | if prevwinnr > winnr() 320 | let prevwinnr = prevwinnr - 1 321 | endif 322 | 323 | quit 324 | 325 | call s:JumpToWin(prevwinnr) 326 | endfun 327 | 328 | fun! s:JumpToWin(winnum) 329 | silent! exec a:winnum.'wincmd w' 330 | endfun 331 | 332 | fun! s:CloseCurrentTabAndJumpTo(return_tabnr) 333 | let prevtabnr = a:return_tabnr 334 | if prevtabnr > tabpagenr() 335 | let prevtabnr = prevtabnr - 1 336 | endif 337 | 338 | tabclose 339 | 340 | call s:JumpToTab(prevtabnr) 341 | endfun 342 | 343 | fun! s:JumpToTab(tabnum) 344 | exec 'tabnext' a:tabnum 345 | endfun 346 | 347 | " vim:set noet sw=4 sts=4 ts=4 tw=78: 348 | -------------------------------------------------------------------------------- /doc/QFEnter.txt: -------------------------------------------------------------------------------- 1 | *QFEnter.txt* Open a Quickfix item in a window you choose. 2 | *QFEnter* 3 | 4 | Author: yssl 5 | 6 | ============================================================================== 7 | Contents *QFEnter-contents* 8 | 9 | 1. Introduction ............................... |QFEnter-intro| 10 | 2. Usage ...................................... |QFEnter-usage| 11 | 3. Options .................................... |QFEnter-options| 12 | 4. |switchbuf| option ......................... |QFEnter-switchbuf| 13 | 5. Deprecated Commands & Options .............. |QFEnter-deprecated| 14 | 6. Changelog .................................. |QFEnter-changelog| 15 | 16 | ============================================================================== 17 | 1. Introduction *QFEnter-intro* 18 | 19 | QFEnter allows you to open items from the |quickfix| or location list wherever you wish. 20 | 21 | You can set a target window by giving it focus just before jumping to the 22 | |quickfix| (or location list) window, or you can open items in new splits, vsplits, and tabs. 23 | You can even open multiple items at once by visual selection! 24 | 25 | Vim's default means of opening items from the |quickfix| list are limited and 26 | inconvenient: 27 | 28 | - You cannot select a window in which to open a file when you press : 29 | > 30 | Hitting the key or double-clicking the mouse on a line has the 31 | same effect. The file containing the error is opened *in the window 32 | above the quickfix window*. 33 | -- from :help quickfix 34 | < 35 | - It is inconsistent with other |quickfix| commands like |:cnext| and |:cprev| 36 | which open a file in a previously focused window. 37 | 38 | - You cannot decide where a horizontal split will be created when using 39 | |CTRL-W_|, Vim always creates the new split window above the 40 | |quickfix| window. 41 | 42 | - There is no command at all for 'open in a new vertical split window'. 43 | 44 | These are confusing and bothered me every time, so I wrote a simple plugin to 45 | make up for these weak points. Its name comes from the most basic way to open 46 | a file from the |quickfix| window -- the key. 47 | 48 | ============================================================================== 49 | 2. Usage *QFEnter-usage* 50 | 51 | In the quickfix (or location list) window, 52 | 53 | , <2-LeftMouse> (open) 54 | Normal mode : Open an item under cursor in the previously focused window. 55 | Visual mode : Open items in visual selection in the previously focused window. 56 | As a result, the last item appears in the window. 57 | 58 | (vopen) 59 | Normal mode : Open an item under cursor in a new vertical split of the 60 | previously focused window. 61 | Visual mode : Open items in visual selection in a sequence of new vertical 62 | splits from the previously focused window. 63 | 64 | (hopen) 65 | Normal mode : Open an item under cursor in a new horizontal split from the 66 | previously focused window. 67 | Visual mode : Open items in visual selection in a sequence of new horizontal 68 | splits of the previously focused window. 69 | 70 | (topen) 71 | Normal mode : Open an item under cursor in a new tab. 72 | Visual mode : Open items in visual selection in a sequence of new tabs. 73 | By default, the |quickfix| window is automatically opened in the 74 | new tab to help you open other Quickfix items. This behavior 75 | can be changed with the |g:qfenter_enable_autoquickfix| option. 76 | 77 | You can change these key mappings in your .vimrc (see |QFEnter-options|). 78 | 79 | ============================================================================== 80 | 3. Options *QFEnter-options* 81 | 82 | |QFEnter| mappings are enabled only in |quickfix| (or location list) window. 83 | 84 | *g:qfenter_keymap* 85 | Customizable key mapping table for all 24 item-opening cases. 86 | It is a vimscript dictionary which has 'command' (as key) and 'key list' 87 | (as value) pairs. 88 | 89 | Default: > 90 | let g:qfenter_keymap.open = ['', '<2-LeftMouse>'] 91 | let g:qfenter_keymap.vopen = [''] 92 | let g:qfenter_keymap.hopen = [''] 93 | let g:qfenter_keymap.topen = [''] 94 | < 95 | Predefined commands are: 96 | 97 | 'open': Open items under cursor or in visual block in a previously focused window. 98 | 'vopen': Open items under cursor or in visual block in new vertical splits from a previously focused window. 99 | 'hopen': Open items under cursor or in visual block in new horizontal splits from a previously focused window. 100 | 'topen': Open items under cursor or in visual block in new tabs. 101 | 102 | 'cnext': Open items using |:cnext| command in a previously focused window. 103 | 'vcnext': Open items using |:cnext| command in new vertical splits from a previously focused window. 104 | 'hcnext': Open items using |:cnext| command in new horizontal splits from a previously focused window. 105 | 'tcnext': Open items using |:cnext| command in new tabs. 106 | 107 | 'cprev': Open items using |:cprev| command in a previously focused window. 108 | 'vcprev': Open items using |:cprev| command in new vertical splits from a previously focused window. 109 | 'hcprev': Open items using |:cprev| command in new horizontal splits from a previously focused window. 110 | 'tcprev': Open items using |:cprev| command in new tabs. 111 | 112 | 'open_keep': Same as 'open', but the quickfix (or location list) window keeps focus after opening items. 113 | 'vopen_keep': Same as 'vopen', but the quickfix (or location list) window keeps focus after opening items. 114 | 'hopen_keep': Same as 'hopen', but the quickfix (or location list) window keeps focus after opening items. 115 | 'topen_keep': Same as 'topen', but the quickfix (or location list) window keeps focus after opening items. 116 | 117 | 'cnext_keep': Same as 'cnext', but the quickfix (or location list) window keeps focus after opening items. 118 | 'vcnext_keep': Same as 'vcnext', but the quickfix (or location list) window keeps focus after opening items. 119 | 'hcnext_keep': Same as 'hcnext', but the quickfix (or location list) window keeps focus after opening items. 120 | 'tcnext_keep': Same as 'tcnext', but the quickfix (or location list) window keeps focus after opening items. 121 | 122 | 'cprev_keep': Same as 'cprev', but the quickfix (or location list) window keeps focus after opening items. 123 | 'vcprev_keep': Same as 'vcprev', but the quickfix (or location list) window keeps focus after opening items. 124 | 'hcprev_keep': Same as 'hcprev', but the quickfix (or location list) window keeps focus after opening items. 125 | 'tcprev_keep': Same as 'tcprev', but the quickfix (or location list) window keeps focus after opening items. 126 | 127 | Note that |g:qfenter_keymap| should be defined as an empty dictionary 128 | in your .vimrc to customize key mappings. > 129 | let g:qfenter_keymap = {} 130 | < 131 | For example, to open a next quickfix item in a previously focused window while keeping focus in the quickfix window by typing a, you can use these: > 132 | let g:qfenter_keymap = {} 133 | let g:qfenter_keymap.cnext_keep = ['a'] 134 | < 135 | 136 | *g:qfenter_autoclose* 137 | Enable or disable automatic closing of a quickfix window after opening an item. 138 | when 'open in a new tab' command is executed, if this option disabled, 139 | a quickfix window is automatically opened in the new tab with its 140 | original size, view and position to help you open other quickfix items. 141 | (not correctly, but smartly determined) 142 | Default: > 143 | let g:qfenter_autoclose = 0 144 | < 145 | 146 | *g:qfenter_exclude_filetypes* 147 | Use this option to prevent quickfix items from opening in windows of certain filetypes. 148 | Default: > 149 | let g:qfenter_exclude_filetypes = [] 150 | < 151 | For example, you can prevent opening items in NERDTree and Tagbar windows using the following code in your .vimrc: > 152 | let g:qfenter_exclude_filetypes = ['nerdtree', 'tagbar'] 153 | < 154 | You can check *filetype* of the current window using `:echo &filetype`. 155 | 156 | 157 | *g:qfenter_excluded_action* 158 | Action to take when selected window contains an excluded filetype. 159 | 160 | * 'next': Open the file in the next usable window, otherwise fall back to quickfix default (split above) 161 | * 'error': Show an error message and do not open the file. This is an option for legacy behavior prior to QFEnter 2.4.2. 162 | 163 | Default: > 164 | let g:qfenter_excluded_action = 'next' 165 | 166 | 167 | *g:qfenter_prevtabwin_policy* 168 | This option determines which window on which tab should have focus when the `wincmd p` is executed after opening a quickfix item. 169 | 170 | * 'qf': The previous window and tab are set to the quickfix window from which the QFEnter open command is invoked and the tab the window belongs to. 171 | * 'none': Do nothing for the previous window and tab. 172 | The previous window is the window that previously had focus before the target window, in the process of `tabwinfunc`. 173 | For `v*` and `h*` predefined commands, the previous window is the window focused before the quickfix window. 174 | For `t*` predefined commands, the previous window and tab are the window focused before the quickfix window and the tab it belongs to. 175 | * 'legacy': The option for legacy behavior prior to QFEnter 2.4.1. 176 | For `t*` predefined commands, follow the 'qf' policy. 177 | Otherwise, follow the 'none' policy. 178 | 179 | Default: > 180 | let g:qfenter_prevtabwin_policy = 'qf' 181 | < 182 | 183 | *g:qfenter_custom_map_list* 184 | An optional list of custom action mappings to use your 185 | custom functions to specify the window to jump to. 186 | Default: > 187 | let g:qfenter_custom_map_list = [] 188 | < 189 | Each item in |g:qfenter_custom_map_list| should have four key-value pairs: 190 | 191 | * 'tabwinfunc': The name of your custom function to specify the target window, 192 | which should not have any parameters. 193 | Its return value should be a list of ['tabpagenr', 'winnr', 'hasfocus', 'isnewtabwin']. 194 | *'tabpagenr': tabpage number of the target window 195 | * 'winnr': window number of the target window 196 | * 'hasfocus': whether the target window already has focus or not 197 | * 'isnewtabwin': 198 | * `'nt'`: the target window is in a newly created tab 199 | * `'nw'`: the target window is a newly created window 200 | * otherwise: the target window is one of existing windows 201 | * 'qfopencmd': One of the following values 202 | * `'cc'`: Open a quickfix item using `:cc`. 203 | * `'cn'`: Open a quickfix item using `:cnext`. 204 | * `'cp'`: Open a quickfix item using `:cprev`. 205 | * 'keepfocus': `1` to keep focus in the quickfix (or location list) window after opening an item, otherwise `0`. 206 | * 'keys': shortcut key list 207 | 208 | For example, with the following code in .vimrc, 209 | * You can open a next quickfix item in a 210 | previously focused window while keeping focus in the quickfix window by typing `n` 211 | (identical effect to `let g:qfenter_keymap.cnext_keep = ['n']`). 212 | 213 | * You can open a quickfix item under cursor in the first window (winnr==1) in the first tab (tabnr==1). 214 | > 215 | let g:qfenter_custom_map_list = [] 216 | call add(g:qfenter_custom_map_list, { 217 | \'tabwinfunc': 'QFEnter#GetTabWinNR_Open', 218 | \'qfopencmd': 'cn', 219 | \'keepfocus': 1, 220 | \'keys': ['n'], 221 | \}) 222 | call add(g:qfenter_custom_map_list, { 223 | \'tabwinfunc': 'TestTab1Win1_Open', 224 | \'qfopencmd': 'cc', 225 | \'keepfocus': 0, 226 | \'keys': ['t'], 227 | \}) 228 | func! TestTab1Win1_Open() 229 | return [1, 1, 0, ''] 230 | endfunc 231 | < 232 | 233 | *g:qfenter_cc_cmd* 234 | *g:qfenter_ll_cmd* 235 | QFEnter internally uses |:cc| (or |:ll| for the location list) command 236 | to open an item under cursor. 237 | If you're using your custom "cc" (or "ll") command instead of vim's 238 | default |:cc| (or |:ll|), you can register it by setting this option 239 | and make QFEnter use it. 240 | The option should have "##" which is converted to the line number later. 241 | Default: > 242 | let g:qfenter_cc_cmd = '##cc' 243 | let g:qfenter_ll_cmd = '##ll' 244 | < 245 | 246 | *g:qfenter_cn_cmd* 247 | *g:qfenter_lne_cmd* 248 | *g:qfenter_cp_cmd* 249 | *g:qfenter_lp_cmd* 250 | If you're using your custom "cn" or "cp" command instead of vim's default 251 | |:cn| or |:cp| (or the equivalent for the location list, |:lne| or |:lp|), you 252 | can register them by setting these options. 253 | Default: > 254 | let g:qfenter_cn_cmd = 'cn' 255 | let g:qfenter_cp_cmd = 'cp' 256 | let g:qfenter_lne_cmd = 'lne' 257 | let g:qfenter_lp_cmd = 'lp' 258 | < 259 | 260 | ============================================================================== 261 | 4. |switchbuf| option *QFEnter-switchbuf* 262 | 263 | You can control QFEnter's behavior with vim's |switchbuf| option when opening 264 | an item. When each opening command is invoked, QFEnter checks |switchbuf| 265 | option and adjusts its behavior. |switchbuf| option can have five values; 266 | (none), useopen, usetab, split, newtab. 267 | 268 | For example, you can set the option in your .vimrc as following: 269 | > 270 | set switchbuf=useopen 271 | < 272 | The default value is (none), meaning that: 273 | > 274 | set switchbuf= 275 | < 276 | If there is no already opened window of the buffer for the item you selected, 277 | QFEnter opens the item with its default behavior as described in 278 | |QFEnter-usage|. 279 | 280 | Otherwise, |switchbuf| option choose the window to open the item in. 281 | You can refer :help switchbuf for more details. 282 | 283 | ============================================================================== 284 | 5. Deprecated Commands & Options *QFEnter-deprecated* 285 | 286 | These options are deprecated since version 2.4.3 and are supposed to be removed 287 | in version 2.5.0. 288 | 289 | *g:qfenter_enable_autoquickfix* 290 | Enable or disable automatic opening of quickfix window when 'open in a new 291 | tab' command is executed. 292 | If enabled, quickfix window is automatically opened in the new tab with its 293 | original size, view and position to help you open other quickfix items. 294 | (not correctly, but smartly determined) 295 | Default: > 296 | let g:qfenter_enable_autoquickfix = 1 297 | < 298 | : Use |g:qfenter_autoclose| instead. 299 | 300 | 301 | ============================================================================== 302 | 6. Changelog *QFEnter-changelog* 303 | 304 | 2.4.3 2022/10/16 305 | - Add a new option g:qfenter_autoclose and deprecate g:qfenter_enable_autoquickfix 306 | Thanks for the suggestion auto-close quickfix, minhduc0711! 307 | 308 | 2.4.2 2022/10/15 309 | - Change the default value of g:qfenter_excluded_action to 'next' 310 | - Fix the behavior in the case of undefined g:qfenter_excluded_action and g:qfenter_prevtabwin_policy 311 | - Add option to use next window when excluded. Thanks for the PR, mmrwoods! 312 | - Fix g:qfenter_prevtabwin_policy behavior when switchbuf=usetab or useopen is used 313 | and fix a bug with 'open' cmds. Thanks for the suggestions, Konfekt! 314 | - Fix prevtabwin_policy tag name in doc. Thanks for the PR, tssm! 315 | 316 | 2.4.1 2020/10/07 317 | - Add an option for the policy to determine the previous window / tab' 318 | g:qfenter_custom_map_list. Thanks for the suggestions, Konfekt and mckellyln! 319 | 320 | 2.4.0 2020/10/05 321 | - Remove the deprecated commands from 2.3.0: g:qfenter_*_map, 322 | g:qfenter_keep_quickfixfocus 323 | - Support custom functions to specify target window through 324 | g:qfenter_custom_map_list. Thanks for the suggestion, p0deje! 325 | - Add an option to prevent quickfix items from opening in windows 326 | of certain filetypes. Thanks for the suggestion, lsaint! 327 | - Fix typo `filetype` to `FileType`. Thanks for the PR, dragonxlwang! 328 | - Fix always open quickfix window when 'open in a new tab' command 329 | is executed inside the location list. Thanks for the PR, QMonkey! 330 | 331 | 2.3.1 2017/03/04 332 | - Bug fix for deprecated variable(g:qfenter_keep_quickfixfocus) checking. 333 | Thanks for the report, Leandro! 334 | - Update documents for customization. 335 | 336 | 2.3.0 2017/02/28 337 | - Key mapping setup has totally changed for more flexible customizing. 338 | Thanks for the suggestion, qsvui! 339 | - Include handling for :lne and :lp. Thanks for the PR, mMontu! 340 | 341 | 2.2.2 2015/05/26 342 | - Avoid messages when mappings are executed. Thanks for the PR, mMontu! 343 | - Catch E553 of cn & cp commands 344 | - Modelines, clean up vimdoc formatting and edit text. Thanks to the PR, ches! 345 | - Support location list. Thanks to the PR, feix760! 346 | 347 | 2.2.1 2014/03/17 348 | - Update the document for 'switchbuf' option. 349 | 350 | 2.2.0 2014/03/17 351 | - Now QFEnter supports vim's 'switchbuf' option. 352 | if you change 'switchbuf' option, QFEnter adapts its behavior to the 353 | changed option. Thanks to the suggestion, sergey-vlasov! 354 | 355 | 2.1.0 2014/01/28 356 | - Subdivide g:qfenter_keep_quickfixfocus option for each command. e.g. 357 | g:qfenter_keep_quickfixfocus.open, g:qfenter_keep_quickfixfocus.cnext, 358 | g:qfenter_keep_quickfixfocus.cprev 359 | - Bug fix : not updated window for already opened file when 360 | g:qfenter_keep_quickfixfocus==1 361 | - Thanks for the suggestions, mMontu! 362 | 363 | 2.0.0 2014/01/27 364 | - Visual mode support to open multiple Quickfix items at once 365 | - Add option to keep focus in Quicifix window after opening items 366 | (g:qfenter_keep_quickfixfocus) 367 | - Support :cnext and :cprev command to open items 368 | 369 | 1.3.0 2013/12/10 370 | - Improve auto quickfix open when 'open in new tab' 371 | - Restore view(cursor position, scroll..) of quickfix window to 372 | auto-opened quickfix window 373 | - Restore size of quickfix window to auto-opened quickfix window 374 | - Now you don't need to provide g:qfenter_copen_modifier option. 375 | QFEnter now smartly determine whether the new quickfix window is 376 | botright or topleft, vertical or horizontal. 377 | - Change g:qfenter_ttopen_map option name to g:qfenter_topen_map (backward 378 | compatibility ismaintained) 379 | - Remove '' from default mapping 380 | 381 | 1.2.0 2013/12/08 382 | - Now, Quickfix window is automatically opened after "open in a new tab" 383 | - Add options about Quickfix auto opening 384 | - Add one more default mapping for "open in a new tab" 385 | - Code refactoring 386 | 387 | 1.1.1 2013/12/06 388 | - Change default mapping for "open a file in a new tab" 389 | 390 | 1.1.0 2013/12/06 391 | - Add new features 392 | : open a file under cursor in a new tab. 393 | : register custom "cc" command with g:qfenter_cc_cmd 394 | 395 | 1.0.0 2013/11/24 396 | - First version 397 | 398 | vim: tw=78 ts=8 sts=4 tw=4 et ft=help norl: 399 | -------------------------------------------------------------------------------- /plugin/QFEnter.vim: -------------------------------------------------------------------------------- 1 | " File: plugin/QFEnter.vim 2 | " Description: Open a Quickfix item in a window you choose. 3 | " Author: yssl 4 | " License: MIT License 5 | 6 | if exists("g:loaded_qfenter") || &cp 7 | finish 8 | endif 9 | let g:loaded_qfenter = 1 10 | let s:keepcpo = &cpo 11 | set cpo&vim 12 | """"""""""""""""""""""""""""""""""""""""""""" 13 | 14 | " static variables 15 | 16 | " cmd-action map (key-value pairs) 17 | " value[0]: tabwinfunc (such as QFEnter#GetTabWinNR_Open()) 18 | " value[1]: qfopencmd (cc,cn, or cp) 19 | " value[2]: keepfocus (0-do not keep focus, 1-keep focus) 20 | let s:cmd_action_map = { 21 | \'open': ['QFEnter#GetTabWinNR_Open', 'cc', 0], 22 | \'vopen': ['QFEnter#GetTabWinNR_VOpen', 'cc', 0], 23 | \'hopen': ['QFEnter#GetTabWinNR_HOpen', 'cc', 0], 24 | \'topen': ['QFEnter#GetTabWinNR_TOpen', 'cc', 0], 25 | \'cnext': ['QFEnter#GetTabWinNR_Open', 'cn', 0], 26 | \'vcnext': ['QFEnter#GetTabWinNR_VOpen', 'cn', 0], 27 | \'hcnext': ['QFEnter#GetTabWinNR_HOpen', 'cn', 0], 28 | \'tcnext': ['QFEnter#GetTabWinNR_TOpen', 'cn', 0], 29 | \'cprev': ['QFEnter#GetTabWinNR_Open', 'cp', 0], 30 | \'vcprev': ['QFEnter#GetTabWinNR_VOpen', 'cp', 0], 31 | \'hcprev': ['QFEnter#GetTabWinNR_HOpen', 'cp', 0], 32 | \'tcprev': ['QFEnter#GetTabWinNR_TOpen', 'cp', 0], 33 | \'open_keep': ['QFEnter#GetTabWinNR_Open', 'cc', 1], 34 | \'vopen_keep': ['QFEnter#GetTabWinNR_VOpen', 'cc', 1], 35 | \'hopen_keep': ['QFEnter#GetTabWinNR_HOpen', 'cc', 1], 36 | \'topen_keep': ['QFEnter#GetTabWinNR_TOpen', 'cc', 1], 37 | \'cnext_keep': ['QFEnter#GetTabWinNR_Open', 'cn', 1], 38 | \'vcnext_keep': ['QFEnter#GetTabWinNR_VOpen', 'cn', 1], 39 | \'hcnext_keep': ['QFEnter#GetTabWinNR_HOpen', 'cn', 1], 40 | \'tcnext_keep': ['QFEnter#GetTabWinNR_TOpen', 'cn', 1], 41 | \'cprev_keep': ['QFEnter#GetTabWinNR_Open', 'cp', 1], 42 | \'vcprev_keep': ['QFEnter#GetTabWinNR_VOpen', 'cp', 1], 43 | \'hcprev_keep': ['QFEnter#GetTabWinNR_HOpen', 'cp', 1], 44 | \'tcprev_keep': ['QFEnter#GetTabWinNR_TOpen', 'cp', 1], 45 | \} 46 | 47 | " global variables 48 | 49 | " g:qfenter_keymap - cmd-keylist map 50 | " default key mappings are assigned for open, vopen, hopen, topen 51 | if !exists('g:qfenter_keymap') 52 | let g:qfenter_keymap = {} 53 | endif 54 | if !has_key(g:qfenter_keymap, 'open') 55 | let g:qfenter_keymap.open = ['', '<2-LeftMouse>'] 56 | endif 57 | if !has_key(g:qfenter_keymap, 'vopen') 58 | let g:qfenter_keymap.vopen = [''] 59 | endif 60 | if !has_key(g:qfenter_keymap, 'hopen') 61 | let g:qfenter_keymap.hopen = [''] 62 | endif 63 | if !has_key(g:qfenter_keymap, 'topen') 64 | let g:qfenter_keymap.topen = [''] 65 | endif 66 | 67 | " deprecated. will be removed from 2.5.0 68 | " Now the default setting of the new option g:qfenter_autoclose=0 will open a quickfix in a new tab (if g:qfenter_enable_autoquickfix is not 0 before 2.5.0). 69 | "if !exists('g:qfenter_enable_autoquickfix') 70 | "let g:qfenter_enable_autoquickfix = 1 71 | "endif 72 | 73 | if !exists('g:qfenter_autoclose') 74 | let g:qfenter_autoclose = 0 75 | endif 76 | 77 | if !exists('g:qfenter_exclude_filetypes') 78 | let g:qfenter_exclude_filetypes = [] 79 | endif 80 | 81 | if !exists('g:qfenter_excluded_action') 82 | " Action to take when the selected window contains and exclude filetype 83 | " 'next': Open the file in the next usable window, fall back to quickfix default if no usable windows (split above) (Default) 84 | " 'error': Show an error message and do not open the file 85 | let g:qfenter_excluded_action = 'next' 86 | endif 87 | 88 | if !exists('g:qfenter_prevtabwin_policy') 89 | " This option determines which window on which tab should have focus when the `wincmd p` is executed after opening a quickfix item. 90 | " 'qf': The previous window and tab are set to the quickfix window from which the QFEnter open command is invoked and the tab the window belongs to. (Default) 91 | " 'none': Do nothing for the previous window and tab. 92 | " The previous window is the window that previously had focus before the target window, in the process of `tabwinfunc`. 93 | " For `v*` and `h*` predefined commands, the previous window is the window focused before the quickfix window. 94 | " For `t*` predefined commands, the previous window and tab are the window focused before the quickfix window and the tab it belongs to. 95 | " 'legacy': The option for legacy behavior prior to QFEnter 2.4.1. 96 | " For `t*` predefined commands, follow the 'qf' policy. 97 | " Otherwise, follow the 'none' policy. 98 | let g:qfenter_prevtabwin_policy = 'qf' 99 | endif 100 | 101 | if !exists('g:qfenter_custom_map_list') 102 | let g:qfenter_custom_map_list = [] 103 | endif 104 | "The effect of 105 | " let g:qfenter_custom_map_list = [] 106 | " call add(g:qfenter_custom_map_list, { 107 | " \'tabwinfunc': 'QFEnter#GetTabWinNR_Open', 108 | " \'qfopencmd': 'cn', 109 | " \'keepfocus': 1, 110 | " \'keys': ['n'], 111 | " \}) 112 | "is identical to 113 | " let g:qfenter_keymap = {} 114 | " let g:qfenter_keymap.cnext_keep = ['n'] 115 | 116 | if !exists('g:qfenter_cc_cmd') | let g:qfenter_cc_cmd = '##cc' | endif 117 | if !exists('g:qfenter_ll_cmd') | let g:qfenter_ll_cmd = '##ll' | endif 118 | if !exists('g:qfenter_cn_cmd') | let g:qfenter_cn_cmd = 'cn' | endif 119 | if !exists('g:qfenter_cp_cmd') | let g:qfenter_cp_cmd = 'cp' | endif 120 | if !exists('g:qfenter_lne_cmd') | let g:qfenter_lne_cmd = 'lne' | endif 121 | if !exists('g:qfenter_lp_cmd') | let g:qfenter_lp_cmd = 'lp' | endif 122 | 123 | 124 | " autocmd 125 | augroup QFEnterAutoCmds 126 | autocmd! 127 | autocmd FileType qf call s:RegisterKeymap() 128 | augroup END 129 | 130 | " functions 131 | function! s:RegisterKeymap() 132 | for [cmd, keylist] in items(g:qfenter_keymap) 133 | let tabwinfunc = s:cmd_action_map[cmd][0] 134 | let qfopencmd = s:cmd_action_map[cmd][1] 135 | let keepfocus = s:cmd_action_map[cmd][2] 136 | for key in keylist 137 | execute 'nnoremap '.key.' :call QFEnter#OpenQFItem("'.tabwinfunc.'","'.qfopencmd.'","'.keepfocus.'",0)' 138 | execute 'vnoremap '.key.' :call QFEnter#OpenQFItem("'.tabwinfunc.'","'.qfopencmd.'","'.keepfocus.'",1)' 139 | endfor 140 | endfor 141 | for cfitem in g:qfenter_custom_map_list 142 | for key in cfitem.keys 143 | execute 'nnoremap '.key.' :call QFEnter#OpenQFItem("'.cfitem.tabwinfunc.'","'.cfitem.qfopencmd.'","'.cfitem.keepfocus.'",0)' 144 | execute 'vnoremap '.key.' :call QFEnter#OpenQFItem("'.cfitem.tabwinfunc.'","'.cfitem.qfopencmd.'","'.cfitem.keepfocus.'",1)' 145 | endfor 146 | endfor 147 | endfunction 148 | 149 | """""""""""""""""""""""""""""""""""""""""""" 150 | let &cpo= s:keepcpo 151 | unlet s:keepcpo 152 | 153 | " vim:set noet sw=4 sts=4 ts=4 tw=78: 154 | --------------------------------------------------------------------------------