Skip to content

a vim/nvim plugin to simply send lines to terminal

Notifications You must be signed in to change notification settings

shawnchenx6/vimTermPipe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 

Repository files navigation

vimTermPipe

demo a vim/nvim plugin to simply send lines to terminal

This plugin is tested on windows 10 nvim. I am python and R user. So python, ipthon, R and radian are tested.

How to install

Either use a plugin manager such as Vim-Plug or copy the directories and their files to your ~/.vim or ~/.config/nvim directory.

Main function

Send line/lines

You can send one single line, code blocks and selection to the terminal (default binding <C-Enter>)

  1. send one line in the normal mode, press <C-Enter>
  2. send code block put the cursor at the first line of a code block, press <C-Enter>

The block is defined as follows:

def foo():
    return 1

a = [1,2,
    3,4,5]

a = [1,2,
    3,4,5
]

a = (1,2,3,
    4,5
)

for i in range(10):
    print(i)
foo = function(x){
    return 1
}
for i in list:
    echo i
endif

  1. If the automatic code block is not what you want. You can send selection to the terminal.

Use visual mode to select the lines and press <C-Enter> to send selection to the terminal.

Note :If your selection is within the same line, you can send the selected piece of code to the terminal. If your selection covers more than 1 line, the complete lines are sent.

mulitiple terminal Binding

  1. This plugin support multiple terminals binding. The binding happens when you press <C-Enter>. If no terminal is binded to the current buffer, this plugin will automatically bind the current buffer to the most newly opened terminal. So you can bind each buffer to different terminals and send code respectively. (say you have a python file and R file. you can open a python session and R session in terminal. python code goes to the python session and R code goes to the R session.)

  2. If the automatic binding didn't bind the buffer to the terminal you want you can use the :LinkTerm to change binding. say the terminal buffer number you want to bind is 3, put the cursor in the code buffer, type :LinkTerm 3 to link the buffer to the terminal.

Usage

  1. put the following line to your vimrc file
nmap <C-Enter> <Plug>SendBlock
vmap <C-Enter> <Plug>SendSelection
  1. open a code file , say hello.py
  2. use :split to split the window
  3. open a terminal using :terminal, type python or ipython in the termial to start a python session
  4. now go back to the file and put the cursor at the line you want to send, press <C-Enter>

** for multiple terminal binding**

  1. spit a window, open a file, say hello.R
  2. split a window and open terminal
  3. go back to the file and put the cursor, press <C-Enter>

Happy vim! Feel free to star and fork.

About

a vim/nvim plugin to simply send lines to terminal

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published