vim-sendtoterm
vim-sendtoterm copied to clipboard
Send text to a builtin vim :terminal
= Send text to :terminal :author: Maxim Kim :experimental: :toc: left :toclevels: 3 :icons: font :autofit-option: :sectnums: :sectnumlevels: 4 :source-highlighter: rouge :rouge-style: github :source-linenums-option: :imagesdir: images :doctype: article
Send some text to your R, ruby, elixir (probably many others too) interpreters opened in a vim terminal.
R example
image::img_README_1.png[]
R example in action
image::https://github.com/habamax/habamax.github.io/blob/master/assets/gifs/vim-sendtoterm.gif[Send to term anigif]
== Installation === minpac
.somewhere in .vimrc [source,vim]
call minpac#init() " ... " more plugins " ... call minpac#add('habamax/vim-sendtoterm')
Then :call minpac#update()
to install it.
=== vim-plug .somewhere in .vimrc [source,vim]
call plug#begin('~/.vim/plugged') " ... " more plugins " ... Plug 'habamax/vim-sendtoterm'
call plug#end()
Then :PlugInstall
to install it.
== Usage
=== Send to barebone Windows CMD
. open terminal :term
. type in any other buffer:
+
[source,bat]
dir /w
. <leader>tt
to send current line
. You should see directory list printed in a terminal
=== Send to Interactive Elixir (iex)
. open terminal :term
. run interactive elixir there iex
. in the other buffer type
+
[source,elixir]
(1..100) |> Enum.sum()
. <leader>tt
to send current line to iex
. You should see something like:
+
[source]
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:
[source,elixir] defmodule MyMod do def hello(world) do IO.puts(world) end end MyMod.hello("Hey!")
Press <leader>tip
to send current paragraph to iex
:
[source,text] 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)>
== Settings
To use something else instead of <leader>t
you remap <Plug>(SendToTerm)
s, for example:
.vimrc [source,vim]
xmap r <Plug>(SendToTerm)
nmap r <Plug>(SendToTerm)
omap r <Plug>(SendToTerm)
nmap rr <Plug>(SendToTermLine)
What about Ctrl-Enter
to send current line (probably would not work for all terminals)?
.vimrc [source,vim]
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 [source,vim]
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