I want the below function to return keybindings but all it returns is a string.
nmap <expr> <space>t ManageTerminal()
function ManageTerminal()
if bufname('terminal') ==# 'terminal'
if expand('%:t') ==# "terminal"
return '<C-\><C-N><C-w>q'
else
return ':sb terminal<CR>:resize -6<CR>i'
endif
else
return ':split<CR>:resize -6<CR>:te<CR>:file terminal<CR>i'
endif
endfunction
This works just fine.
nmap <expr> <space>t bufname('terminal') ==# 'terminal' ? (expand('%:t') ==# "terminal" ? '<C-\><C-N><C-w>q' : ':sb terminal<CR>:resize -6<CR>i') : ':split<CR>:resize -6<CR>:te<CR>:file terminal<CR>i'
But it is messy. So how do I return keybindings from a function?
<space> t
mapping supposed to run one of the commands that you're returning as strings? Why not just call the function and have the function run the appropriate command? – B Layer Jan 9 at 12:48nmap ....etc etc
) . It doesn't seem worthwhile to make it happen in two places. Or, I suppose, you could build a string that contains the whole mapping (return "nmap ... etc etc"
) and do:exe ManageTerminal()
or something like that. – B Layer Jan 9 at 12:50return '<C-\><C-N><C-w>q'
would just return it as a plain string with no meaning. Whereas what I wanted isreturn "\<C-\>\<C-N>\<C-w>q"
. This is what I meant by return keybinding – Akash Karnatak Jan 9 at 13:23