Skip to content

Commit e04eb42

Browse files
Fixing visual mode and bracketed paste (#23)
* fixing visual mode and bracketed paste * keeping bracketed paste as default * Added marks to ensure correct cursor positioning * Changed register x to unnamed register * Made a global default and updated documentation Co-authored-by: Will Handley <[email protected]>
1 parent 306c74e commit e04eb42

File tree

4 files changed

+134
-96
lines changed

4 files changed

+134
-96
lines changed

README.rst

+84-60
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,49 @@ Vimteractive
33
============
44
:vimteractive: send commands from text files to interactive programs via vim
55
:Author: Will Handley
6-
:Version: 2.2.0
6+
:Version: 2.2.1
77
:Homepage: https://github.com/williamjameshandley/vimteractive
88
:Documentation: ``:help vimteractive``
99

1010
Vimteractive was inspired by the workflow of the
1111
`vim-ipython <https://github.com/ivanov/vim-ipython>`__ plugin.
1212

13-
This plugin is designed to extend a subset of the functionality of
14-
vim-ipython to other interpreters (including ipython). It is based
15-
around the unix philosophy of `"do one thing and do it
16-
well" <https://en.wikipedia.org/wiki/Unix_philosophy#Do_One_Thing_and_Do_It_Well>`__.
13+
This plugin is designed to extend a subset of the functionality of vim-ipython
14+
to other interpreters (including ipython). It is based around the unix
15+
philosophy of `"do one thing and do it well" <https://en.wikipedia.org/wiki/Unix_philosophy#Do_One_Thing_and_Do_It_Well>`__.
1716
Vimteractive aims to provide a robust and simple link between text files and
1817
interactive interpreters. Vimteractive will never aim to do things like
1918
autocompletion, leaving that to other, more developed tools such as
20-
`YouCompleteMe <https://github.com/Valloric/YouCompleteMe>`__.
19+
`YouCompleteMe <https://github.com/Valloric/YouCompleteMe>`__ or
20+
`TabNine <https://tabnine.com>``.
2121

2222
The activating commands are
2323

2424
- ipython ``:Iipython``
25-
- python ``:Ipython``
2625
- julia ``:Ijulia``
2726
- maple ``:Imaple``
2827
- bash ``:Ibash``
2928
- zsh ``:Izsh``
29+
- python ``:Ipython``
3030
- clojure ``:Iclojure``
3131
- autodetect based on filetype ``:Iterm``
3232

33-
Commands may be sent from a text file to the chosen terminal using
34-
``CTRL-S``. If there is no terminal, ``CTRL-S`` will automatically
35-
open one for you using ``:Iterm``.
33+
Commands may be sent from a text file to the chosen terminal using ``CTRL-S``.
34+
If there is no terminal, ``CTRL-S`` will automatically open one for you using
35+
``:Iterm``.
36+
37+
Note: it's highly recommended to use IPython as your default Python
38+
interpreter. You can set it like this:
39+
40+
.. code:: vim
3641
37-
It's highly recommended to set your default Python shell to IPython
38-
(see "Extending functionality" section for instructions). If you prefer
39-
not to do it, make sure, that every top-level block has at least one newline
40-
after it.
42+
let g:vimteractive_default_shells = { 'python': 'ipython' }
4143
4244
Installation
4345
------------
4446

45-
Since this package leverages the native vim interactive terminal, vimteractive is only compatible with vim 8 or greater.
47+
Since this package leverages the native vim interactive terminal, vimteractive
48+
is only compatible with vim 8 or greater.
4649

4750
To use the key-bindings, you should first disable the ``CTRL-S``
4851
default, which is a terminal command to freeze the output. You can
@@ -71,22 +74,21 @@ Motivation
7174
----------
7275

7376
`IPython and Jupyter <https://ipython.org/>`__ are excellent tools for
74-
exploratory analyses in python. They leverage the interactivity of the
75-
python kernel to allow you to keep results of calculations in memory
76-
whilst developing further code to process them.
77-
78-
However, I can't stand typing into anything other than vim. Anywhere
79-
else, my screen fills with hjklEB, or worse, I close the window with a
80-
careless ``<C-w>``. I want a technique that allows me to operate on
81-
plain text files, but still be able to work interactively with the
82-
interpreter with minimal effort.
83-
84-
`Many Projects <#similar-projects>`__ achieve this with a varying level
85-
of functionality. Vimteractive aims to create the simplest tool for
86-
sending things from text to interpreter, and making it easy to add
87-
additional interpreters. In particular, my main aim in starting this was
88-
to get a vim-ipython like interface to the command line
89-
`maple <https://www.maplesoft.com/>`__.
77+
exploratory analyses in python. They leverage the interactivity of the python
78+
kernel to allow you to keep results of calculations in memory whilst developing
79+
further code to process them.
80+
81+
However, I can't stand typing into anything other than vim. Anywhere else, my
82+
screen fills with hjklEB, or worse, I close the window with a careless
83+
``<C-w>``. I want a technique that allows me to operate on plain text files,
84+
but still be able to work interactively with the interpreter with minimal
85+
effort.
86+
87+
`Many Projects <#similar-projects>`__ achieve this with a varying level of
88+
functionality. Vimteractive aims to create the simplest tool for sending things
89+
from text to interpreter, and making it easy to add additional interpreters. In
90+
particular, my main aim in starting this was to get a vim-ipython like
91+
interface to the command line `maple <https://www.maplesoft.com/>`__.
9092

9193
Usage
9294
-----
@@ -110,69 +112,91 @@ Create a python file ``test.py`` with the following content:
110112
ax.set_xlabel('$x$')
111113
ax.set_ylabel('$y$')
112114
113-
Now start an ipython interpreter in vim with ``:Iipython``. You should
114-
see a preview window open above with your ipython prompt. Position your
115-
cursor over the first line of ``test.py``, and press
116-
``CTRL-S``. You should see this line now appear in the first prompt of
117-
the preview window. Do the same with the second and fourth lines. At the
118-
fourth line, you should see a figure appear once it's constructed with
119-
``plt.subplots()``. Continue by sending lines to the interpreter. You
120-
can send multiple lines by doing a visual selection and pressing
121-
``CTRL-S``.
122-
123-
If you switch windows with ``CTRL-W+k``, you will see the terminal
124-
buffer switch to a more usual looking normal-mode buffer, from which you
125-
can perform traditional normal mode commands. However, if you try to
126-
insert, you will enter the terminal, and be able to enter commands
127-
interactively into the prompt as if you had run it in the command line.
128-
You can save this buffer if you wish to a new file if it contains
129-
valuable output
115+
Now start an ipython interpreter in vim with ``:Iipython``. You should see a
116+
preview window open above with your ipython prompt. Position your cursor over
117+
the first line of ``test.py``, and press ``CTRL-S``. You should see this line
118+
now appear in the first prompt of the preview window. Do the same with the
119+
second and fourth lines. At the fourth line, you should see a figure appear
120+
once it's constructed with ``plt.subplots()``. Continue by sending lines to the
121+
interpreter. You can send multiple lines by doing a visual selection and
122+
pressing ``CTRL-S``.
123+
124+
If you switch windows with ``CTRL-W+k``, you will see the terminal buffer
125+
switch to a more usual looking normal-mode buffer, from which you can perform
126+
traditional normal mode commands. However, if you try to insert, you will enter
127+
the terminal, and be able to enter commands interactively into the prompt as if
128+
you had run it in the command line. You can save this buffer if you wish to a
129+
new file if it contains valuable output
130130

131131
You may want to send lines to one terminal from two buffers. To achieve that,
132132
run ``:Iconn <buffer_name>`` where ``<buffer_name>`` is a name of buffer
133-
containing terminal. If there is only one terminal, you can use just ``:Iconn``.
133+
containing terminal. If there is only one terminal, you can use just
134+
``:Iconn``.
134135

135136
Supported terminals
136137
~~~~~~~~~~~~~~~~~~~
137138

138139
- ``:Iipython`` Activate an ipython terminal
139-
- ``:Ipython`` Activate a python terminal
140140
- ``:Ijulia`` Activate a julia terminal
141141
- ``:Imaple`` Activate a maple terminal
142142
- ``:Ibash`` Activate a bash terminal
143143
- ``:Izsh`` Activate a zsh terminal
144+
- ``:Ipython`` Activate a python terminal
144145
- ``:Iclojure`` Activate a clojure terminal
145146
- ``:Iterm`` Activate default terminal for this filetype
146147

147148
Sending commands
148149
~~~~~~~~~~~~~~~~
149150

150-
``CTRL-S`` sends lines of text to the interpreter in a mode-dependent
151-
manner:
151+
``CTRL-S`` sends lines of text to the interpreter in a mode-dependent manner:
152152

153-
In Normal mode, ``CTRL-S`` sends the line currently occupied by the
154-
cursor the terminal.
153+
In Normal mode, ``CTRL-S`` sends the line currently occupied by the cursor the
154+
terminal.
155155

156-
In Insert mode, ``CTRL-S`` sends the line currently being edited, and
157-
then returns to insert mode at the same location.
156+
In Insert mode, ``CTRL-S`` sends the line currently being edited, and then
157+
returns to insert mode at the same location.
158158

159159
In Visual mode, ``CTRL-S`` sends the current selection to the terminal.
160160

161161
``ALT-S`` sends all lines from the start to the current line.
162162

163+
Connecting to an existing terminal
164+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
165+
166+
``:Iconn [{buffer]`` connects current buffer to REPL in ``{buffer}``. You can
167+
connect any number of buffers to one REPL. ``{buffer}`` can be omitted if there
168+
is only one terminal.
169+
170+
171+
Common issues
172+
-------------
173+
174+
Bracketed paste
175+
~~~~~~~~~~~~~~~
176+
177+
If you see strange symbols like ``^[[200~`` when sending lines to your new
178+
interpreter, you may be on an older system which does not have bracketed paste
179+
enabled, or have other shell misbehaviour issues. You can change the default
180+
setting with
181+
182+
.. code:: vim
183+
184+
let g:vimteractive_bracketed_paste_default = 0
185+
186+
163187
Options
164-
~~~~~~~
188+
-------
165189
These options can be put in your ``.vimrc``, or run manually as desired:
166190

167191
.. code:: vim
168192
169-
let g:vimteractive_vertical = 1 " Vertically split terminals
170-
let g:vimteractive_autostart = 0 " Don't start terminals by default
193+
let g:vimteractive_vertical = 1 " Vertically split terminals
194+
let g:vimteractive_autostart = 0 " Don't start terminals by default
171195
172196
Extending functionality
173197
-----------------------
174198

175-
This project is very much in an alpha phase, so if you have any issues
199+
This project is very much in an beta phase, so if you have any issues
176200
that arise on your system, feel free to `leave an issue <https://github.com/williamjameshandley/vimteractive/issues/new>`__ or create a `fork and pull
177201
request <https://gist.github.com/Chaser324/ce0505fbed06b947d962>`__ with
178202
your proposed changes

autoload/vimteractive.vim

+2-3
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,9 @@ function! vimteractive#sendlines(lines)
8585

8686
call s:show_term()
8787

88-
let l:term_type = getbufvar(b:vimteractive_connected_term, "term_type")
88+
let l:term_type = getbufvar(b:vimteractive_connected_term, "vimteractive_term_type")
8989

90-
mark`
91-
if get(g:vimteractive_bracketed_paste, l:term_type, 1)
90+
if get(g:vimteractive_bracketed_paste, l:term_type, g:vimteractive_bracketed_paste_default)
9291
call term_sendkeys(b:vimteractive_connected_term,"[200~" . a:lines . "[201~\n")
9392
else
9493
call term_sendkeys(b:vimteractive_connected_term, a:lines . "\n")

doc/vimteractive.txt

+44-32
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ CONTENTS *vimteractive-contents*
88

99
1.Intro........................................|vimteractive-intro|
1010
2.Usage........................................|vimteractive-usage|
11-
3.Extending functionality......................|vimteractive-extending|
12-
4.About........................................|vimteractive-about|
13-
5.License......................................|vimteractive-license|
11+
3.Common issues................................|vimteractive-issues|
12+
4.Extending functionality......................|vimteractive-extending|
13+
5.About........................................|vimteractive-about|
14+
6.License......................................|vimteractive-license|
1415

1516
==============================================================================
1617
1. Intro *vimteractive-intro*
@@ -24,35 +25,30 @@ to other interpreters (including ipython). It is based around the unix
2425
philosophy of "do one thing and do it well". It aims to provide a robust and
2526
simple link between text files and interactive interpreters. Vimteractive will
2627
never aim to do things like autocompletion, leaving that to other, more
27-
developed tools such as YouCompleteMe.
28+
developed tools such as YouCompleteMe or TabNine.
2829

2930
The activating commands are
3031
- ipython |:Iipython|
31-
- python |:Ipython|
3232
- julia |:Ijulia|
3333
- maple |:Imaple|
3434
- bash |:Ibash|
35-
- clojure |:Iclojure|
3635
- zsh |:Izsh|
36+
- python |:Ipython|
37+
- clojure |:Iclojure|
38+
- autodetect based on filetype |:Iterm|
3739

38-
You can also let Vimteractive detect interpreter using |:Iterm| or just send
39-
some lines: Vimteractive will create terminal if needed. Note: it's highly
40-
recommended to use IPython as your default Python interpreter. You can set it
41-
like this:
42-
43-
let g:vimteractive_default_shells = { 'python': 'ipython' }
40+
Commands may be sent from a text file to the chosen terminal using CTRL-S. If
41+
there is no terminal, CTRL-S will automatically open one for you using
42+
|:Iterm|. See |v_CTRL_S| for more details.
4443

45-
Default Python REPL support for pasting is really bad and you should use
46-
IPython whenever possible. If you need to use default Python REPL, you must
47-
put newline after every top-level block.
44+
Note: it's highly recommended to use IPython as your default Python
45+
interpreter. You can set it like this:
4846

49-
Commands may be sent from a text file to the chosen terminal using CTRL-S.
50-
See |v_CTRL_S| for more details.
47+
let g:vimteractive_default_shells = { 'python': 'ipython' }
5148

5249
Since this package leverages the native vim interactive terminal, it is
5350
only compatible with vim 8 or greater.
5451

55-
5652
==============================================================================
5753
2. Usage *vimteractive-usage*
5854

@@ -64,7 +60,7 @@ stty -ixon
6460
into your .bashrc (or equivalent shell profile file)
6561

6662
------------------------------------------------------------------------------
67-
Example usage:
63+
Example usage *vimteractive-usage*
6864

6965
Create a python file "test.py" with the following content:
7066

@@ -97,18 +93,19 @@ you wish to a new file if it contains valuable output
9793
By default every buffer is connected to separate terminal. If you want to
9894
connect two buffers to one terminal, use |:Iconn| command.
9995

100-
96+
------------------------------------------------------------------------------
10197
Supported terminals *vimteractive-terminals*
10298

10399
*:Iipython* Activate an ipython terminal
104-
*:Ipython* Activate a python terminal
105100
*:Ijulia* Activate a julia terminal
106101
*:Imaple* Activate a maple terminal
107102
*:Ibash* Activate a bash terminal
108103
*:Izsh* Activate a zsh terminal
104+
*:Ipython* Activate a python terminal
109105
*:Iclojure* Activate a clojure terminal
110106
*:Iterm* Activate a terminal based on current filetype
111107

108+
------------------------------------------------------------------------------
112109
Sending commands *v_CTRL_S*
113110

114111
CTRL-S sends lines of text to the interpreter in a mode-dependent manner:
@@ -126,23 +123,38 @@ ALT-S sends all lines from the start to the current line.
126123
If there is no active terminal for current buffer, CTRL-S will automatically
127124
create one for you using |:Iterm|.
128125

126+
------------------------------------------------------------------------------
127+
Connecting to existing REPLs *:Iconn* *vimteractive-connecting*
128+
129+
:Iconn [{buffer}] connects current buffer to REPL in {buffer}. You can connect
130+
any number of buffers to one REPL. {buffer} can be omitted if there is only one
131+
terminal.
132+
129133
==============================================================================
130-
3. Connecting to existing REPLs *:Iconn* *vimteractive-connecting*
131-
:Iconn [{buffer}] Connect current buffer to REPL in {buffer}. You can
132-
connect any number of buffers to one REPL. {buffer}
133-
can be omitted if there is only one terminal.
134+
3. Common issues *vimteractive-issues*
135+
136+
------------------------------------------------------------------------------
137+
Bracketed paste *vimteractive-issues-bracketed-paste*
138+
139+
If you see strange symbols like ^[[200~ when sending lines to your new
140+
interpreter, you may be on an older system which does not have bracketed paste
141+
enabled, or have other shell misbehaviour issues. You can change the default
142+
setting with
143+
144+
let g:vimteractive_bracketed_paste_default = 0
145+
134146

135147
==============================================================================
136-
3. Vimteractive options *vimteractive-options*
148+
4. Vimteractive options *vimteractive-options*
137149

138150
These options can be put in your |.vimrc|, or run manually as desired:
139151

140-
let g:vimteractive_vertical = 1 " Vertically split terminals
141-
let g:vimteractive_autostart = 0 " Don't start terminals by default
152+
let g:vimteractive_vertical = 1 " Vertically split terminals
153+
let g:vimteractive_autostart = 0 " Don't start terminals by default
142154

143155

144156
==============================================================================
145-
4. Extending functionality *vimteractive-extending*
157+
5. Extending functionality *vimteractive-extending*
146158

147159
To add a new interpreter to Vimteractive, you should define
148160
g:vimteractive_commands variable. For example:
@@ -165,13 +177,13 @@ milliseconds like this:
165177

166178
let g:vimteractive_slow_prompt = { 'pythonasync': 200 }
167179

168-
This project is very much in an alpha phase, so if you have any issues that
180+
This project is very much in an beta phase, so if you have any issues that
169181
arise on your system, feel free to contact me:
170182

171183
172184

173185
==============================================================================
174-
5. About *vimteractive-functionality*
186+
6. About *vimteractive-functionality*
175187

176188
The core maintainer of vimteractive is:
177189

@@ -182,6 +194,6 @@ Find the latest version of vimteractive at:
182194
http://github.com/williamjameshandley/vimteractive
183195

184196
==============================================================================
185-
6. License *vimteractive-license*
197+
7. License *vimteractive-license*
186198

187199
Vimteractive is licensed under GPL 3.0

0 commit comments

Comments
 (0)