I know my title is not that descriptive/clear so let me explain.
Yesterday I can across Vimgrep and copen so I added the below line in .vimrc
nnoremap <silent> ,/ :execute 'vimgrep /'.@/.'/g %'<CR>:copen<CR>
What it does is open a quickfix list for the searched(highlighted) word in vim.
Now when you press Enter<CR> in quickfix list it takes you to a corresponding line in the main Vim Window.
Now, the problem I am facing is I have mapped my <CR like map <CR> o<Esc> which creates a new line just below the current line.
So, as you can see there is a conflict b/w the two. So, what I am trying is to come up with a vim function like
Pseudo Code
function IfNotInsideQuickFix()
if buffer != QuickFix
then map <CR> o<Esc>
elif buffer == QuickFix
Normal behaviour
Call function
Here is the output of :buffers
:buffers
1 #a "test.cs" line 0
2 %a- "[Quickfix List]" line 1
Press ENTER or type command to continue
I have no experience in writing vim functions. So, can someone please guide me to it.
PS: I know that I can change my Vim mapping to create a new line but I want to learn how to do it via Vim function
You can keep your global
<CR>mapping as-is, but locally in quickfix windows restore the original behavior. This is done via an:autocmd(triggered when the quickfix window opens) that maps (without remapping)<CR>(locally via<buffer>) onto itself.