I am trying to execute a keystroke from function when its called. However, it does not work.
function SmartNERDTreeFocus() if expand('%') =~ 'NERD_tree.*' normal <C-w><C-p> "execute 'normal \<c-w>\<c-p>' "return "\<C-w>\<C-p>" else call NERDTreeFocus() endif endfunction map <silent> <C-b> :call SmartNERDTreeFocus()<CR>
Hitting the shortcut will open up NERDTree, but hitting it again while in NERDTree's buffer does nothing. I want it to return to the previous window (C-wC-p).
What is the correct way to execute some keystrokes from a vimscript function in neovim?