I'm trying to create a simple function in vim which lets me map <leader>b
, <leader>n
, and <leader>0
to execute a function that checks if a nerd tree is open then cycle tabs and do :NerdTreeFind
if not then only cycle tabs. but I couldn't seem to make it work and it returns E121: Undefined variable: CR
here is the script
function! CheckNerdTree(tab)
if exists("g:NERDTree") && g:NERDTree.IsOpen()
execute a:tab<CR>:NERDTreeFind<CR><C-w>l<CR>
else
execute a:tab<CR>
endif
endfunction
noremap <leader>0 :call CheckNerdTree(":tablast")
noremap <leader>n :call CheckNerdTree(":tabnext")
noremap <leader>b :call CheckNerdTree(":tabprev")
I'm pretty new to vim scripting and haven't really 100% understand how it works, any help would be appreciated. Thanks
nnoremap
for normal mode.