Home

Awesome

Use (neo)vim terminal in the floating/popup window.

CI GitHub license Maintenance

Features

Requirements

Installation

use 'voldikss/vim-floaterm'

Plug 'voldikss/vim-floaterm'
call dein#add('voldikss/vim-floaterm')

Get Started

Use :FloatermNew to open a terminal window, use :FloatermToggle to hide/reopen that. The filetype of the terminal buffer is 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.

❗️Note: Long-running jobs (e.g. yarn watch) inside the builtin terminal would probably slowdown your operation. It's recommended to put them into the external terminals.

Commands

:FloatermNew[!] [options] [cmd] Open a floaterm window.

For example, the command

:FloatermNew --height=0.6 --width=0.4 --wintype=float --name=floaterm1 --position=topleft --autoclose=2 ranger --cmd="cd ~"

will open a new floating/popup floaterm instance named floaterm1 running ranger --cmd="cd ~" in the topleft corner of the main window.

The following command allows you to compile and run your C code in the floaterm window:

:FloatermNew --autoclose=0 gcc % -o %< && ./%<

:FloatermPrev Switch to the previous floaterm instance

:FloatermNext Switch to the next floaterm instance

:FloatermFirst Switch to the first floaterm instance

:FloatermLast Switch to the last floaterm instance

:FloatermUpdate [options] Update floaterm window attributes(height, width, etc.).

:[N]FloatermToggle[!] [floaterm_name] Open or hide the floaterm window.

:[N]FloatermShow[!] [floaterm_name] Show the current floaterm window.

:[N]FloatermHide[!] [floaterm_name] Hide the current floaterms window.

:[N]FloatermKill[!] [floaterm_name] Kill the current floaterm instance

:FloatermSend[!] [--name=floaterm_name] [cmd] Send command to a job in floaterm.

Options

g:floaterm_shell

Type String. Default: &shell

g:floaterm_title

Type String. Show floaterm info(e.g., 'floaterm: 1/3' implies there are 3 floaterms in total and the current is the first one) at the top left corner of floaterm window.

Default: 'floaterm: $1/$2'($1 and $2 will be substituted by 'the index of the current floaterm' and 'the count of all floaterms' respectively)

Example: 'floaterm($1|$2)'

g:floaterm_wintype

Type String. 'float'(nvim's floating or vim's popup) by default. Set it to 'split' or 'vsplit' if you don't want to use floating or popup window.

g:floaterm_width

Type Number (number of columns) or Float (between 0 and 1). If Float, the width is relative to &columns.

Default: 0.6

g:floaterm_height

Type Number (number of lines) or Float (between 0 and 1). If Float, the height is relative to &lines.

Default: 0.6

g:floaterm_position

Type String. The position of the floating window. Available values:

In addition, there is another option 'random' which allows to pick a random position from above when (re)opening a floaterm window.

g:floaterm_borderchars

Type String. 8 characters of the floating window border (top, right, bottom, left, topleft, topright, botright, botleft).

Default: ─│─│┌┐┘└

g:floaterm_rootmarkers

Type List of String. Markers used to detect the project root directory for --cwd=<root> or --cwd=<buffer-root>.

Default: ['.project', '.git', '.hg', '.svn', '.root']

g:floaterm_giteditor

Type Boolean. Whether to override $GIT_EDITOR in floaterm terminals so git commands can open open an editor in the same neovim instance. See git for details. This flag also overrides $HGEDITOR for Mercurial.

Default: v:true

g:floaterm_opener

Type String. Command used for opening a file in the outside nvim from within :terminal.

Available: 'edit', 'split', 'vsplit', 'tabe', 'drop' or user-defined commands

Default: 'split'

g:floaterm_autoclose

Type Number. Whether to close floaterm window once the job gets finished.

Default: 1.

g:floaterm_autohide

Type Number. Whether to hide previous floaterms before switching to or opening a another one.

Default: 1.

g:floaterm_autoinsert

Type Boolean. Whether to enter Terminal-mode after opening a floaterm.

Default: v:true

g:floaterm_titleposition

Type String. The position of the floaterm title.

Available: 'left', 'center', 'right'.

Default: 'left'

Keymaps

This plugin doesn't supply any default mappings. Here are the configuration examples.

" Configuration example
let g:floaterm_keymap_new    = '<F7>'
let g:floaterm_keymap_prev   = '<F8>'
let g:floaterm_keymap_next   = '<F9>'
let g:floaterm_keymap_toggle = '<F12>'

You can also use other keys as shown below:

let g:floaterm_keymap_new = '<Leader>ft'

All options for the mappings are listed below:

Note that the key mappings are set from the plugin/floaterm.vim, so if you are using on-demand loading feature provided by some plugin-managers, the keymap above won't take effect(:help load-plugins). Then you have to define the key bindings by yourself. For example,

