Comments (16)
Hmmmm… does that just mean not turning on ipython mode? Or is there more to it?
from vim-slime.
I took a 200 line python script, copied it to the system clipboard, and then just hit Cmd-V to paste it and it pasted with the correct indentation. I'm not sure how they implement it. I'd try not turning it on and see if that works.
from vim-slime.
I was able to get this to partially work by turning on "bracked paste mode" (https://cirw.in/blog/bracketed-paste), instead of using %cpaste
. Specifically in ftplugin/python/slime.vim
I changed
if exists('g:slime_python_ipython') && len(split(a:text,"\n")) > 1
return ["%cpaste -q\n", a:text, "--\n"]
to
if exists('g:slime_python_ipython') && len(split(a:text,"\n")) > 1
return ["\e[200~", a:text, "\e[201~\n"]
where \e[200~
and \e[201~
are the bracketed paste escape sequences.
As far as I can tell, this prevents ipython 5.0+ from only reading the first line.
See also (ipython/ipython#9948)
I don't know enough about vimscript to make it check the current version of ipython (as multi-line pasting is version 5.0+).
from vim-slime.
@jpalardy , "not turning on ipython mode" doesn't work because you need to send something special for "non-executing-newline"
We need to bind a shortcut that adds a new line without executing, if you are scripting you can use C-o Down to force a newline and Escape Enter to force execution.
See also: ENH: enable multiline send for ipython
(I think I like "bracketed paste mode" better)
from vim-slime.
Based on what I'm reading, this is related to #142 ?
from vim-slime.
For IPython 7.2, I managed to get it working with the following changes:
if exists('g:slime_python_ipython') && len(split(a:text,"\n")) > 1
return ["%cpaste -q\n", g:slime_dispatch_ipython_pause, a:text, "--\n"]
to
if exists('g:slime_python_ipython')
return [a:text, g:slime_dispatch_ipython_pause, "\n"]
when vim-slime pastes the text, IPython 5.0+ will run the code with no problems, but it will not auto-execute. Adding the pause and the newline character makes IPython execute the code after pasting.
Note that for large blocks of code with empty lines, there is still a problem with IPython executing at some of these empty lines, which seems to occur randomly, indicating a timing issue. This will be a problem for indented code. I'm not sure how to address this.
from vim-slime.
I'll have to defer to an iPython user for a solution.
from vim-slime.
If I replace empty lines with a comment character, it suppresses early execution and somewhat preserves the layout of the code. A bit hacky, but it seems to work.
from vim-slime.
So... should I submit a pull request for testing perhaps? Or no?
from vim-slime.
I'm up for it.
If you send a PR, I'll merge it. If it doesn't work, we'll revert?
from vim-slime.
New to this... hopefully it's OK.
from vim-slime.
@NedWestern
For the problem with IPython executing at empty lines somewhat randomly (treating one code chunk as multiple chunks), have you tried adding the "bracketed paste mode" characters around a.text
? (see #123 (comment))
I've been using it (for the last two years) to send code from vim to ipython using tmux and it's removed the issue of ipython thinking I'm sending multiple chunks (as far as I can tell).
Specifically replacing
if exists('g:slime_python_ipython')
return [a:text, g:slime_dispatch_ipython_pause, "\n"]
with
if exists('g:slime_python_ipython')
return ["\e[200~", a:text, "\e[201~", g:slime_dispatch_ipython_pause, "\n"]
It might let you avoid having to suppress empty lines with comment characters.
from vim-slime.
@aicherc
Hi Christopher, yes I read your blog post. Sounds interesting, but I can not get it to work for my setup (IPython 7.2 in vimterminal in gVim). It sends the escape sequence, minus the "\e", and does not execute.
In [1]: [200~print('foo')
: ^[[201~
:
Does it require specific settings in vim?
from vim-slime.
@NedWestern
Thanks for trying it out.
After re-reading the blog post, it sounds like "bracketed paste mode" is only intended to work in terminals that support it (my setup is gnome-terminal + tmux). I'm not very familiar with vimterminal (or terminal emulation in vim/neovim) to know if they support it.
Based on this, I like your current solution (empty lines -> #
), since it works more generally.
from vim-slime.
True, but it seems to break for some people... ugh.
from vim-slime.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
from vim-slime.
Related Issues (20)
- Cursor returns to the beginning of a selection when sending code from a script in one tmux pane to the terminal in the other terminal pane. HOT 8
- send to multiple panes HOT 2
- How to send <Ctrl-C> via tmux? HOT 2
- <C-c><Text object> HOT 2
- Option to change bracket paste delimiters HOT 4
- neovim tmux in msys2 in windows HOT 4
- Run vimscript commands interactively HOT 5
- Issue #23 returns HOT 1
- Can SlimeConfig apply to all vim buffers HOT 10
- slime_no_mappings works only if declaredbefore plugin is loaded HOT 1
- Naming convention inconsistency HOT 1
- kitty slime broken in kitty v0.32 HOT 5
- WezTerm Pane Direction ID has trailing whitespace
- Proposal for Changes to `autoload/slime.vim` HOT 6
- Additional 'return' required when sending indented, commented code to ipython HOT 3
- neovim target TermOpen autocmd interactions with other terminal buffers HOT 3
- working with ConqueTerm HOT 1
- Error raised after trigger send if there is no neovim terminal opened HOT 6
- Issue to send multiple lines with recent versions of vim-slime HOT 7
- "Undefined variable: g:slime_config_defaults" on opening Python files HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vim-slime.