Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

cgsdfc/object.vim

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')
let var = object#new(MyClass)
  • Calling methods of parents and siblings with super().
" MyClass as above.
function! MyClass.__init__()
 call object#super(MyClass, self).__init__()
 let self.data = 1
endfunction
  • Creating Lambdas.
let x = reverse(range(3))
echo sort(x, object#lambda('x y', 'x - y'))
[0, 1, 2]
  • Iterator and for loop construct.
echo object#list(object#zip('abc', range(3)))
[['a', 0], ['b', 1], ['c', 2]]
let dict = {'foo': 1, 'bar': 2}
call object#for('key val', items(dict), 'echo key val')
foo 1
bar 2
  • Open files for reading and writing.
let f = object#open('data.txt', 'r')
echo object#repr(f)
<open file 'data.txt', mode 'r'>
echo f.read()
'All the lines concatenated with newline.'
  • Wrappers for built-in types for inheritance.
let dict = object#dict_()
echo object#repr(dict)
<'dict' type>
let MyDict = object#class('MyDict', dict)
let var = object#new(MyDict, {'foo': 1})
echo var.values()
[['foo', 1]]
  • A bunch of customizable protocol functions.
echo object#len(range(10))
10
echo object#contains('', 'string')
1
let object = object#object_()
echo object#dir(object)
['__name__', '__bases__', '__base__', '__repr__', '__class__', '__init__', '__mro__']
  • Hashing arbitrary objects.
echo object#hash('this is a string')
197650594
echo object#hash(-1234)
2147482414
echo object#hash(function('tr'))
233815837
  • Class-based exceptions.
let except = object#except#builtins()
call object#class('MyException', except.Exception, g:)
call object#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 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')

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

License

Stars

Watchers

Forks

AltStyle によって変換されたページ (->オリジナル) /