nnoremap   <silent>   <F7>    :FloatermNew<CR>
tnoremap   <silent>   <F7>    <C-\><C-n>:FloatermNew<CR>
nnoremap   <silent>   <F8>    :FloatermPrev<CR>
tnoremap   <silent>   <F8>    <C-\><C-n>:FloatermPrev<CR>
nnoremap   <silent>   <F9>    :FloatermNext<CR>
tnoremap   <silent>   <F9>    <C-\><C-n>:FloatermNext<CR>
nnoremap   <silent>   <F12>   :FloatermToggle<CR>
tnoremap   <silent>   <F12>   <C-\><C-n>:FloatermToggle<CR>

Highlights

There are two highlight-groups to specify the color of floaterm (also the border color if g: floaterm_wintype is 'float') window.

To customize, use hi command together with the colors you prefer.

" Configuration example

" Set floaterm window's background to black
hi Floaterm guibg=black
" Set floating window border line color to cyan, and background to orange
hi FloatermBorder guibg=orange guifg=cyan
<details> <summary>Demo</summary> <img src="https://user-images.githubusercontent.com/20282795/91368959-fee00f00-e83c-11ea-9002-cab992d30794.png"/> </details>

Besides, there is a neovim only highlight group which can be used to configure no-current-focused window(:help NormalNC).

" Configuration example

" Set floaterm window foreground to gray once the cursor moves out from it
hi FloatermNC guifg=gray
<details> <summary>Demo</summary> <img src="https://user-images.githubusercontent.com/20282795/91380259-28a62f80-e857-11ea-833f-11160d15647a.gif"/> </details>

Autocmd

autocmd User FloatermOpen        " triggered after opening a new/existed floaterm

Advanced Topics

Use with command line tools

The following cases should work both in Vim and NeoVim unless otherwise specifically noted.

floaterm

Normally if you run vim/nvim somefile.txt within the builtin terminal, you would get another nvim/vim instance running in the subprocess.

Floaterm, which is a builtin script in this plugin, allows you to open files from within : terminal without starting a nested nvim. To achieve that, just literally replace vim/nvim with floaterm, e.g. floaterm somefile.txt

P.S.

<details> <summary>Demo</summary> <img src="https://user-images.githubusercontent.com/20282795/91380257-27750280-e857-11ea-8d49-d760c009fee0.gif"/> </details>

git

Execute git commit in the terminal window without starting a nested vim/nvim.

Refer to g:floaterm_giteditor to disable this behavior.

Refer to g:floaterm_opener for configurable open action

<details> <summary>Demo</summary> <img src="https://user-images.githubusercontent.com/20282795/91380268-2cd24d00-e857-11ea-8dbd-d39a0bbb105e.gif"/> </details>

fzf

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:

command! FZF FloatermNew fzf
<details> <summary>Demo</summary> <img src="https://user-images.githubusercontent.com/20282795/107140144-10d0ec80-695b-11eb-8c2f-8bd42ae26e6d.gif"/> </details>

ripgrep

Requirements:

This plugin has implemented a wrapper for rg command.

Try :FloatermNew rg or create yourself a new command like this:

command! Rg FloatermNew --width=0.8 --height=0.8 rg

or map via .vimrc

" Hotkey: \ + rg
nmap <leader>rg :Rg<CR>
<details> <summary>Demo</summary> You can use <button>Alt-A</button> to select all files and <button>Alt-D</button> to deselect them. Use <button>Ctrl-/</button> to toggle preview. <img src="https://user-images.githubusercontent.com/20282795/107148083-4c37df00-698c-11eb-80fb-ccfd94fc4419.gif"/> </details>

broot

This plugin has implemented a wrapper for broot.

Try :FloatermNew broot or create yourself a new command like this:

command! Broot FloatermNew --width=0.8 --height=0.8 broot
<details> <summary>Demo</summary> <img src="https://user-images.githubusercontent.com/20282795/109648379-83696c80-7b95-11eb-8776-071b816cce2d.gif"/> </details>

fff

There is also an fff wrapper

Try :FloatermNew fff or define a new command:

command! FFF FloatermNew fff
<details> <summary>Demo</summary> <img src="https://user-images.githubusercontent.com/1472981/75105718-9f315d00-567b-11ea-82d1-6f9a6365391f.gif"/> </details>

nnn

There is also an nnn wrapper

Try :FloatermNew nnn or define a new command:

command! NNN FloatermNew nnn
<details> <summary>Demo</summary> <img src="https://user-images.githubusercontent.com/20282795/91380278-322f9780-e857-11ea-8b1c-d40fc91bb07d.gif"/> </details>

