【Introduction in Chinese|中文介绍】
Use (neo)vim terminal in the floating/popup window.
- Features
- Requirements
- Installation
- Basic Usage
- Integrate with command line tools
- Integrate with other plugins
- How to define more wrappers
- How to write sources for fuzzy finder plugins
- Wiki
- F.A.Q
- Break changes
- Credits
- License
- NeoVim floatwin and Vim8 popupwin support
- Open and toggle terminal window quickly
- Multiple terminal instances
- Customizable floating terminal style
- Switch/Preview floating terminal buffers using vim-clap, denite.nvim or coc.nvim
- Integrate with other external command-line tools(ranger, lf, fzf, etc.)
- Use as a custom task runner for asynctasks.vim
- Vim or NeoVim with
terminalfeature
Run :checkhealth to check the environment.
- vim-plug
Plug 'voldikss/vim-floaterm'- dein.nvim
call dein#add('voldikss/vim-floaterm')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.
- If
!exists, run program in$SHELL. Try:FloatermNew pythonand:FloatermNew! pythonto learn about the difference. - If
cmddoesn't exist, open$SHELL. - The
optionsis formed as--key[=value], it is used to specify some attributes of the floaterm instance, includingheight,width,wintype,position,nameandautoclose.heightseeg:floaterm_heightwidthseeg:floaterm_widthwintypeseeg:floaterm_wintypepositionseeg:floaterm_positionnamename of the floatermautocloseclose the window after finishing job, seeg:floaterm_autoclose
- Use
<TAB>to get completion.
For example, command
:FloatermNew --height=0.6 --width=0.4 --wintype=floating --name=floaterm1 --position=topleft --autoclose=2 ranger --cmd="cd ~"will open a new floating floaterm instance named floaterm1 running ranger --cmd="cd ~" in the topleft corner of the main window.
- The
optionsis the same as in:FloatermNew. - Use
<TAB>to get completion.
- If
floaterm_nameexists, toggle the floaterm instance whosenameattribute isfloaterm_name. - Use
<TAB>to get completion. - If
!exists, toggle all floaterms
- If
floaterm_nameexists, show the floaterm namedfloaterm_name. - If
!exists, show all floaterms
- If
floaterm_nameexists, show the floaterm namedfloaterm_name. - If
!exists, hide all floaterms
- If
floaterm_nameexists, kill the floaterm instance namedfloaterm_name. - If
!exists, kill all floaterms
- If
--name=floaterm_nameexists, send lines to the floaterm instance whosenameisfloaterm_name. Otherwise use the current floaterm. - If
cmdexists, it will be sent to floaterm and selected lines will be ignored. - This command can also be used with a range, i.e.,
'<,'>:FloatermSend [--name=floaterm_name]to send selected lines to a floaterm.- If
cmdexists, the selected lines will be ignored. - If use this command with a
!, i.e.,'<,'>:FloatermSend! [--name=floaterm_name]the common white spaces in the beginning of lines will be trimmed while the relative indent between lines will still be kept.
- If
- Use
<TAB>to get completion. - Examples
:FloatermSend " Send current line to the current floaterm :FloatermSend --name=ft1 " Send current line to the floaterm named ft1 :FloatermSend ls -la " Send `ls -la` to the current floaterm :FloatermSend --name=ft1 ls -la " Send `ls -la` to the floaterm named ft1 :23FloatermSend ... " Send the line 23 to floaterm :1,23FloatermSend ... " Send lines between line 1 and line 23 to floaterm :'<,'>FloatermSend ... " Send lines selected to floaterm :%FloatermSend ... " Send the whole buffer to floaterm
Type string. Default: &shell
Type string. 'floating'(neovim) or 'popup'(vim) by default. Set it to 'normal' if your vim/nvim doesn't support floatwin or popup.
Type bool. Whether to show floaterm info(e.g., 'floaterm: 1/3') at the top left corner of floaterm window. Default: v:true
Type int (number of columns) or float (between 0 and 1). If float, the width is relative to &columns. Default: 0.6
Type int (number of lines) or float (between 0 and 1). If float, the height is relative to &lines. Default: 0.6
Type int. The transparency of the floating terminal. Only works in neovim. Default: 0
Type string. The position of the floating window. Available values:
- If
wintypeisnormal:'top','right','bottom','left'. Default:'bottom' - If
wintypeisfloatingorpopup:'top','right','bottom','left','center','topleft','topright','bottomleft','bottomright','auto'(at the cursor place). Default:'center'
Type array of string. Characters of the floating window border.
Default: ['─', '│', '─', '│', '┌', '┐', '┘', '└']
Type array of string. If not empty, floaterm will be opened in the project root directory.
Example: ['.project', '.git', '.hg', '.svn', '.root', '.gitignore'], Default: []
Type bool. Enter terminal mode after opening a floaterm. Default: v:true
Type string. Command used for opening a file from within :terminal.
Available: 'edit', 'split', 'vsplit', 'tabe', 'drop'. Default: 'edit'
Type string. Opening strategy for running git commit in floaterm window. Only works in neovim.
Available: 'floaterm'(open gitcommit file in the floaterm window), 'split', 'vsplit', 'tabe'.
Recommended: 'split' or 'vsplit'.
Default: v:null which means this is disabled by default(use your own $GIT_EDITOR).
Type number. Decide whether to close floaterm window once job gets finished.
0: Always do NOT close floaterm window1: Close window if the job exits normally, otherwise stay it with messages like[Process exited 101]2: Always close floaterm window
Default: 1.
Type boolean. Decide whether to hide previous floaterms before switching to or opening a new one.
Default: v:true.
This plugin doesn't supply any default mappings. To use a recommended mappings, put the following code in your vimrc.
" 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>fn'All options for the mappings are listed below:
g:floaterm_keymap_newg:floaterm_keymap_prevg:floaterm_keymap_nextg:floaterm_keymap_hideg:floaterm_keymap_showg:floaterm_keymap_killg:floaterm_keymap_toggle
Note that this key mapping is installed from the plugin directory, so if you use on-demand loading provided by some plugin-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,
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>This plugin provides two highlight-groups to specify the background/foreground color of floaterm (also the border color if g:floaterm_wintype is 'floating' or 'popup') window.
By default, they are both linked to Normal(see detail). 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=cyanBesides, there is a neovim only hi-group which can be used to configure no-current window(:help NormalNC). It's also linked to Normal by default.
" Configuration example
" Set floaterm window background to skyblue once the cursor moves out from it
hi FloatermNC guibg=skyblueBefore you start, if you are using neovim, please make sure that nvr is required, please install it via pip using pip3 install neovim-remote.
The following cases should work both in Vim and NeoVim unless otherwise specifically noted.
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
❗️Note: This is neovim only
See g:floaterm_gitcommit option.
Execute git commit in the terminal window without starting a nested nvim.
❗️Note: This is neovim only
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 fzfThere is also an fff wrapper
Try :FloatermNew fff or define a new command:
command! FFF FloatermNew fffThere is also an nnn wrapper
Try :FloatermNew nnn or define a new command:
command! NNN FloatermNew nnnThere is also an lf wrapper
Try :FloatermNew lf or define a new command:
command! LF FloatermNew lfThis 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 rangerThere is also a vifm wrapper
Try :FloatermNew vifm or define a new command:
command! Vifm FloatermNew vifmFurthermore, you can also use other command-line programs, such as lazygit, htop, ncdu, etc.
Use lazygit for instance:
Use :FloatermNew python to open a python shell. 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 vim-clap to switch/preview floating terminal buffers.
Try :Clap floaterm
Use denite to switch/preview/open floating terminal buffers.
Try :Denite floaterm
Use CocList to switch/preview/open floating terminal buffers.
Install coc-floaterm and try :CocList floaterm
Please refer to the Wiki
This plugin can be a runner for asynctasks.vim. To use it, copy the following code to your vimrc set g:asynctasks_term_pos to "floaterm" or add a "pos=floaterm" filed in your asynctasks configuration files.
function! s:runner_proc(opts)
let curr_bufnr = floaterm#curr()
if has_key(a:opts, 'silent') && a:opts.silent == 1
FloatermHide!
endif
let cmd = 'cd ' . shellescape(getcwd())
call floaterm#terminal#send(curr_bufnr, [cmd])
call floaterm#terminal#send(curr_bufnr, [a:opts.cmd])
stopinsert
if &filetype == 'floaterm' && g:floaterm_autoinsert
call floaterm#util#startinsert()
endif
endfunction
let g:asyncrun_runner = get(g:, 'asyncrun_runner', {})
let g:asyncrun_runner.floaterm = function('s:runner_proc')Then your task will be ran in the floaterm instance. See asynctasks.vim Wiki for more information.
Once you've find a nice command line program which can be used as a wrapper of this plugin, you can either send me a PR or define a personal wrapper for yourself.
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:
-
To be executed after spawning
$SHELL. Here is the old implementation of fzf wrapperfunction! floaterm#wrapper#fzf#() abort return ['floaterm $(fzf)', {}, v:true] endfunction
The code above returns a list.
floaterm $(fzf)is the command to be executed.v:truemeans the command will be executed after the&shellstartup. In this way, the second element of the list must be{}. -
To be executed through
termopen()/term_start()function, in that case, a callback option can be provided. See fzf wrapperfunction! floaterm#wrapper#fzf#(cmd) abort let s:fzf_tmpfile = tempname() let cmd = a:cmd . ' > ' . s:fzf_tmpfile return [cmd, {'on_exit': funcref('s:fzf_callback')}, v:false] endfunction function! s:fzf_callback(...) abort if filereadable(s:fzf_tmpfile) let filenames = readfile(s:fzf_tmpfile) if !empty(filenames) if has('nvim') call floaterm#window#hide_floaterm(bufnr('%')) endif for filename in filenames execute g:floaterm_open_command . ' ' . fnameescape(filename) endfor endif endif endfunction
In the example above, after executing
:FloatermNew fzf, functionfloaterm#wrapper#fzf#will return['fzf > /tmp/atmpfilename', {'on_exit': funcref('s:fzf_callback')}, v:false].Here
v:falsemeanscmd(fzf > /tmp/atmpfilename) will be passed throughtermopen()(neovim) orterm_start()(vim). As a result, an fzf interactive will be opened in a floaterm window. After choosing a file using<CR>, fzf exits and the filepath will be written in/tmp/atmpfilename. Then the functions:fzf_callback()will be invoked to open the file.
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 vim-clap.
-
Put this code in your
vimrcautocmd User Startified setlocal buflisted
-
Use
autocmd. For examplefunction s:floatermSettings() setlocal number " more settings endfunction autocmd FileType floaterm call s:floatermSettings()
-
Use
:FloatermUpdate:FloatermUpdate --wintype=normal --position=right
-
See option g:floaterm_autoinsert, also #52 might be helpful.
-
Because this was firstly developed based on nvim's floating window. But now it supports both floaterm and popup, you can get similar experience in both.
- Change in asynctasks.runner_proc:
call floaterm#hide()=>call floaterm#hide(1, '') - Current floaterm will be hidden by default before opening a new one or switching to prev/next one using
:FloatermPrevor:FloatermNext. Seeg:floaterm_autohideto get more info. - Current floaterm won't be hidden before switching to prev/next one using
:FloatermPrevor:FloatermNext - Command
:FloatermSend [floaterm_name]=>:FloatermSend [--name=floaterm_name] [cmd] - Use GNU style for cmdline arguments. e.g.,
wintype=normal=>--wintype=normal - Floaterm window won't be closed automatically after finishing job by default, see
g:floaterm_autoclose - Rename:
g:floaterm_type=>g:floaterm_wintype - Rename:
FloatermNF=>Floaterm - Rename:
FloatermBorderNF=>FloatermBorder
-
floaterm executable is modified from vim-terminal-help
-
Some features require neovim-remote
MIT














