for javascript
nnoremap <F5> :FloatermNew node %<CR>
for c
nnoremap <F5> :FloatermNew gcc % && ./a.out<CR>
for c++
nnoremap <F5> :FloatermNew g++ % && ./a.out<CR>
for python
nnoremap <F5> :Floaterm python3 %<CR>
Now i want that these all working with one shortcut F5
.
i done like this but get an error
nnoremap <expr> <F5> My_mapping()
function! My_mapping
if &filetype ==# 'c'
nnoremap <F5>:FloatermNew gcc % ./a.out <CR>
elseif &filetype ==# 'c++'
nnoremap <F5>:FloatermNew g++ % ./a.out <CR>
elseif &filetype ==# 'js'
nnoremap <F5>:FloatermNew node % <CR>
elseif &filetype ==# 'py'
nnoremap <F5>:FloatermNew python3 % <CR>
else
nnoremap <F5><CR>
endif
endfunction
error
Error detected while processing /home/visrut/.config/nvim/init.vim:
line 208:
E123: Undefined function: My_mapping
n <F5> * My_mapping()
line 220:
E193: :endfunction not inside a function
can anyone fix error?