__ _ __
____ / /_ (_)__ _____/ /_
/ __ \/ __ \ / / _ \/ ___/ __/
/ /_/ / /_/ / / / __/ /__/ /_
\____/_.___/_/ /\___/\___/\__/
/___/
object.vim is a minimal framework for Python-like programming in VimScript.
- Defining classes and creating instances.
let MyClass =object#class('MyClass')
letvar=object#new(MyClass)- Calling methods of parents and siblings with
super().
" MyClass as above.function! MyClass.__init__()
callobject#super(MyClass, self).__init__()
letself.data =1endfunction- Creating Lambdas.
letx=reverse(range(3))
echosort(x, object#lambda('x y', 'x - y'))
[0, 1, 2]- Iterator and for loop construct.
echoobject#list(object#zip('abc', range(3)))
[['a', 0], ['b', 1], ['c', 2]]
letdict= {'foo': 1, 'bar': 2}
callobject#for('key val', items(dict), 'echo key val')
foo 1bar2- Open files for reading and writing.
letf=object#open('data.txt', 'r')
echoobject#repr(f)
<open file 'data.txt', mode 'r'>echof.read()
'All the lines concatenated with newline.'- Wrappers for built-in types for inheritance.
letdict=object#dict_()
echoobject#repr(dict)
<'dict' type>let MyDict =object#class('MyDict', dict)
letvar=object#new(MyDict, {'foo': 1})
echovar.values()
[['foo', 1]]- A bunch of customizable protocol functions.
echoobject#len(range(10))
10echoobject#contains('', 'string')
1let object =object#object_()
echoobject#dir(object)
['__name__', '__bases__', '__base__', '__repr__', '__class__', '__init__', '__mro__']- Hashing arbitrary objects.
echoobject#hash('this is a string')
197650594echoobject#hash(-1234)
2147482414echoobject#hash(function('tr'))
233815837- Class-based exceptions.
let except =object#except#builtins()
callobject#class('MyException', except.Exception, g:)
callobject#raise(MyException)
E605: Exception not caught: MyException:- Shallow namespace
object#. - Multiple inheritances powered by C3 linearization.
- A complete set of Python-like built-in functions.
- True lambda with closure and named arguments.
- True iterator and
zip()andenumerate(). - Hash (nearly) arbitrary object.
- Read and write files with
open().
This plugin follows the standard runtime path structure, so it can be installed with a variety of plugin managers:
| Plugin Manager | Command |
|---|---|
| NeoBundle | NeoBundle 'cgsdfc/object.vim' |
| Vundle | Plugin 'cgsdfc/object.vim' |
| Plug | Plug 'cgsdfc/object.vim' |
| VAM | call vam#ActivateAddons(['vim-airline']) |
| Dein | call dein#add('cgsdfc/object.vim') |
| minpac | call minpac#add('cgsdfc/object.vim') |
- vim-maktaba for handling built-in type.
- vader.vim for unit tests.
- vimdoc for generating the help file from comments.
Please read the docs or after installation, run :help object to see the full documents.
If you find our software useful in your research, please consider citing us as follows:
@misc{cong_objectvim_2018,
title = {object.vim: {A} minimal framework for {Python}-like programming in {VimScript}.},
shorttitle = {object.vim},
url = {https://github.com/cgsdfc/object.vim},
abstract = {object.vim is a minimal framework for Python-like programming in VimScript. It provides some of the core features of the Python programming language in the form of VimScript functions and dictionaries, such as class-based object-oriented programming, lambda functions, iterators, and exceptions. It is also an interesting try to implement features of a high-level language in terms of another lower-level language.},
author = {Cong, Feng},
year = {2018},
}