2023-04-25

Vim-Floaterm Wrapper for WinTermNote

Vim-floaterm plugin supports wrappers, a set of Vim scripts located in the autoload\floaterm\wrapper runtime directory, useful for running terminal applications inside a Vim's window.

The script below creates a wrapper for WinTermNote, a notetaking terminal application.

"" filename:~/.vim/autoload/floaterm/wrapper/wintermnote.vim
function! floaterm#wrapper#wintermnote#(cmd, jobopts, config) abort
  let g:floaterm_wintype='float'
  let g:floaterm_position='right'
  let a:jobopts.on_exit = funcref('s:wintermnote_callback')
  ""------------------|
  ""                  V WinTermNote Path
  return [v:false, 'C:\\Users\\user\\AppData\\Local\\Programs\\WinTermNote\\wintermnote_terminal.exe --external']
endfunction

function! s:wintermnote_callback(job, data, event, opener) abort
  sleep 100m
  let newbuf = system("more ".fnamemodify('~',':p')."\\.wintermnote_mr")
  if len(newbuf)>1
    silent exec(":e ".newbuf)
  endif
endfunction

As shown in this video, the command:

   :FloatermNew wintermnote

run the application inside Vim, and the selected note will be opened directly in a buffer.

You can modify the type of the floating window (floaterm_wintype), it accepts also horizontal and vertical splits and the position on the screen (floaterm_position) where it will be displayed.