开发者

open a file under cursor in a split window

开发者 https://www.devze.com 2022-12-23 05:12 出处:网络
I of开发者_运维问答ten jump from a file to file,while workinga large codebase. I typically do this by way ofputting cursor on the file, say foo.h, and typing \"gf\". I wonder if I can do the same thin

I of开发者_运维问答ten jump from a file to file, while working a large codebase. I typically do this by way of putting cursor on the file, say foo.h, and typing "gf". I wonder if I can do the same thing, yet open the file in a split window.

One obvious solution is to simply type: vsp (sp) filename.


<c-w>gf open in a new tab (Ctrl-w gf)

<c-w>f for split window <-- this is the answer you are seeking (Ctrl-w f)

source: http://vim.wikia.com/wiki/Open_file_under_cursor


When I do :sp or :vs, the new window is created, but my cursor is left on the same line. Thus, you could do :sp followed by gf. You could also make a shortcut command or mapping for that sequence.


I use a.vim plugin for this. http://www.vim.org/scripts/script.php?script_id=31

In addition to what you are looking for. I also has a feature in which you can alternate between header and cpp file very easily(if you work on c/cpp code). Its very handy sometimes


If you put this line into your _vimrc:

map <F2> <C-w>f:call MoveWindowToRight(1)<CR>

you can open the file name under the cursor with F2 and it will appear at the right side of you current window. This is the best match to your mentioned 'obvious solution' using :vsplit.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号