You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
NeoVim supporting floating window is better, but not necessary
Run :checkhealth to check the environment.
Installation
vim-plug
Plug 'voldikss/vim-floaterm'
dein.nvim
calldein#add('voldikss/vim-floaterm')
Basic Usage
Use :FloatermNew command to open a terminal window, use :FloatermToggle to hide/reopen that. The filetype of the terminal buffer is set to floaterm.
If you've opened multiple floaterm instances, they will be attached to a double-circular-linkedlist. Then you can use :FloatermNext or :FloatermPrev to switch between them.
Commands
:FloatermNew [options] [cmd] Open a floaterm window.
If cmd exists, it will be executed automatically after the shell startup.
The options is formed as key=value, it is used to specify some attributes of the floaterm instance, including height, width, wintype, position and name.
:FloatermToggle [floaterm_name] Open or hide the floaterm window.
If floaterm_name exists, toggle the floaterm instance whose name attribute is floaterm_name.
Use <TAB> to get completion.
:FloatermPrev Switch to the previous floaterm instance
:FloatermNext Switch to the next floaterm instance
:FloatermSend [floaterm_name] Send selected lines to a job in floaterm.
If floaterm_name exists, send to the floaterm instance whose name is floaterm_name.
Use <TAB> to get completion.
Typically this command is executed with a range. i.e., :'<,'>FloatermSend, if no ranges, send the current line.
Also you may try :FloatermSend! and :'<,'>FloatermSend!, the former trims the whitespace in the begin of the line, and the latter removes the whitespace but still keeps the indent.
Global variables
g:floaterm_wintype
Type string. 'floating'(neovim only) by default. Set it to 'normal' if your vim/nvim doesn't support floatwin.
g:floaterm_width
Type int (number of columns) or float (between 0 and 1). If float, the width is relative to &columns. Default: 0.6
g:floaterm_height
Type int (number of lines) or float (between 0 and 1). If float, the height is relative to &lines. Default: 0.6
g:floaterm_winblend
Type int. The transparency of the floating terminal. Default: 0
g:floaterm_position
Type string. The position of the floating window. Available values:
If wintype is normal: 'top', 'right', 'bottom', 'left'. Default: 'bottom'
If wintype is floating: 'top', 'right', 'bottom', 'left', 'center', 'topleft', 'topright', 'bottomleft', 'bottomright', 'auto'(at the cursor place). Default: 'center'
g:floaterm_borderchars
Type array of string. Characters of the floating window border.
Default: ['─', '│', '─', '│', '┌', '┐', '┘', '└']
g:floaterm_rootmarkers
Type array of string. If not empty, floaterm will be opened in the project root directory.
Note that this key mapping is installed from the plugin directory, so if you use on-demand loading provided by some plugins-managers, the keymap above won't take effect(:help load-plugins). Then you have to define the key bindings yourself by putting the code used to define the key bindings in your vimrc. For example,
This plugin provides two highlight-groups to specify the background/foreground color of floaterm (also the border color if g:floaterm_wintype is 'floating') window.
By default, they are both linked to NormalFloat. To customize, use hi command together with the colors you prefer.
" Configuration example" Set floaterm window's background to blackhi FloatermNF guibg=black" Set floating window border line color to cyan, and background to orangehi FloatermBorderNF guibg=orange guifg=cyan
More use cases and demos
vim-floaterm is a nvim/vim terminal plugin, it can run all the command-line programs in the terminal even nvim/vim itself.
❗️Note: The following cases should work both in NeoVim and Vim, if some of them don't work on Vim, try startuping Vim with --servername argument, i.e., vim --servername /tmp/vimtmpfile
General
Requirements: pip3 install neovim-remote
Normally if you run vim/nvim somefile.txt within a builtin terminal, you will get another nvim/vim instance running in the subprocess. This plugin allows you to open files from within :terminal without starting a nested nvim process. To archive that, just replace vim/nvim with floaterm, i.e., floaterm somefile.txt
Use as the git editor
See g:floaterm_gitcommit option.
Execute git commit in the terminal window without starting a nested nvim.
Use as an fzf plugin
This plugin has implemented a wrapper for fzf command. So it can be used as a tiny fzf plugin.
Try :FloatermNew fzf or even wrap this to a new command like this:
This plugin has a builtin runner for asynctasks.vim. To use it, set g:asynctasks_term_pos to "floaterm" or add a "pos=floaterm" filed in your asynctasks configuration files. Then your task will be ran in the floaterm instance. See asynctasks.vim Wiki for more information.
If you are using on-demand loading, you need to copy the following lines to your vimrc to make it work.
The code above returns an array. floaterm $(fzf) is the command to be executed. v:true means the command will be executed after the &shell startup.
To be executed through termopen()/term_start() function, in this case, a callback function is allowed. See ranger wrapper
function!floaterm#wrapper#ranger#() abortlets:ranger_tmpfile=tempname()
let cmd ='ranger --choosefiles=' . s:ranger_tmpfilereturn [cmd, {'on_exit': funcref('s:ranger_callback')}, v:false]
endfunctionfunction!s:ranger_callback(...) abortiffilereadable(s:ranger_tmpfile)
let filenames =readfile(s:ranger_tmpfile)
if!empty(filenames)
callfloaterm#hide()
for filename in filenames
execute'edit ' . fnameescape(filename)
endforendifendifendfunction
Here v:false means cmd will be passed through termopen()(neovim) or term_start()(vim). Function s:ranger_callback() will be invoked when the cmd exits.
How to write sources for fuzzy finder plugins
Function floaterm#buflist#gather() returns a list contains all the floaterm buffers.
Function floaterm#terminal#open({bufnr}) opens the floaterm whose buffer number is bufnr.
【Introduction in Chinese|中文文档】
Use neovim terminal in the floating window.
Features
Requirements
Vim or NeoVim with
terminal
featureNeoVim supporting
floating window
is better, but not necessaryRun
:checkhealth
to check the environment.Installation
Plug 'voldikss/vim-floaterm'
Basic Usage
Use
:FloatermNew
command to open a terminal window, use:FloatermToggle
to hide/reopen that. The filetype of the terminal buffer is set tofloaterm
.If you've opened multiple floaterm instances, they will be attached to a double-circular-linkedlist. Then you can use
:FloatermNext
or:FloatermPrev
to switch between them.Commands
:FloatermNew [options] [cmd]
Open a floaterm window.cmd
exists, it will be executed automatically after the shell startup.options
is formed askey=value
, it is used to specify some attributes of the floaterm instance, includingheight
,width
,wintype
,position
andname
.height
seeg:floaterm_height
width
seeg:floaterm_width
wintype
seeg:floaterm_wintype
position
seeg:floaterm_position
name
name of the floaterm<TAB>
to get completion.For example, command
will open a new
floating
floaterm instance namedfloaterm1
runningranger --cmd="cd ~"
in thetopleft
corner of the main window.:FloatermUpdate [options]
Update floaterm window attributes(height
,width
, etc.).options
is the same as in:FloatermNew
.<TAB>
to get completion.:FloatermToggle [floaterm_name]
Open or hide the floaterm window.floaterm_name
exists, toggle the floaterm instance whosename
attribute isfloaterm_name
.<TAB>
to get completion.:FloatermPrev
Switch to the previous floaterm instance:FloatermNext
Switch to the next floaterm instance:FloatermSend [floaterm_name]
Send selected lines to a job in floaterm.floaterm_name
exists, send to the floaterm instance whosename
isfloaterm_name
.<TAB>
to get completion.Typically this command is executed with a range. i.e.,
:'<,'>FloatermSend
, if no ranges, send the current line.Also you may try
:FloatermSend!
and:'<,'>FloatermSend!
, the former trims the whitespace in the begin of the line, and the latter removes the whitespace but still keeps the indent.Global variables
g:floaterm_wintype
Type
string
.'floating'
(neovim only) by default. Set it to'normal'
if your vim/nvim doesn't supportfloatwin
.g:floaterm_width
Type
int
(number of columns) orfloat
(between 0 and 1). Iffloat
, the width is relative to&columns
. Default:0.6
g:floaterm_height
Type
int
(number of lines) orfloat
(between 0 and 1). Iffloat
, the height is relative to&lines
. Default:0.6
g:floaterm_winblend
Type
int
. The transparency of the floating terminal. Default:0
g:floaterm_position
Type
string
. The position of the floating window. Available values:wintype
isnormal
:'top'
,'right'
,'bottom'
,'left'
. Default:'bottom'
wintype
isfloating
:'top'
,'right'
,'bottom'
,'left'
,'center'
,'topleft'
,'topright'
,'bottomleft'
,'bottomright'
,'auto'(at the cursor place)
. Default:'center'
g:floaterm_borderchars
Type
array of string
. Characters of the floating window border.Default:
['─', '│', '─', '│', '┌', '┐', '┘', '└']
g:floaterm_rootmarkers
Type
array of string
. If not empty, floaterm will be opened in the project root directory.Example:
['.project', '.git', '.hg', '.svn', '.root', '.gitignore']
, Default:[]
g:floaterm_autoinsert
Type
bool
. Enter terminal mode after opening a floaterm. Default:v:true
g:floaterm_open_command
Type
string
. Command used for opening a file from within:terminal
.Available:
'edit'
,'split'
,'vsplit'
,'tabe'
,'drop'
. Default:'edit'
g:floaterm_gitcommit
Type
string
. Opening strategy for runninggit commit
in floaterm window.Available:
'floaterm'
(opengitcommit
file in the floaterm window),'split'
,'vsplit'
,'tabe'
.Default:
v:null
which means this is disabled by default(use your own$GIT_EDITOR
).Keymaps
This plugin doesn't supply any default mappings. To use a recommended mappings, put the following code in your
vimrc
.You can also use other keys as shown below:
Note that this key mapping is installed from the plugin directory, so if you use on-demand loading provided by some plugins-managers, the keymap above won't take effect(
:help load-plugins
). Then you have to define the key bindings yourself by putting the code used to define the key bindings in yourvimrc
. For example,Change highlight
This plugin provides two
highlight-groups
to specify the background/foreground color of floaterm (also the border color ifg:floaterm_wintype
is'floating'
) window.By default, they are both linked to
NormalFloat
. To customize, usehi
command together with the colors you prefer.More use cases and demos
vim-floaterm is a nvim/vim terminal plugin, it can run all the command-line programs in the terminal even
nvim/vim
itself.❗️Note: The following cases should work both in NeoVim and Vim, if some of them don't work on Vim, try startuping Vim with
--servername
argument, i.e.,vim --servername /tmp/vimtmpfile
General
Requirements:
pip3 install neovim-remote
Normally if you run
vim/nvim somefile.txt
within a builtin terminal, you will get another nvim/vim instance running in the subprocess. This plugin allows you to open files from within:terminal
without starting a nested nvim process. To archive that, just replacevim/nvim
withfloaterm
, i.e.,floaterm somefile.txt
Use as the git editor
See
g:floaterm_gitcommit
option.Execute
git commit
in the terminal window without starting a nested nvim.Use as an fzf plugin
This plugin has implemented a wrapper for fzf command. So it can be used as a tiny fzf plugin.
Try
:FloatermNew fzf
or even wrap this to a new command like this:Use as an fff plugin
There is also an fff wrapper
Try
:FloatermNew fff
or define a new command:Use as an nnn plugin
There is also an nnn wrapper
Try
:FloatermNew nnn
or define a new command:Use as an lf plugin
There is also an lf wrapper
Try
:FloatermNew lf
or define a new command:Use as a ranger plugin
This plugin can also be a handy ranger plugin since it also has a ranger wrapper
Try
:FloatermNew ranger
or define a new command:Use as a Vifm plugin
There is also a vifm wrapper
Try
:FloatermNew vifm
or define a new command:Use as a Python REPL plugin
Use
:FloatermNew python
to open a python REPL. After that you can use:FloatermSend
to send lines to the Python interactive shell.This can also work for other languages which have interactive shells, such as lua, node, etc.
Use with other command line tools
Furthermore, you can also use other command-line programs, such as lazygit, htop, ncdu, etc.
Use
lazygit
for instance:Integrate with vim-clap
Use vim-clap to switch/preview floating terminal buffers.
Try
:Clap floaterm
Integrate with denite.nvim
Use denite to switch/preview/open floating terminal buffers.
Try
:Denite floaterm
Integrate with coc.nvim
Use CocList to switch/preview/open floating terminal buffers.
Install coc-floaterm and try
:CocList floaterm
Integrate with asynctasks.vim
This plugin has a builtin runner for asynctasks.vim. To use it, set
g:asynctasks_term_pos
to"floaterm"
or add a"pos=floaterm"
filed in your asynctasks configuration files. Then your task will be ran in the floaterm instance. See asynctasks.vim Wiki for more information.If you are using on-demand loading, you need to copy the following lines to your
vimrc
to make it work.How to define more wrappers
There are two ways for a command to be spawned:
To be executed after
&shell
was startup. see fzf wrapperThe code above returns an array.
floaterm $(fzf)
is the command to be executed.v:true
means the command will be executed after the&shell
startup.To be executed through
termopen()
/term_start()
function, in this case, a callback function is allowed. See ranger wrapperHere
v:false
meanscmd
will be passed throughtermopen()
(neovim) orterm_start()
(vim). Functions:ranger_callback()
will be invoked when thecmd
exits.How to write sources for fuzzy finder plugins
Function
floaterm#buflist#gather()
returns a list contains all the floaterm buffers.Function
floaterm#terminal#open({bufnr})
opens the floaterm whose buffer number isbufnr
.For reference, see floaterm source for vim-clap.
F.A.Q
This plugin leaves an empty buffer on startify window
Put this code in your
vimrc
I want to use another shell in the terminal. (e.g., Use fish instead of bash)
Set
shell
option in yourvimrc
:I would like to customize the style of the floating terminal window
Use
autocmd
. For exampleI want to open normal(non-floating) floaterm in a vsplit window.
Use
:FloatermUpdate
Not starting insert mode after creating a new floaterm...
See option g:floaterm_autoinsert, also #52 might be helpful.
Credits
floaterm executable is modified from vim-terminal-help
Some features require neovim-remote
License
MIT
The text was updated successfully, but these errors were encountered: