vim shortcut to open a file under cursor in an already opened window
In vim you can open a file under the cursor by using the gf
command.
One can also easily open that file in a new split window by hitting <c-w> f
. This is a really nice and time saving feature.
However, I can't figure out, how to open the file in an already opened split window (without creating a new one).
vim vi editors key-mapping gvim
add a comment |
In vim you can open a file under the cursor by using the gf
command.
One can also easily open that file in a new split window by hitting <c-w> f
. This is a really nice and time saving feature.
However, I can't figure out, how to open the file in an already opened split window (without creating a new one).
vim vi editors key-mapping gvim
1
You may want to have a look at thepreview
feature (see:h preview
).
– Stéphane Chazelas
May 3 '13 at 15:01
Right, I use preview as well. However I didnt want to open the file in the preview window but explicitely in an other one.
– psibar
May 3 '13 at 15:04
add a comment |
In vim you can open a file under the cursor by using the gf
command.
One can also easily open that file in a new split window by hitting <c-w> f
. This is a really nice and time saving feature.
However, I can't figure out, how to open the file in an already opened split window (without creating a new one).
vim vi editors key-mapping gvim
In vim you can open a file under the cursor by using the gf
command.
One can also easily open that file in a new split window by hitting <c-w> f
. This is a really nice and time saving feature.
However, I can't figure out, how to open the file in an already opened split window (without creating a new one).
vim vi editors key-mapping gvim
vim vi editors key-mapping gvim
edited May 3 '13 at 14:37
asked May 3 '13 at 13:08
psibar
21628
21628
1
You may want to have a look at thepreview
feature (see:h preview
).
– Stéphane Chazelas
May 3 '13 at 15:01
Right, I use preview as well. However I didnt want to open the file in the preview window but explicitely in an other one.
– psibar
May 3 '13 at 15:04
add a comment |
1
You may want to have a look at thepreview
feature (see:h preview
).
– Stéphane Chazelas
May 3 '13 at 15:01
Right, I use preview as well. However I didnt want to open the file in the preview window but explicitely in an other one.
– psibar
May 3 '13 at 15:04
1
1
You may want to have a look at the
preview
feature (see :h preview
).– Stéphane Chazelas
May 3 '13 at 15:01
You may want to have a look at the
preview
feature (see :h preview
).– Stéphane Chazelas
May 3 '13 at 15:01
Right, I use preview as well. However I didnt want to open the file in the preview window but explicitely in an other one.
– psibar
May 3 '13 at 15:04
Right, I use preview as well. However I didnt want to open the file in the preview window but explicitely in an other one.
– psibar
May 3 '13 at 15:04
add a comment |
3 Answers
3
active
oldest
votes
I got all the pieces together to do the trick. The best way is to create a custom mapping for all the commands:
map <F8> :let mycurf=expand("<cfile>")<cr><c-w> w :execute("e ".mycurf)<cr><c-w>p
Explanation:
map <F8>
maps on "F8" the commands that follow
let mycurf=expand("<cfile>")
gets the filename under the cursor and saves it inmycurf
<c-w>w
changes the focus to the next open split window
execute("e ".mycurf)
opens the file saved inmycurf
- finally
<c-w>p
changes the focus to the previous window (where we actually came from)
add a comment |
That can't be done easily. A [count]
before <C-w>f
specifies which file match on 'path'
is opened, it does not select an existing window. Only for the <C-w>w
command, [count]
means "go to existing window number".
To get that functionality, you need to write a custom mapping which either
- grabs the file, goes to the
[count]
window and emulates thegf
command, or - clones the current buffer to the
[count]
window, and executesgf
there
Yes the only way to do it is to write a custom mapping. I was just having some trouble with grabbing the file under the cursor. But I think I have figured it out now
– psibar
May 3 '13 at 14:13
add a comment |
I searched for the same VIm's function and found out this solution which works like charm:
map <F8> :vertical wincmd f<CR>
Source page.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f74571%2fvim-shortcut-to-open-a-file-under-cursor-in-an-already-opened-window%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
I got all the pieces together to do the trick. The best way is to create a custom mapping for all the commands:
map <F8> :let mycurf=expand("<cfile>")<cr><c-w> w :execute("e ".mycurf)<cr><c-w>p
Explanation:
map <F8>
maps on "F8" the commands that follow
let mycurf=expand("<cfile>")
gets the filename under the cursor and saves it inmycurf
<c-w>w
changes the focus to the next open split window
execute("e ".mycurf)
opens the file saved inmycurf
- finally
<c-w>p
changes the focus to the previous window (where we actually came from)
add a comment |
I got all the pieces together to do the trick. The best way is to create a custom mapping for all the commands:
map <F8> :let mycurf=expand("<cfile>")<cr><c-w> w :execute("e ".mycurf)<cr><c-w>p
Explanation:
map <F8>
maps on "F8" the commands that follow
let mycurf=expand("<cfile>")
gets the filename under the cursor and saves it inmycurf
<c-w>w
changes the focus to the next open split window
execute("e ".mycurf)
opens the file saved inmycurf
- finally
<c-w>p
changes the focus to the previous window (where we actually came from)
add a comment |
I got all the pieces together to do the trick. The best way is to create a custom mapping for all the commands:
map <F8> :let mycurf=expand("<cfile>")<cr><c-w> w :execute("e ".mycurf)<cr><c-w>p
Explanation:
map <F8>
maps on "F8" the commands that follow
let mycurf=expand("<cfile>")
gets the filename under the cursor and saves it inmycurf
<c-w>w
changes the focus to the next open split window
execute("e ".mycurf)
opens the file saved inmycurf
- finally
<c-w>p
changes the focus to the previous window (where we actually came from)
I got all the pieces together to do the trick. The best way is to create a custom mapping for all the commands:
map <F8> :let mycurf=expand("<cfile>")<cr><c-w> w :execute("e ".mycurf)<cr><c-w>p
Explanation:
map <F8>
maps on "F8" the commands that follow
let mycurf=expand("<cfile>")
gets the filename under the cursor and saves it inmycurf
<c-w>w
changes the focus to the next open split window
execute("e ".mycurf)
opens the file saved inmycurf
- finally
<c-w>p
changes the focus to the previous window (where we actually came from)
edited May 3 '13 at 16:07
Damien
498513
498513
answered May 3 '13 at 14:29
psibar
21628
21628
add a comment |
add a comment |
That can't be done easily. A [count]
before <C-w>f
specifies which file match on 'path'
is opened, it does not select an existing window. Only for the <C-w>w
command, [count]
means "go to existing window number".
To get that functionality, you need to write a custom mapping which either
- grabs the file, goes to the
[count]
window and emulates thegf
command, or - clones the current buffer to the
[count]
window, and executesgf
there
Yes the only way to do it is to write a custom mapping. I was just having some trouble with grabbing the file under the cursor. But I think I have figured it out now
– psibar
May 3 '13 at 14:13
add a comment |
That can't be done easily. A [count]
before <C-w>f
specifies which file match on 'path'
is opened, it does not select an existing window. Only for the <C-w>w
command, [count]
means "go to existing window number".
To get that functionality, you need to write a custom mapping which either
- grabs the file, goes to the
[count]
window and emulates thegf
command, or - clones the current buffer to the
[count]
window, and executesgf
there
Yes the only way to do it is to write a custom mapping. I was just having some trouble with grabbing the file under the cursor. But I think I have figured it out now
– psibar
May 3 '13 at 14:13
add a comment |
That can't be done easily. A [count]
before <C-w>f
specifies which file match on 'path'
is opened, it does not select an existing window. Only for the <C-w>w
command, [count]
means "go to existing window number".
To get that functionality, you need to write a custom mapping which either
- grabs the file, goes to the
[count]
window and emulates thegf
command, or - clones the current buffer to the
[count]
window, and executesgf
there
That can't be done easily. A [count]
before <C-w>f
specifies which file match on 'path'
is opened, it does not select an existing window. Only for the <C-w>w
command, [count]
means "go to existing window number".
To get that functionality, you need to write a custom mapping which either
- grabs the file, goes to the
[count]
window and emulates thegf
command, or - clones the current buffer to the
[count]
window, and executesgf
there
answered May 3 '13 at 14:00
Ingo Karkat
8,53911832
8,53911832
Yes the only way to do it is to write a custom mapping. I was just having some trouble with grabbing the file under the cursor. But I think I have figured it out now
– psibar
May 3 '13 at 14:13
add a comment |
Yes the only way to do it is to write a custom mapping. I was just having some trouble with grabbing the file under the cursor. But I think I have figured it out now
– psibar
May 3 '13 at 14:13
Yes the only way to do it is to write a custom mapping. I was just having some trouble with grabbing the file under the cursor. But I think I have figured it out now
– psibar
May 3 '13 at 14:13
Yes the only way to do it is to write a custom mapping. I was just having some trouble with grabbing the file under the cursor. But I think I have figured it out now
– psibar
May 3 '13 at 14:13
add a comment |
I searched for the same VIm's function and found out this solution which works like charm:
map <F8> :vertical wincmd f<CR>
Source page.
add a comment |
I searched for the same VIm's function and found out this solution which works like charm:
map <F8> :vertical wincmd f<CR>
Source page.
add a comment |
I searched for the same VIm's function and found out this solution which works like charm:
map <F8> :vertical wincmd f<CR>
Source page.
I searched for the same VIm's function and found out this solution which works like charm:
map <F8> :vertical wincmd f<CR>
Source page.
answered 1 hour ago
waldauf
9018
9018
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f74571%2fvim-shortcut-to-open-a-file-under-cursor-in-an-already-opened-window%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
You may want to have a look at the
preview
feature (see:h preview
).– Stéphane Chazelas
May 3 '13 at 15:01
Right, I use preview as well. However I didnt want to open the file in the preview window but explicitely in an other one.
– psibar
May 3 '13 at 15:04