Ⅰ. 插件描述
wrapper for Vim's ':terminal' commandⅡ. 基本信息
|
Ⅲ. 安装方法
使用Vundle管理器安装
在你的.vimrc下添加:Plugin 'lxhillwind/terminal-wrapper'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall
对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。
使用NeoBundle管理器安装
在你的.vimrc下添加:NeoBundle 'lxhillwind/terminal-wrapper'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall
使用VimPlug管理器安装
在你的.vimrc下添加:Plug 'lxhillwind/terminal-wrapper'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall
使用Pathogen管理器安装
在终端中运行以下命令:cd ~/.vim/bundle
git clone https://github.com/lxhillwind/terminal-wrapper
Ⅳ. 文档说明
# terminal-wrapper
wrapper for vim's ':terminal' command
Warning
This repository is archived, since this plugin is not used by me anymore.
It is a pain to maintain a wrapper for :terminal command for both vim 8 and
neovim.
I also find that it's easier to use shell outside vim window, so I write a
vim command to open a new tmux window with current directory,
and a wrapper to do the compile (to a binary in temporary directory) and run loop
(run filename [optional compiler args] -- [optional args]), which fit my
need and replace this vim plugin.
Requirement
neovim, or vim where has('terminal') == 1.
Introduction
This plugin introduces an expand rule: ^E and two command: :Run, :KRun.
^E
You may already know that when executing some command like this: :!echo %,
the % will be expanded to current filename. In this plugin, ^E
(by pressing <Ctrl-v><Ctrl-e>) works like this, with proper filename escape
and various expansion:
If command is like this: :!cat %, and filename contains <Space>, then it
won't work as expected. :Run cat % won't work either. You should use:Run cat ^E{%} to make % (current filename) expanded to escaped filename.
The xxx in ^E{xxx} will be expanded using Vim's expand() andfnameescape() functions.
Run
:Run is similar to :!, except that it executes given command in a terminal
inside vim window. This means that you can run a command asynchronously!
KRun
:KRun is an abbreviation for something like this:
If your current editing file is a Python source named 'somename.py', then you
can run :KRun args1 args2 ..., which will be translated to:Run python ^E{%} args1 args2 ....
Which program to run depends on your configuration (variableg:terminal_wrapper#cmd):
" default config:
" dictionary of: &ft, command
" '^E{ARGS}' in command will be translated to arguments after `:KRun`
let s:predefined_command =
\{
\'c': 'cc ^E{%} -o ^E{%:p:r} && ^E{%:p:r} ^E{ARGS}',
\'go': 'go run ^E{%} ^E{ARGS}',
\'javascript': 'node ^E{%} ^E{ARGS}',
\'perl': 'perl ^E{%} ^E{ARGS}',
\'python': 'python ^E{%} ^E{ARGS}',
\'rust': 'cargo run -- ^E{ARGS}',
\'scheme': 'racket -r ^E{%} ^E{ARGS}',
\'typescript': 'tsc ^E{%} && node ^E{%:p:r}.js ^E{ARGS}',
\}
" you can override it like this:
let g:terminal_wrapper#cmd =
\{
\'python': 'python3 ^E{%} ^E{ARGS}',
\}
" or if you have defined dict g:terminal_wrapper#cmd
let g:terminal_wrapper#cmd['c'] = 'cc ^E{%} -o ^E{%:p:r} && ^E{%:p:r} ^E{ARGS}'Install
Any famous vim plugin manager should work.
cmd vs shell
This plugin behaves like neovim's :terminal command, which means that you
can type like in a real shell after :Run and :KRun; which shell to run
depends on &shell and &shellcmdflag.
More precisely, it behaves like that you are typing:
/bin/bash -c 'your command goes here' # '/bin/bash -c' may varyor on Windows:
cmd /c "your command goes here"NOTE
To make README.md readable on GitHub, I have translated all ^E
(<Ctrl-v><Ctrl-e>, whose ASCII code is 5) to literal string: '^' + 'E'.