Consider the following function
function! Exp()
call feedkeys(":new ~/.vimrc\<CR>")
call search('F')
endfunction
My expectation from Exp() was that if I call Exp() then
1) I see my vimrc file opened in a new window, and
2) the first instance of 'F' is searched in the vimrc file with the cursor landing on it.
However, what I see is that only the first expectation meets reality. In fact, the second line call search('F')
seems to be ignored by vim.
PS: Please feel free if you have a suggestion to improve my code.
call feedkeys(...)
withsplit $MYVIMRC
? – D. Ben Knoble♦ Apr 16 '20 at 17:47.vimrc
is not really important here. I'd like to do this for arbitrary files. Thanks. – caffeinemachine Apr 16 '20 at 18:03split
, similar tonew
, and use$MYVIMRC
to always get the right vimrc file) – D. Ben Knoble♦ Apr 16 '20 at 18:04call feedkeys(":split $MYVIMRC\<CR>")
different fromsplit $MYVIMRC
? in the second line of the code. – caffeinemachine Apr 16 '20 at 18:13:help feedkeys()
? It has to do with the underlying buffer of keystrokes getting manipulated, which often has unforseen impacts. Easier to just let the vimscript engine do things in order. You rarely need feedkeys. – D. Ben Knoble♦ Apr 16 '20 at 18:17