numtostr / fterm.nvim Goto Github PK
View Code? Open in Web Editor NEW:fire: No-nonsense floating terminal plugin for neovim :fire:
License: MIT License
:fire: No-nonsense floating terminal plugin for neovim :fire:
License: MIT License
Hello!
Having a small issue.
I have the following function:
function LazygitFloat()
local cfg = {
ft = 'lazygit',
cmd = "lazygit",
auto_close = true,
dimensions = {
height = 0.8, -- Height of the terminal window
width = 0.8, -- Width of the terminal window
},
}
local term = require('FTerm').new(cfg)
if not term then
return
end
term.open()
end
When I attempt to run this, I get this message:
FTerm: setup() is optional. Please remove it!
What am I doing wrong in the above function to get this?
If I just run require('FTerm').run("lazygit")
, it works fine enough, but I am unable to customize the options in this case.
small update:
from init.lua for FTerm
---Creates a custom terminal
---@param cfg Config
---@return Term
function M:new(cfg)
print(cfg)
return Term:new():setup(cfg)
end
I'm getting a nil
for the print(cfg)
I added. I must be doing something wrong.
Any help is greatly appreciated.
Thanks!
First of all, I love your plugin! As I'm sure others have done, I use it to wrap lf
as a built-in file browser. It forms what I think is the most ergonomic part of my setup, and the API you've put together basically made it so I didn't even need to think about the terminal side of things. ๐
The issue I'm running into is that when I toggle the FTerm instance that contains my lf
process and then open it back up again, the existing output re-appears shifted to the left by several characters part of the time.
This only appears to happen when the output produced by lf
is wider than the window size defined by FTerm. This is almost certainly something I can fix on the lf
side of things (seems to be caused by my file preview script, and only happens when I'm currently previewing a file that is wider than some threshold).
I wonder, though, if it makes sense to have FTerm scroll back to the left of the terminal output when restoring the terminal buffer's contents so that the left edge of the output is always visible?
nvim --version:
NVIM v0.5.0-dev
Build type: Release
LuaJIT 2.1.0-beta3
Compilation:
Compiled by nixbld
Features: +acl +iconv +tui
See ":help feature-compile"
minimal init.lua:
local path = vim.fn.stdpath('data')..'/site/pack/packer/opt/packer.nvim'
if vim.fn.empty(vim.fn.glob(path)) > 0 then
vim.api.nvim_command('!git clone https://github.com/wbthomason/packer.nvim '..path)
end
-- Required if packer is in `opt` path
vim.cmd('packadd packer.nvim')
local packer = require('packer')
return packer.startup(function()
local use = packer.use
use { 'wbthomason/packer.nvim', opt = true }
use {
"numtostr/FTerm.nvim",
config = function()
require'FTerm'.setup()
end
}
end)
Commands FTermOpen or FTermToggle:
E5108: Error executing lua ...site/pack/packer/start/FTerm.nvim/lua/FTerm/terminal.lua:93: Invalid key 'border'
I tried:
require'FTerm'.setup({
dimensions = {
height = 0.8,
width = 0.8,
x = 0.5,
y = 0.5
},
border = 'single'
-- border = '|'
})
with the same result.
Thanks for your work.
After a process in a scratch terminal is executed, it would be useful to be able to execute a lua function taking the exit_status of the job as it's input.
I think the implementation should be pretty straight-forward as the building blocks already seems to be in place (jobwait).
I'm thinking about two main api:
A table field in the scratch paramater:
lua require('FTerm').scratch({ cmd = 'yarn build' , on_exit = function})
A function call( is this possible in lua?):
lua require('FTerm').scratch({ cmd = 'yarn build' }).on_exit(function)
My main goal is to be able to interact with nvim-notify nicely.
Steps to reproduce:
:xa
Error:
E948: Job still running
E676: No matching autocommands for acwrite buffer
Nvim version: nightly@fe808f0
I'm trying to run a terminal with 'cd "'..vim.fn.expand('%:h')..'" ; cd "$(git rev-parse --show-toplevel)" ; lazygit'
everytime the terminal is (re)opened. This is not currently possible, as the cmd
is only evaluated upon creation.
It would be nice if the I could use a function instead of a string on cmd
, which would be called on every startup of the terminal:
require("FTerm"):new({
...
cmd = function() return 'cd "'..vim.fn.expand('%:h')..'" ; cd "$(git rev-parse --show-toplevel)" ; lazygit' end,
...
})
Note: I'm posting this request because terminal:run()
won't suffice, as run
will re-run the command on every execution, while setting cmd
would only re-run the command when the terminal is closed and reopened.
Hi all,
I love the scratch terminal and have used it forever since its release. Very fast and super useful.
Still, I need the ability to pass the arguments along with cmd option in config. My example use case would be like this
-- debug current python script
vim.cmd('command! Pudb lua require("FTerm").scratch({ cmd = "pudb" args = "%" })')
Of course, "%" is a vim feature for expanding the current filename. I haven't had much experience with vim API in lua yet. Maybe some of you guys know how to do it right away and have some suggesting idea. I think this feature could add even more flexibility to Fterm.
Thank you in advance!
hello I have an issue. How can I lazy load FTerm. I am trying to find this so that I can implement this on StarVim
When a new terminal is created with the run() function, instead of running the inputted command, something like: $ table: HEXNUM
is run instead.
After doing some testing, this broke in commit f3fb0fe.
With a fresh version of FTerm.nvim, put this in your init.vim:
nnoremap <leader>r :w<CR> :lua require('FTerm').run({'echo', 'hello'})<CR>
or whatever the equivalent is in Lua.
Now when r is pressed, the command doesn't work and behaves as described in the 'Problem' section.
After going back to the commit before f3fb0fe, everything worked again.
Run nvim -v
:
NVIM v0.7.0-dev+817-gbe255557c
E5108: Error executing lua ...site/pack/packer/start/FTerm.nvim/lua/FTerm/terminal.lua:156: Expected Lua number
stack traceback:
[C]: in function 'nvim_buf_set_option'
...site/pack/packer/start/FTerm.nvim/lua/FTerm/terminal.lua:156: in function 'open_term'
...site/pack/packer/start/FTerm.nvim/lua/FTerm/terminal.lua:178: in function 'open'
...site/pack/packer/start/FTerm.nvim/lua/FTerm/terminal.lua:221: in function 'toggle'
...vim/site/pack/packer/start/FTerm.nvim/lua/FTerm/init.lua:37: in function 'toggle'
[string ":lua"]:1: in main chunk
Press ENTER or type command to continue
nvim
v0.5.0-865-gfb52790d1
sway
version 1.5.1
alacritty
0.6.0 (04cbf767)
Arch 5.9.1-rt20-1-rt
this sort of stuff happens when I resize my window (for bigger) after calling :FTermToggle
on opening nvim
.
and this sort of stuff happens when I resize my window (for smaller) after calling :FTermToggle
on opening nvim
.
in both cases i have to toggle FTerm off/on to create the issue.
can you reproduce on your wm / system ?
and thanks for a nice plugin.
The first time that a terminal window is opened takes some seconds to be able to use, mainly if you have a lot of configurations to start the terminal.
Would be nice a pre start feature, without to show a terminal, starting in background.
Thanks for maintaining FTerm.nvim! It's a really cool project :)
I use k9s
to monitor my kubernetes clusters in the terminal, and was previously using nvim-k8s to launch a floating window in neovim with k9s
running in it. I wanted to consolidate my plugins and use fterm for k9s instead, because nvim-k8s is not actively maintained right now anyway. Here's what I put together in my lua config:
local fterm = require("FTerm")
-- must install k9s in advance, see: https://k9scli.io/topics/install/
local k9s = fterm:new({
ft = 'fterm_k9s',
cmd = "k9s",
dimensions = {
height = 0.9,
width = 0.9
}
})
-- Use this to toggle k9s in a floating terminal
-- first arg of 'n' is for normal mode in neovim
-- <A-b> are keys: Alt + b (alt is option on macOS)
vim.keymap.set('n', '<A-b>', function()
k9s:toggle()
end)
Launching k9s
in a floating terminal with Alt+b works fine, but I can't background it with the same key combination and I'm not sure why. I think k9s
is capturing the key input, but I'm not really sure how to fix this. I know in nvim-k8s they used the keys Alt+p for toggling the floating window, and that worked fine, but I have no idea why it doesn't work for fterm.
I tried with Alt+p instead of the config above and I get the same result of it working for opening the terminal, but not for backgrounding it.
Do you have any ideas on how to solve this? It doesn't look like k9s
is actually using Alt for anything according to their docs, so I'm a bit confused ๐ค
I've installed FTerm and am using lua require('FTerm').toggle()
to toggle the terminal, which opens it, but once the terminal is open, how to I toggle it closed again as I can't enter neovim's command mode inside the terminal?
launching the terminal in project root possibly ?
I intend to use this to create a wrapper to TUI file managers like ranger
& lf
, where opening a file in the terminal would open it in a new buffer. I have no idea how to implement something like this though. Any pointers?
Reference: https://github.com/ptzz/lf.vim
Update: For others joining in, I misinterpreted the issue at first. See my next comment below for describing the real problem.
With Neovim v0.5.0-dev+1302-g8a93d1028, when I run the following, the border style looks exactly the same as if single
was replaced with double
:
:lua require'FTerm'.setup({border = 'single'})
Adjusting this setting through an init file has the same results.
On the other hand, using the values none
and shadow
(taken from :h nvim_open_win
) works as expected.
I see there's no way to modify colours. I got a PR concerning the colours not showing on FTerm. my attempt to fix it locally seems to not be working.
local filetype = vim.api.nvim_buf_get_option(0, "filetype")
-- File/buffer specific settings
if filetype == "FTerm" then
colors.black = "#fff"
colors.bg2 = "#fff"
end
I think the problem might be stemming from this. Any help or suggestions would be appreciated. Thanks
Hi! I've got a little question. I'm using the vifm
file manager and I'm wondering if I should add a PR for a default vifm-floating-terminal. What do you think about that?
As title. For padding I mean the distance between text inside the floating terminal and the border of it.
Currently, when auto_close = true
, FTerm always close window after cmd finished, success or failure. I think it's useful to check the error msg if a cmd failed. So I suggest we can keep the terminal window if cmd didn't exit with code 0.
Hi! I mean a58dc7a. I tried setting cmd
in my require'FTerm'.setup()
, but it didn't work because it always asserts os.getenv('SHELL')
regardless of what I set cmd
to. Reverting line 26 in utils.lua
makes it work again.
Is it possible to get the buffer number of a custom terminal? I would like to be able to set a custom keymap for a specific terminal. This would also be useful for other buffer-local settings. Something like the (not working) example below:
local uvicorn = fterm:new {
cmd = 'poetry run uvicorn api.main:app --host 0.0.0.0 --reload',
ft = 'fterm__uvicorn'
}
vim.keymap.set(
't',
'q',
function() uvicorn:close() end,
{ buffer = uvicorn:get_buf(), desc = 'Close uvicorn window' }
)
E5108: Error executing lua ...site/pack/packer/start/FTerm.nvim/lua/FTerm/terminal.lua:97: Window was closed immediately
stack traceback:
[C]: in function 'nvim_open_win'
...site/pack/packer/start/FTerm.nvim/lua/FTerm/terminal.lua:97: in function 'create_win'
...site/pack/packer/start/FTerm.nvim/lua/FTerm/terminal.lua:163: in function 'open'
...site/pack/packer/start/FTerm.nvim/lua/FTerm/terminal.lua:208: in function 'toggle'
...are/nvim/site/pack/packer/start/FTerm.nvim/lua/FTerm.lua:37: in function 'toggle'
[string ":lua"]:1: in main chunk
I encountered this error when using fzf-lua
's git_status
function. I pressed <ESC>
after I finished reading the git diff
of files.
When FTerm is invoked in a buffer (in this case, to use gitui
) the plugin lualine reverts to the built-in statusline. However, after switching buffers (:bn
or bp
), the statusline rendered by lualine returns. I do not see this behavior with other plugins that use floating windows such as rnvimr or fzf.vim.
The desired behavior is that the statusline does not revert to the built-in statusline after invoking FTerm.
I'm not sure how to go about looking into this further, but here are some relevant configs:
" A blazing fast and easy to configure neovim statusline written in pure lua. Plug 'hoob3rt/lualine.nvim'
require('lualine').setup {
options = {theme = 'everforest'}
}
local term = require("FTerm.terminal")
local gitui = term:new():setup({
cmd = "gitui",
dimensions = {
height = 0.9,
width = 0.9
}
})
-- Use this to toggle gitui in a floating terminal
function _G.__fterm_gitui()
gitui:toggle()
end
-- Keybinding
local map = vim.api.nvim_set_keymap
local opts = { noremap = true, silent = true }
map('', '<leader>t', '<CMD>lua _G.__fterm_gitui()<CR>', opts)
map('', '<leader>T', '<C-\\><C-n><CMD>lua _G.__fterm_gitui()<CR>', opts)
Please let me know if there is any other relevant info that I can post.
I ran :pwd
in a buffer and got ~/.config
, while when I execute :lua require("FTerm").toggle()
the path is at ~
.
Update: I have tested other folders under ~
, this bug only happens on ~/.config
.
It would be great to have the ability to pass a command to a floating terminal.
I would use this to launch lazygit
with a single keybind.
Includes
Hi! Coming from reddit. Not sure if this is the best place to ask something.
If I toggle the term, what does pressing escape do? Does it shift the focus to the buffer that was last opened before opening a floating term?
If yes, can this behavior be changed? E.g. disabling esc key in the floating term
I'm asking because I'll like to use fterm with lazygit and would need to use esc there.. many thanks in advance for your help!!
After commit 0080eae, whenever I enter a new terminal, my cursor gets stuck outside of the floating window.
Just open any terminal window and try to enter something into the prompt.
Good day to you!
For opening csv files in certain program i have this code:
local fterm = require("FTerm")
function _G.fterm.visidata()
local visidata = fterm:new({
ft = "fterm_visidata", -- You can also override the default filetype, if you want
cmd = "visidata " .. vim.fn.expand("%"),
dimensions = {
x = 1,
y = 0,
height = 0.9,
width = 0.9,
},
})
-- if vim.bo.filetype == "csv" then
visidata:toggle()
-- end
end
right now it creates new fterm
-instance in function.
is it possible to define template without cmd
attribute, but set it in dynamic
function, so cmd
could be dynamic because of expansion of %
?
something like this (i've tried this, but get only shell float window):
local fterm = require("FTerm")
local visidata = fterm:new({
ft = "fterm_visidata", -- You can also override the default filetype, if you want
dimensions = {
x = 1,
y = 0,
height = 0.9,
width = 0.9,
},
})
function _G.fterm.visidata()
visidata.cmd = "visidata " .. vim.fn.expand("%") -- if vim.bo.filetype == "csv" then
visidata:toggle()
-- end
end
Thank you!
I noticed there's no option to save current buffer before executing the scratch terminal in this plugin so I did that myself by calling vim.cmd
. Here's a part of my config for that (executing a code inside of buffer 0):
local fterm = require('FTerm')
local fterm_dimensions = {
height = 0.35,
width = 1.0,
y = 1.0
}
fterm.setup({ dimensions = fterm_dimensions })
local runners = {
python = 'python3.7',
sh = 'bash'
}
map('n', '<Leader>e', function()
vim.cmd('write')
local buf = vim.api.nvim_buf_get_name(0)
local ftype = vim.filetype.match({ filename = buf })
local exec = runners[ftype]
if exec ~= nil then
fterm.scratch({
cmd = { exec, buf },
dimensions = fterm_dimensions
})
end
end
)
Environment:
OS
: debian10
NVIM version
: the latest 0.9.0 dev
The problem is that if I do execute that action over unsaved buffer too fast. the contents of it displays in the terminal buffer. How to reproduce that with the config above:
<Leader>e
hotkey.All the actions above must be performed as quick as you can. And whatever you do in the main buffer (buffer 0) is mirrored to the terminal buffer.
This's a little video showing that behaviour (starting from 0:56 sec)
https://user-images.githubusercontent.com/6321554/199979073-ecd3b7b5-d949-4d11-afd9-ff1f96fb10a6.mp4
Hi!
Thanks for the awesome plugin.
I've noticed that the row
and col
are calculated as
local col = math.ceil((cl - width) * opts.x)
local row = math.ceil((ln - height) * opts.y - 1)
which means the position depends on the free space.
My dimensions config looks as follow
{ height = 0.3, width = 0.2, x = 0.8, y = 0 }
But the result is not the expected. If I want to place the terminal at the top right, then the x
position must be 1
which feels counter intuitive.
{ height = 0.3, width = 0.2, x = 1, y = 0 }
How to Reproduce:
FzfLua buffers
:lua require("FTerm").toggle()
Friendly linked to the error line:
FTerm.nvim/lua/FTerm/terminal.lua
Line 109 in eabb65f
Hi, thx for this great project!
I don't know how to set compile and execute commands in scratch terminal cmd
config. Firstly, I've tried this by follow readme :
local runners = { c = 'gcc', cpp = 'g++' }
vim.keymap.set('n', '<leader><Enter>', function()
local buf = vim.api.nvim_buf_get_name(0)
local ftype = vim.filetype.match({ filename = buf })
local fname = string.gsub(buf, ftype, '')
local exec = runners[ftype]
if exec ~= nil then
if exec == 'c' then
local cbin_fname = fname..'out'
require('FTerm').scratch({
cmd = { exec, buf, '-o', '&&', './'..cbin_fname }
})
end
end
end)
But this didn't work what I expect. The result is same as cmd = { exec, buf }
, just compile to a default a.out
file, and didn't executed.
Then I tried this to only execute a.out
:
local runners = { c = 'gcc', cpp = 'g++' }
vim.keymap.set('n', '<leader><Enter>', function()
local buf = vim.api.nvim_buf_get_name(0)
local ftype = vim.filetype.match({ filename = buf })
local exec = runners[ftype]
if exec ~= nil then
if exec == 'c' then
require('FTerm').scratch({
cmd = { exec, buf, '&&', './a.out' }
})
end
end
end)
This had same result as I firstly tried. So I wonder to know how to set commands to auto compile and run statically-typed language.
Hello,
I am currently trying to configure FTerm.
Whenever I execute the keybind for toggling FTerm i get this error message
E5108: Error executing lua [string ":lua"]:1: module 'FTerm' not found: no field package.preload['FTerm'] no file './FTerm.lua' no file '/opt/homebrew/Cellar/luajit-openresty/20210510/share/luajit-2.1.0-beta3/FTerm.lua' no file '/usr/local/share/lua/5.1/FTerm.lua' no file '/usr/local/share/lua/5.1/FTerm/init.lua' no file '/opt/homebrew/Cellar/luajit-openresty/20210510/share/lua/5.1/FTerm.lua' no file '/opt/homebrew/Cellar/luajit-openresty/20210510/share/lua/5.1/FTerm/init.lua' no file './FTerm.so' no file '/usr/local/lib/lua/5.1/FTerm.so' no file '/opt/homebrew/Cellar/luajit-openresty/20210510/lib/lua/5.1/FTerm.so' no file '/usr/local/lib/lua/5.1/loadall.so'
Now, I already deleted my whole nvim/state folder, reinstalled all of my Plugins, ran
:PackerSync
and PackerInstall
which tells me that FTerm is installed btw.
I'll have to keep using floaterm until this issue is fixed;
Hey hi, will this plugin get multiple terminal float windows just like vim-floaterm
Reproduce:
Start nvim and execute :split
, we can use <C-w>p
or :wincmd p
to switch to previous window.
Open and close a float term, we can't switch back to previous window, because it's overwritten by the closed floating window which is not what we expected.
The terminal's empty when you reopen it in another session.
To reproduce:
I assume this is caused by session-lens removing the buffer.
Many thanks for this plugin ๐
First of all thank you very much for the great plugin!
I am creating a terminal instance where a pass a certain custom command as per the docs: in particular a minimal reproducible example can be thought of as
local function hello()
return fterm:new({ cmd = 'echo "hello"' })
end
vim.keymap.set('n', '<A-g>', function()
hello():toggle()
end)
This works fine when toggling the terminal in normal mode, however whilst in terminal mode (with the command already toggled and the custom terminal already active) the only way to close it is via q
rather than via <A-g>
again. If I explicitly define a command in terminal mode as shown
vim.keymap.set('t', '<A-g>', '<C-\\><C-n><CMD>lua hello()<CR>')
I get exceptions of "attempt to index a boolean value" (also if I fully qualify the path to the custom function fully requiring the whole module). I wonder if the object fterm:new()
really returns a toggleable instance, or perhaps I am merely making silly grammar mistakes while defining the keymap in terminal mode?
I want known how can i get something done like :FloatermNew --autoclose=0 gcc % -o %< && ./%:h
, i know there's require("FTerm").run
but i don't know , how can i get current buffer name , current buffer name without extension , current line number or something else . anyone knows if there a help manual?
One thing that I really like about nvim-tree.lua is that when ever I try to open a file inside its window, it'll open it up inside another window.
This behavior is extremely helpful especially in a terminal window. I have git setup to open the COMMIT buffer directly in neovim when it is a subprocess of another neovim process (rather than having a new instance of neovim nested in the integrated terminal) but my problem is that right after I run git commit
to edit my commit message in neovim, the buffer will be opened inside the floating terminal window instead of a sensible window for example a window that contains a buffer with vim.bo.buftype
equal to ""
if in docker ( docker run --rm -ti ubuntu:21.04 sh ), there is no SHELL
env set, the plugin stopped to work:
site/pack/packer/start/FTerm.nvim/lua/FTerm/config.lua:30: attempt to index local 'str' (a nil value)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.