2

I've done some searching with various keywords, but unsuccessfully. Sorry for my English, I'm not a native speaker.

I'm new to VIM and to Python, and I'm learning both on the go as much as I can, but sometimes I hit a brick wall and land here. Though SE already answered most of my questions, hence this is my first one.

While I'm not sure if it's even possible (why am I the only junior Python programmer searching/asking for that?), I'd like to know for sure without learning the whole scripting language beforehand and discovering it's not.

To the point:

When I'm writing a new class in Python I have to write:

class TestClass(object):
    def __init__(self, arg1, ..., argn, namedarg1 = defaultvalue, namedarg2 = "default string value", namedarg3, ... namedargn):
    self.arg1 = arg1
    ...        
    self.argn = argn
    self.namedarg1 = namedarg1
    self.namedarg2 = namedarg2
    self.namedarg3 = namedarg3
    ...
    self.namedargn = namedargn

... which seems a terrible waste of time, especially once I've heard about vim macros, snippets, autocorrect, etc.

What would be the best way to automate change from, let's say, this:

Testclass(arg1, ..., argn, namedarg1 = defaultvalue, namedarg2 = "default string value", namedarg3, ... namedargn)

to the first example I showed? How would it work (i.e. how do I use it; bonus points for explaining how would the macro/script/snippet work)?

2
  • Here's what I'd do (because you'll learn more my doing): try to create a macro that works only for comma-separated arguments name. Then introduce the default values. Your macro should do something like: copy the argument name, type some text and past the argument name.
    – nobe4
    Jan 23, 2017 at 9:28
  • 1
    Thank you for commenting, but that's not what I'm looking for. I can do small macros, but that's not the point, I wanted a systemic solution, not to record a macro (probably failing at it a few dozen times) and run it n times over the constructor. Had I wanted to do that, I'd write a python script to do that instead of using vimscript.
    – Mr n
    Jan 23, 2017 at 15:45

1 Answer 1

0

I'm going to go with ultisnips, whose git page actually has a gif of it in action, doing almost exactly what I want (I guess I'm in for a bit of tweaking):

ultisnips

Thanks for the interest! Cheers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.