kalmiz / vim-sendtoterm

Send text to a builtin vim :terminal

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Send text to :terminal

Send some text to your R, ruby, elixir (probably many others too) interpreters opened in a vim terminal.

R example

img README 1

R example in action

Send to term anigif
Note
Vim 8+ only.

1. Installation

1.1. minpac

somewhere in .vimrc
call minpac#init()
" ...
" more plugins
" ...
call minpac#add('habamax/vim-sendtoterm')

Then :call minpac#update() to install it.

1.2. vim-plug

somewhere in .vimrc
call plug#begin('~/.vim/plugged')
" ...
" more plugins
" ...
Plug 'habamax/vim-sendtoterm'

call plug#end()

Then :PlugInstall to install it.

2. Usage

2.1. Send to barebone Windows CMD

  1. open terminal :term

  2. type in any other buffer:

    dir /w
  3. <leader>tt to send current line

  4. You should see directory list printed in a terminal

2.2. Send to Interactive Elixir (iex)

  1. open terminal :term

  2. run interactive elixir there iex

  3. in the other buffer type

    (1..100) |> Enum.sum()
  4. <leader>tt to send current line to iex

  5. You should see something like:

    Interactive Elixir (1.8.1) - press Ctrl+C to exit (type h() ENTER for help)
    iex(1)> (1..100) |> Enum.sum()
    5050
    iex(2)>

You can also use other text objects:

defmodule MyMod do
  def hello(world) do
    IO.puts(world)
  end
end
MyMod.hello("Hey!")

Press <leader>tip to send current paragraph to iex:

iex(2)> defmodule MyMod do
  def hello(world) do
...(2)>     IO.puts(world)
...(2)>   end
end
...(2)> MyMod.hello("Hey!")
...(2)> {:module, MyMod,
 <<70, 79, 82, 49, 0, 0, 4, 88, 66, 69, 65, 77, 65, 116, 85, 56, 0, 0, 0, 140,
   0, 0, 0, 15, 12, 69, 108, 105, 120, 105, 114, 46, 77, 121, 77, 111, 100, 8,
   95, 95, 105, 110, 102, 111, 95, 95, 7, ...>>, {:hello, 1}}
iex(3)> Hey!
:ok
iex(4)>

3. Settings

To use something else instead of <leader>t you remap <Plug>(SendToTerm)s, for example:

vimrc
xmap <leader>r  <Plug>(SendToTerm)
nmap <leader>r  <Plug>(SendToTerm)
omap <leader>r  <Plug>(SendToTerm)
nmap <leader>rr <Plug>(SendToTermLine)

About

Send text to a builtin vim :terminal

License:MIT License


Languages

Language:Vim Script 100.0%