In Sublime Text I used small and handy MiniPy plugin.
It evaluates each expression in multi-cursor selection and replaces the selection with the result.
For example, I have selected these lines in ST:
1+1
2+1
3+1
When I press <c-s-x> I get:
2
3
4
I use vim-multiple-cursors plugin, but can't see how to make this work.
So my question is how can I evaluate multi-cursor selections in vim, preferably through Python.
Please note that multi-cursor selection doesn't have to be on a separate lines.
I would go with bc, too, but what about a pure Vim command?
:1,3norm c$^R=^R"^M
^R is obtained with <C-v><C-r> and ^M with <C-v><CR>.
As for your question, this will depend on what that plugin does with the "selected" text.
Since Vim doesn't provide non-contiguous selection there's no ready made way to get the content of the multiple "selections" (they are not actual selections) made with that plugin.
You will need that plugin to export the selected text in one way or another and I'm afraid this goes a bit beyond the scope of SO.
I'd suggest you get in touch with the author of that plugin and see if he is able to help you.
That said, you might be interested by Pipe2Eval.
Related
I am new to spf13-vim configuration. I have a basic problem; for example, when I am writing a python script, if I type "for" in vim console, I could see:
1 for item in <`2:items`>:
2 <`0`>
Then I can type any variable on "item", but I couldn't figure out how to jump to the next item, "<2:items>". How could I do that?
The direct answer to your question is: press Tab.
This feature is most certainly not provided by spf13 itself: it is provided by a snippet-expansion plugin that comes with spf13. Maybe it's SnipMate? Maybe it's UltiSnips? Maybe another one? Who even knows? You could simply look up up the documentation of that plugin but you can't, because you don't know what plugins you have.
Well, you are supposed to know what the plugins you add to your config that you manage yourself do and do not. But you don't, because you gave away that responsibility to someone else and you end up with a black box that contains and does things you have no idea about.
And the best part is that you don't even ask for help to the author/maintainer of that crappy distribution. They lured you into installing their stuff and giving control up, they are the ones who should help their poor, misled, users.
If you are serious about using Vim, drop spf13 immediately and take care of your configuration yourself.
If you don't care about doing things the right way, use another editor.
Press Ctrl+k to jump to the next item.
I use Vim+Ctags to write Python, and my problem is that Vim often jumps to the import for a tag, rather than the definition. This is a common issue, and has already been addressed in a few posts here.
this post shows how to remove the imports from the tags file. This works quite well, except that sometimes it is useful to have tags form the imports (e.g. when you want to list all places where a class/function has been imported).
this post shows how to get to the definition without removing the imports from the tags file. This is basically what I've been doing so far (just remapped :tjump to a single keystroke). However, you still need to navigate the list of tags that comes up to find the definition entry.
It would be nice it if it were possible to just tell Vim to "got the the definition" with a single key chord (e.g. ). Exuberant Ctags annotates the tag entries with the type of entry (e.g. c for classes, i for imports). Does anyone know if there is a way to get Vim to utilize these annotations, so that I could say things like "go to the first tag that is not of type i"?
Unfortunately, there's no way for Vim itself to do that inference business and jump to an import or a definition depending on some context: when searching for a tag in your tags file, Vim stops at the first match whatever it is. A plugin may help but I'm not aware of such a thing.
Instead of <C-]> or :tag foo, you could use g] or :ts foo which shows you a list of matches (with kinds and a preview of the line of each match) instead of jumping to the first one. This way, you are able to tell Vim exactly where you want to go.
As a secondary task to a Python auto-completion (https://github.com/davidhalter/jedi), I'm writing a VIM plugin with the ability to do renaming (refactoring).
The most comfortable way to do renaming is to use cw and autocommand InsertLeave :call do_renaming_func(). To do this I need to access the redo-register (see help redo-register) or something similar, which would record the written text.
If possible, I like to do this without macros, because I don't want to mess up anything.
The . register (#.) contains all editing keys, unfortunately in raw form, so also <Del> and <BS>, which show up as <80>kD, and which insert completion does not interpret. Instead, to extract only the net text entered, use the range delimited by the marks '[ and '] (last one exclusive).
For an example on how to do this, have a look at my PrevInsertComplete plugin.
The . register contains the last inserted text. See :help quote_..
The help doesn't specifically mention any caveats of when this register is populated, however it does mention that it doesn't work when editing the command line. This shouldn't be an issue for you.
The problem was not knowing which register it was, but to access it.
I eventually found the method:
getreg('.')
As #Ingo Karkat points out, this register might include some escape chars.
However, I used a different method in the end. I just read expand('<cword>') to get the new word (because a rename is always only one word). This is far easier and more reliable.
Here's the code (line 113):
https://github.com/davidhalter/jedi/commit/6920f15caf332cd14a7833a071765dfa77d82328
I'm new to eclipse. One thing I notice about eclipse+PyDev is that it give me warning if the indentation is not in multiple of 4 space. That is fine because I could use "reindent.py" to just reindent it. And I manage to setup it as the external tools. But the problem is, when I use it, (using Run->Externaltools->reindent) it would modify the code in the background, so after that, it would pop up saying that the source code has been modified (duh!) would you like to to reload the file? (duh again!) So, my question is, is there a way to pipe the current selection of the source code through reindent (it uses standard input/output when given no argument) and then replace the selection with reindent standard output automatically. Thanks!
Check in the preferences > general > workspace if you have 'refresh on access' and 'refresh with native hooks' both checked (that may solve your problem).
Another thing to check is in your external tool configuration: it has a 'refresh' tab, where you can choose to refresh the selected resource upon completion.
Another thing... if you have things just in a different indent (say 2 spaces), you can simply replace all 2 spaces by 4 spaces in the find instead of going through reindent...
When you run reindent.py as an external tool, you modify the whole file that contains the source code, not the current selection in your editor. But according to PEP 8 you should not mix tabs and spaces, so this might actually be what you want. In that case just click ok to reload the file and find that it worked.
In the settings you find some options under Window->Preferences->PyDev->Editor
There you can activate automatic replacement of a tabs with spaces when typing. Also you can choose that PyDev assumes tab-spacing for files that contain tabs.
You might want to read this:
How to integrate pep8.py in Eclipse?
When you activate Window->Preferences->PyDeV->Editor->Code Analysis->pep8.py you can generate a warning for every line, that conflicts with the convention.
I am using Rope for my python auto-completion in vim. However, one thing that annoys me is that it auto-inserts its suggestions, making me unable to narrow down choices by continuing to type. This means that if I see my desired completion at the bottom of the list, I must move through the entire list with the down-arrow-key to select it.
My preferred usage would be seeing the list of suggested completions and be able to continue typing, which automatically removes items from the list that don't begin with my typed characters. An extra bonus would be the ability to then move down the list with the tab key.
In short, I would like the completion selection process to be like vim's omnicompletion when the options completeopt=longest,menu,menuone are set. Is this possible?
python-mode sets Vim's omnifunc to use Rope completion, which should do what you want.
Otherwise, you could check out this rope-omni plugin.
rope-omni plugin has been merged into the standard ropevim in this commit. And yes, https://github.com/python-rope/ is now the official home of all rope projects.