xplr

There is also an xplr wrapper

Try :FloatermNew xplr or define a new command:

command! XPLR FloatermNew xplr
<details> <summary>Demo</summary> <img src="https://s4.gifyu.com/images/ft-xplr9173d6a849e3f6b9.gif"/> </details>

lf

There is also an lf wrapper. It is recommened to use lf.vim which is an lf wrapper with more features (Overriding netrw, Lfcd, etc.).

Try :FloatermNew lf or define a new command:

command! LF FloatermNew lf
<details> <summary>Demo</summary> <img src="https://user-images.githubusercontent.com/20282795/91380274-3065d400-e857-11ea-86df-981adddc04c6.gif"/> </details>

ranger

This plugin can also be a handy ranger plugin since it also has a ranger wrapper

Try :FloatermNew ranger or define a new command:

command! Ranger FloatermNew ranger
<details> <summary>Demo</summary> <img src="https://user-images.githubusercontent.com/20282795/91380284-3360c480-e857-11ea-9966-34856592d487.gif"/> </details>

joshuto

This plugin can also be a handy joshuto plugin since it also has a joshuto wrapper

Try :FloatermNew joshuto or define a new command:

command! Joshuto FloatermNew joshuto

vifm

There is also a vifm wrapper

Try :FloatermNew vifm or define a new command:

command! Vifm FloatermNew vifm
<details> <summary>Demo</summary> <img src="https://user-images.githubusercontent.com/43941510/77137476-3c888100-6ac2-11ea-90f2-2345c881aa8f.gif"/> </details>

yazi

There is also a yazi wrapper

Try :FloatermNew yazi or define a new command:

command! Yazi FloatermNew yazi

lazygit

Furthermore, you can also use other command-line programs, such as lazygit, htop, ncdu, etc.

Use lazygit for instance:

<details> <summary>Demo</summary> <img src="https://user-images.githubusercontent.com/20282795/74755376-0f239a00-52ae-11ea-9261-44d94abe5924.png"/> </details>

python

Use :FloatermNew python to open a python shell. After that you can use : FloatermSend to send lines to the Python interactive shell.

Or you can just select lines and execute :'<,'>FloatermNew --wintype=split python, then the selected lines will be sent and executed once a python repl floaterm window is opened.

This can also work for other languages which have interactive shells, such as lua, node, etc.

<details> <summary>Demo</summary> <img src="https://user-images.githubusercontent.com/20282795/91380286-352a8800-e857-11ea-800c-ac54efa7dd72.gif"/> </details>

Use with other plugins

vim-clap

Use vim-clap to switch/preview floating terminal buffers.

Install clap-floaterm and try :Clap floaterm

<details> <summary>Demo</summary> <img src="https://user-images.githubusercontent.com/20282795/91380243-217f2180-e857-11ea-9f64-46e8676adc11.gif"/> </details>

denite.nvim

Use denite to switch/preview/open floating terminal buffers.

Install denite-floaterm and try :Denial floaterm

<details> <summary>Demo</summary> <img src="https://user-images.githubusercontent.com/1239245/73604753-17ef4d00-45d9-11ea-967f-ef75927e2beb.gif"/> </details>

coc.nvim

Use CocList to switch/preview/open floating terminal buffers.

Install coc-floaterm and try :CocList floaterm

<details> <summary>Demo</summary> <img src="https://user-images.githubusercontent.com/20282795/91380254-25ab3f00-e857-11ea-9733-d0ae5a954848.gif"/> </details>

fzf

Install fzf-floaterm and try :Floaterms

LeaderF

Install LeaderF-floaterm and try :Leaderf floaterm

asynctasks.vim | asyncrun.vim

This plugin can be a runner for asynctasks.vim or asyncrun.vim. See asyncrun.extra for the installation and usage.

<details> <summary>Demo</summary> <img src="https://user-images.githubusercontent.com/20282795/104123344-b3f70c00-5385-11eb-9f61-0a5703ba78f5.gif"/> </details>

How to define more wrappers

The wrapper script must be located in autoload/floaterm/wrapper/ directory, e.g., autoload/floaterm/wrapper/fzf.vim.

There are two ways for a command to be spawned:

How to write sources for fuzzy finder plugins

Function floaterm#buflist#gather() returns a list contains all the floaterm buffers.

Function floaterm#terminal#open_existing({bufnr}) opens the floaterm whose buffer number is {bufnr}.

For reference, see floaterm source for LeaderF.

Contributing

FAQ

https://github.com/voldikss/vim-floaterm/issues?q=label%3AFAQ

Breaking Changes

https://github.com/voldikss/vim-floaterm/issues?q=label%3A%22breaking+change%22

Related projects

Credits

License

MIT