tpope / vim-rails

rails.vim: Ruby on Rails power tools
http://www.vim.org/scripts/script.php?script_id=1567
4.1k stars 383 forks source link

`gf` to open in new split pane #512

Closed kleinjm closed 6 years ago

kleinjm commented 6 years ago

I saw this in the docs for a new window and new tab but is there a mapping or an easy way to map to opening in a new split?

The |gf| command, which normally edits the current file under the cursor, has
been remapped to take context into account.  |CTRL-W_f| (open in new window),
|CTRL-W_gf| (open in new tab), and |c_CTRL-R_CTRL-F| (insert filename on
command line) are also remapped.
tpope commented 6 years ago

You can use <Plug><cfile> on the command line to access the filename rails.vim hands off to :find. Here's an example for making <Leader>f in Rails buffers use a vertical split:

autocmd User Rails nmap <buffer> <Leader>f :vert sfind <Plug><cfile><CR>

Here's a more complicated example that works universally:

" Use Vim's built-in CTRL-R_CTRL-F when no plugin has claimed <Plug><cfile>
if empty(maparg('<Plug><cfile>', 'c'))
  cnoremap <Plug><cfile> <C-R><C-F>
endif
" Helper map to pass the count (e.g., 2gf) to the underlying command
nnoremap <SID>: :<C-U><C-R>=v:count ? v:count : ''<CR>
" Map <Leader>f to vertical split
nmap <Leader>f <SID>:vert sfind <Plug><cfile><CR>