new VIM user. I'm trying to make creating python properties easier for my class definitions. What I would like for say I type
:pyp x
then VIM will autofill where my cursor is
@property
def x(self):
return self.x
@property.setter
def x(self,val):
self._x = val
or more abstractly I type
:pyp <property_name>
and VIM fills
@property
def <property_name>(self):
return self.<property_name>
@property.setter
def <property_name>(self,val):
self._<property_name> = val
I've looked at a few posts and the wikis on functions, macros but I'm very unsure of how to go about it or what to even look up as I am brand new VIM user, less than a week old.
I tried using this as an example, in my .vimrc but I couldn't even get that to work.
Additionally,
the system I am working on, its very very difficult if not impossible to get pluggins so I have to do stuff through my vimrc or other method. Basically trying to get a plugin installed could take half a year.
So the code I am currently trying is
function! PythonProperty(prop_name)
let cur_line = line('.')
let num_spaces = indent('.')
let spaces = repeat(' ',num_spaces)
let lines = [ spaces."@property",
\ spaces."def ".prop_name."(self):",
\ spaces." return self.".property,
\ spaces."@property.setter",
\ spaces."def".prop_name."(self,val)",
\ spaces." self._".prop_name." = val" ]
call append(cur_line,lines)
endfunction
and I am getting the errors
E121: Undefined variable: prop_name
I am typing
:call PythonProperty("x")
a:
to refer to function arguments.a:prop_name
is what you want.