0

I plugged float-term plugin , that open terminal window in neovim.

when I compile javascript with node in float term I did like :FloatermNew node % then it compiles fine and show me the output in terminal window.

But when I want to make shortcut like this let g:floaterm_keymap_new node % = '<F5>' in my init.vim

it's give me error like this

Error detected while processing /home/visrut/.config/nvim/init.vim:
E121: Undefined variable: g:floaterm_keymap_new
E488: Trailing characters

what should I write?

Should we have to write function for that also note that let g:floaterm_keymap_new = '<F5>' works fine but just open terminal.

I also want to do something like on based on filetype you working, I want to like Vim script that if filetype is .cpp then it compile with g++ and give ./a.out output to terminal with same shortcut F5.

If you don't know second answer then please just give in first answer of that wrong syntax.

you can checkout plugin keymaps from here https://vimawesome.com/plugin/vim-floaterm#keymaps

1
  • 1
    Please avoid asking more than one question in a single post (How to Ask). Since you’ve already posted an answer, it’s unclear what the best way forward is. I think we should keep this one to be the second question, and you can repost the first one separately.
    – D. Ben Knoble
    Commented Oct 11, 2020 at 13:11

1 Answer 1

0

You can map FloatTermNew <cmd> in an autocmd for specific filetypes:

augroup floatterm-mappings
    au!
    au FileType javascript nnoremap <buffer> <F5> :w<esc>:FloatermNew node %<CR>
    au FileType c          nnoremap <buffer> <F5> :w<esc>:FloatermNew gcc % && ./a.out && rm a.out<CR>
    au FileType cpp        nnoremap <buffer> <F5> :w<esc>:FloatermNew g++ % && ./a.out && rm a.out<CR>
    au FileType python     nnoremap <buffer> <F5> :w<esc>:FloatermNew python3 %<CR>
augroup end

The <buffer> in nnoremap makes sure the mapping only works for that specific buffer (rather than all buffers).

2
  • 1
    I think it would be helpful to other users who come across this question if you were to flesh out this answer to more than 4 autocmds (a brief description maybe?). Commented Oct 11, 2020 at 15:21
  • You can edit it if you want I will approve it.
    – Visrut
    Commented Oct 11, 2020 at 15:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.