Skip to content

habamax/vim-sendtoterm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

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)

What about Ctrl-Enter to send current line (probably would not work for all terminals)?

vimrc
nmap <C-CR> <Plug>(SendToTermLine)

What if I want my cursor to go to the next non-empty line after current line was sent to terminal?

vimrc
nmap <C-CR> <Plug>(SendToTermLine)j:call search('^\s*\S.*', 'W')<CR>

By default all tabs are converted to spaces and if you don’t want it:

let g:sendtoterm_expandtab = 0

About

Send text to a builtin vim :terminal

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published