Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

234 Commits

Repository files navigation

object.vim

 __ _ __
____ / /_ (_)__ _____/ /_
/ __ \/ __ \ / / _ \/ ___/ __/
/ /_/ / /_/ / / / __/ /__/ /_
\____/_.___/_/ /\___/\___/\__/
/___/

object.vim is a minimal framework for Python-like programming in VimScript.

Examples

  • 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:

Features

  • 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() and enumerate().
  • Hash (nearly) arbitrary object.
  • Read and write files with open().

Installation

This plugin follows the standard runtime path structure, so it can be installed with a variety of plugin managers:

Plugin ManagerCommand
NeoBundleNeoBundle 'cgsdfc/object.vim'
VundlePlugin 'cgsdfc/object.vim'
PlugPlug 'cgsdfc/object.vim'
VAMcall vam#ActivateAddons(['vim-airline'])
Deincall dein#add('cgsdfc/object.vim')
minpaccall minpac#add('cgsdfc/object.vim')

Dependencies

Documentation

Please read the docs or after installation, run :help object to see the full documents.

Citation

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},
}

About

A minimal framework that enables Python-like code in VimScript (VimL).

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Contributors

Languages