But now I wanted to map <Enter> to <CTRL-W><Enter> so that by pressing
<Enter> the matching filename would open in a new window (the old
<CTRL-W><Enter> behavior). Actually it seems a bit tricky and I
couldn't accomplish this.
These are the things I tried
" Doesn't work, pressing <Enter> does nothing
:map <buffer> <Enter> <CTRL-W><Enter>
" Just to try if I can map <Enter> to somthing else, this works
:map <buffer> <Enter> any-command-with-only-letters-in-it
So the problem seems to be that I can map <Enter> to almost anything,
except more complicated stuff like <CTRL-W><Enter>.
So how would I do this?
Cheers,
Daniel
--
Psss, psss, put it down! - http://www.cafepress.com/putitdown
Got it, this works:
map <buffer> <Enter> <C-w><Enter>
Actually, there is still one mystifying thing about this. If the
quickfix list includes a file that is already open and it is selected
in the quickfix window with <CTRL-W><Enter> so that it is opened in a
new window then vim will jump to the window where the file is already
open (which is good) but will also open an empty window called No Name
right above the quickfix window. Is this intentional? How do I get rid
of this behavior? What I'm aiming for is have vim open the matching
file in a new window if the file is not open yet and if it already
open then just jump to it in its already opened window.
Any ideas?
Daniel
I don't know why that works, but that sort of problem is what the
noremap commands are for: to allow the use of the lhs in the rhs of
a mapping without recursing.
nnoremap <buffer> <Enter> <C-W><Enter>
Unfortunately, the best discussion of this command in the user
manual has no tag near it. To find it, execute ":help usr_40" and
search for "REMAPPING".
HTH,
Gary
Thanks, I've tried this too, but the strange behavior is still there.
If a file in the quickfix window is already open in its own window and
I select it (in the quickfix window) then an empty window called "No
Name" will be created (split) but the cursor will correctly jump to
the already open file. I can't make vim not open the "No Name" window.
For reference, this is what I do to open the quickfix window:
" by pressing 's' on a word open the quickfix window maximized with
grepped files
map s :cclose <Bar> :execute "vimgrep /" . expand("<cword>") . "/j **"
<Bar> cw<CR><Esc><C-w>_
The last part of this "<Esc><C-w>_" is designed to maximize the
quickfix window once it's open, but that doesn't work either :) The
quickfix window opens, but not maximized.
And in ~/.vim/after/ftplugin/qf.vim I have
" by pressing 'enter' the matching filename should open in a maximized
new window
nnoremap <buffer> <CR> <C-w><CR><Esc><C-w>_
In this case "<Esc><C-w>_" has the desired effect and the matched file
open in a maximized window, and the only problem I have is the empty
"No Name" window.
Any ideas?
Cheers,
Danie
That is strange. I don't see that behavior using vim 7.2.148. When
I use your mappings and I hit Enter on a quickfix line referring to
an already-open buffer, vim opens a new window containing that
buffer. I get a new window each time I press Enter in the quickfix
window, but no "[No Name]" buffers.
> For reference, this is what I do to open the quickfix window:
>
> " by pressing 's' on a word open the quickfix window maximized with
> grepped files
> map s :cclose <Bar> :execute "vimgrep /" . expand("<cword>") . "/j **"
> <Bar> cw<CR><Esc><C-w>_
>
> The last part of this "<Esc><C-w>_" is designed to maximize the
> quickfix window once it's open, but that doesn't work either :) The
> quickfix window opens, but not maximized.
The quickfix window is maximized for me.
What is the <Esc> for? I didn't understand its purpose so I removed
it from both macros and the behavior seemed to be the same.
> And in ~/.vim/after/ftplugin/qf.vim I have
>
> " by pressing 'enter' the matching filename should open in a maximized
> new window
> nnoremap <buffer> <CR> <C-w><CR><Esc><C-w>_
>
> In this case "<Esc><C-w>_" has the desired effect and the matched file
> open in a maximized window, and the only problem I have is the empty
> "No Name" window.
>
> Any ideas?
Again, it all works for me. What version of vim are you using?
Try starting vim with "-u NONE" to avoid interfering settings.
Since your goal is to open a new window only if a window containing
the desired buffer doesn't already exist, take a look at
:help switchbuf
I've never been able to use it to achieve the results I've wanted,
but it may do what you want.
Regards,
Gary
I'm using 7.1 and have a bunch of other custom configuration in .vimrc
and other files, so maybe it's the interaction of my other configs and
this particular setting. In any case it's good to know that with your
version everything is fine.
>> For reference, this is what I do to open the quickfix window:
>>
>> " by pressing 's' on a word open the quickfix window maximized with
>> grepped files
>> map s :cclose <Bar> :execute "vimgrep /" . expand("<cword>") . "/j **"
>> <Bar> cw<CR><Esc><C-w>_
>>
>> The last part of this "<Esc><C-w>_" is designed to maximize the
>> quickfix window once it's open, but that doesn't work either :) The
>> quickfix window opens, but not maximized.
>
> The quickfix window is maximized for me.
>
> What is the <Esc> for? I didn't understand its purpose so I removed
> it from both macros and the behavior seemed to be the same.
>
>> And in ~/.vim/after/ftplugin/qf.vim I have
>>
>> " by pressing 'enter' the matching filename should open in a maximized
>> new window
>> nnoremap <buffer> <CR> <C-w><CR><Esc><C-w>_
>>
>> In this case "<Esc><C-w>_" has the desired effect and the matched file
>> open in a maximized window, and the only problem I have is the empty
>> "No Name" window.
>>
>> Any ideas?
>
> Again, it all works for me. What version of vim are you using?
> Try starting vim with "-u NONE" to avoid interfering settings.
Thanks, I'll try this, most probably with "-u NONE" it will work for me too.
Cheers,
Daniel
> Since your goal is to open a new window only if a window containing
> the desired buffer doesn't already exist, take a look at
>
> :help switchbuf
>
> I've never been able to use it to achieve the results I've wanted,
> but it may do what you want.
--