FTerm.nvim icon indicating copy to clipboard operation
FTerm.nvim copied to clipboard

Trigger FocusGained after closing the terminal window

Open mjakl opened this issue 2 years ago • 1 comments

When I manipulate an open file through FTerm (like resetting the file via LazyGit, or simply echo test >> file.txt, I need to manually reload the file from disk when I close/toggle FTerm.

NeoVim usually checks for modifications on FocusGained events, and reloads the files automatically if autoread is active. E.g. when I call echo anothertest >> file.txt in a separate terminal, and then switch back to Vim, the file is reloaded automatically.

Is it possible for FTerm to issue the FocusGained event to trigger the check if the file has been modified when closing FTerm? Users can decide how to deal with this through the autoread option.

It looks like NeoVim has an API for that nvim_ui_set_focus since 0.8.0 (see this ticket).

mjakl avatar Mar 31 '23 10:03 mjakl

Small sidenote: when toggling FTerm, it is possible to include :checktime to check for file-changes and reload on demand. For example: vim.keymap.set("t", "<F7>", "<C-\\><C-n><CMD>lua require('FTerm').toggle()<CR>:checktime<CR>")

To trigger this behavior on exit (FTerm close), I can add a on_exit callback:

        on_exit = function()
          vim.cmd(":checktime")
        end,

mjakl avatar Mar 31 '23 10:03 mjakl