Under spf13-vim, how to jump to next item in the loop - python

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.

Related

How can I call a python function from an advanced scripting voice command in Dragon NaturallySpeaking?

How can I call a python function from an advanced scripting voice command in Dragon NaturallySpeaking?
I don't want to use a third-party application such as dragonfly or NatLink (paper).
So, one way is to compile it. You can put a bunch of functions that do different things all into the same program and pass along appropriate arguments to select the function you want, and pass the parameters along. Returning the result can be tricky, though, but I usually use the Clipboard (so copy the py output to clip and read from clip in Dragon). Multi-word params need to have spaces escaped (%20) and process it inside your py.
Something like this:
ShellExecute "path\program.exe myFunc myPar1, my%20Par%202", 6 ' 6 runs minimized
Wait 1
myVar = Clipboard
Hth,
Warning: This is not an answer. I am not a programmer. I don't know any Python and have no way of testing it.
This is just a suggestion on how to solve this problem. I don't know where else to put this. I'd put it in a comment, but it allows no screenshots. Please edit and suggest as you wish.
There is answer on SO that deals with calling Python from Excel, which is a similar concept: https://stackoverflow.com/a/3569988/2101890. I am trying to use that here but don't know how.
When using commands in another programming language, you can sometimes add them by adding a reference in the MyCommands Editor. You can reference DLLs and other "stuff". Some references to libraries appear automatically. I've installed Python and hoped to find Python in the References, but no such luck:
There is no Python entry here that I can find. You may have better luck. If you do find something, check the box and see if you can add python commands without causing an error when saving the command.
Maybe you can browse to %localappdata%\Programs\Python\Python36\ and add some of the DLLs from there and call Python commands from there. Or try getting it to work in the way described under 1.

Execute statements on multiple cursors (like ST's MiniPy)

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.

Virtual brackets in Python

(Warning: Potential flame-war starter. This is however not my goal, the point here is not to discuss the design choices of Python, but to know how to make the best out of it).
Is there a program, script, method (Unix-based, ideally), to display "virtual" brackets around blocs of code in Python, and to keep them where they are so that the code can still be executed even if indenting is broken ?
I realize that Python only uses indentation to define blocks of code, and that the final program may not contain brackets.
However, I find it very annoying that your program can stop functioning just because of an unfortunate and undetected carriage-return.
So, ideally I would be looking for a plugin in a text editor (kate, gedit...) that would:
Display virtual brackets around blocks of code in my Python program
Keep them in place
Generate dynamically the "correct" Python code with the indentation corresponding to where the brackets belong.
(no flame-war, please !)
I used an editor that does code rollups and understood Python syntax, then I looked for rollups that are in unexpected locations. I don't remember if Kate does that. It's not obvious that there is an issue, but it makes it easier when you are looking for an issue.

pydev - can someone please explain these errors

I am developing using PyDev in Eclipse. I have put in some comments in my code. I get wavy red lines underneath certain words. The program runs fine and there are no warnings mentioned. So what is the meaning of these wavy lines.
e.g.
#!/usr/bin/python - I get the line under usr and python
# generated by accessing registry using another script written in VBScript.
# The scripts can do the follwing things.
- I get wavy lines under the words registry and following.
I need these comments as I may run the module on its own later.
Thanks for the help.
Neil speaks the truth, except for telling you to turn it off -- spell check in comments is quite helpful -- those who come after will thank you for ensuring they can read your comments without trying to decode random spelling errors.
The lines are simply pointing out words your IDE thinks are spelled wrong. I don't know why it doesn't understand "registry", but you have, in fact, misspelled "following" (as "follwing"). Fix the latter, ignore the former (or add it to the dictionary, don't remember if there's a convenient mechanism for that There is! See Macke's helpful comment below.).
Might be this is just a spellchecker. You have a typo "follwing" instead of "following".

python coding speed and cleanest

Python is pretty clean, and I can code neat apps quickly.
But I notice I have some minor error someplace and I dont find the error at compile but at run time. Then I need to change and run the script again. Is there a way to have it break and let me modify and run?
Also, I dislike how python has no enums. If I were to write code that needs a lot of enums and types, should I be doing it in C++? It feels like I can do it quicker in C++.
"I don't find the error at compile but at run time"
Correct. True for all non-compiled interpreted languages.
"I need to change and run the script again"
Also correct. True for all non-compiled interpreted languages.
"Is there a way to have it break and let me modify and run?"
What?
If it's a run-time error, the script breaks, you fix it and run again.
If it's not a proper error, but a logic problem of some kind, then the program finishes, but doesn't work correctly. No language can anticipate what you hoped for and break for you.
Or perhaps you mean something else.
"...code that needs a lot of enums"
You'll need to provide examples of code that needs a lot of enums. I've been writing Python for years, and have no use for enums. Indeed, I've been writing C++ with no use for enums either.
You'll have to provide code that needs a lot of enums as a specific example. Perhaps in another question along the lines of "What's a Pythonic replacement for all these enums."
It's usually polymorphic class definitions, but without an example, it's hard to be sure.
With interpreted languages you have a lot of freedom. Freedom isn't free here either. While the interpreter won't torture you into dotting every i and crossing every T before it deems your code worthy of a run, it also won't try to statically analyze your code for all those problems. So you have a few choices.
1) {Pyflakes, pychecker, pylint} will do static analysis on your code. That settles the syntax issue mostly.
2) Test-driven development with nosetests or the like will help you. If you make a code change that breaks your existing code, the tests will fail and you will know about it. This is actually better than static analysis and can be as fast. If you test-first, then you will have all your code checked at test runtime instead of program runtime.
Note that with 1 & 2 in place you are a bit better off than if you had just a static-typing compiler on your side. Even so, it will not create a proof of correctness.
It is possible that your tests may miss some plumbing you need for the app to actually run. If that happens, you fix it by writing more tests usually. But you still need to fire up the app and bang on it to see what tests you should have written and didn't.
You might want to look into something like nosey, which runs your unit tests periodically when you've saved changes to a file. You could also set up a save-event trigger to run your unit tests in the background whenever you save a file (possible e.g. with Komodo Edit).
That said, what I do is bind the F7 key to run unit tests in the current directory and subdirectories, and the F6 key to run pylint on the current file. Frequent use of these allows me to spot errors pretty quickly.
Python is an interpreted language, there is no compile stage, at least not that is visible to the user. If you get an error, go back, modify the script, and try again. If your script has long execution time, and you don't want to stop-restart, you can try a debugger like pdb, using which you can fix some of your errors during runtime.
There are a large number of ways in which you can implement enums, a quick google search for "python enums" gives everything you're likely to need. However, you should look into whether or not you really need them, and if there's a better, more 'pythonic' way of doing the same thing.

Categories