All Projects β†’ haya14busa β†’ Underscore.vim

haya14busa / Underscore.vim

Licence: mit
Vim script utility library πŸ’“ The sky is the limit!

Labels

Projects that are alternatives of or similar to Underscore.vim

Colorsbox
Stars: ✭ 61 (-15.28%)
Mutual labels:  viml
Tcomment
An extensible & universal comment plugin that also handles embedded filetypes
Stars: ✭ 64 (-11.11%)
Mutual labels:  viml
Bringing Vim To The People
An lo, on the fourth day he did step down from the mountain, and with him VIM did follow . . . .
Stars: ✭ 69 (-4.17%)
Mutual labels:  viml
Bufkill.vim
Unload/delete/wipe a buffer, keep its window(s), display last accessed buffer(s)
Stars: ✭ 61 (-15.28%)
Mutual labels:  viml
Vdbi Vim
Database client for Vim
Stars: ✭ 63 (-12.5%)
Mutual labels:  viml
Vim Startuptime Benchmark
Stars: ✭ 65 (-9.72%)
Mutual labels:  viml
Hypergit.vim
This git plugin provides many awesome features so that you don't need to type commands anymore..
Stars: ✭ 59 (-18.06%)
Mutual labels:  viml
Javascript Indent
Javascript indenter (HTML indent is included)
Stars: ✭ 71 (-1.39%)
Mutual labels:  viml
Vim Eighties
Automatically resizes your windows
Stars: ✭ 64 (-11.11%)
Mutual labels:  viml
Archidroid Legacy
Legacy ArchiDroid Repo / New -> https://github.com/ArchiDroid/ArchiDroid
Stars: ✭ 68 (-5.56%)
Mutual labels:  viml
Showmarks
Visually shows the location of marks.
Stars: ✭ 61 (-15.28%)
Mutual labels:  viml
Html5 Syntax.vim
HTML5 syntax file for vim.
Stars: ✭ 62 (-13.89%)
Mutual labels:  viml
Xvim
Powerfull vim configuration for C/C++/GO/JS coder(ε₯½η”¨ηš„vimζ’δ»Άι›†ζˆεŒ…οΌŒζ”―ζŒC/C++/GO/JSοΌ‰
Stars: ✭ 65 (-9.72%)
Mutual labels:  viml
Vim Ruby Conque
Vim plugin to display ruby, rake, and rspec output colorized in ConqueTerm. Note: repeated runs of conqueterm may cause it to eat your shell ttys. I am no longer maintaining this.
Stars: ✭ 61 (-15.28%)
Mutual labels:  viml
Vimmate
Custom vim like Textmate for Ruby on Rails development
Stars: ✭ 70 (-2.78%)
Mutual labels:  viml
Vim Blockle
Brace yourself, it's time to toggle your ruby blocks!
Stars: ✭ 60 (-16.67%)
Mutual labels:  viml
Camelcasemotion
Motion through CamelCaseWords and underscore_notation.
Stars: ✭ 64 (-11.11%)
Mutual labels:  viml
Vim Git Branch Info
A Vim script to return info about the Git branches.
Stars: ✭ 71 (-1.39%)
Mutual labels:  viml
Vim Spotifysearch
Search spotify in Vim and play songs.
Stars: ✭ 71 (-1.39%)
Mutual labels:  viml
Vim Scmdiff
Vim script to highlight lines changed from a base version in SCM
Stars: ✭ 65 (-9.72%)
Mutual labels:  viml

underscore.vim

Build Status Build status

Vim script utility library πŸ’“ The sky is the limit!

underscore.vim is a Vim script library that provides a whole mess of useful functional programming helpers.

echo s:_.reject([1, 2, 3, 4, 5, 6], 'v:val % 2 == 0')
" => [1, 3, 5]

function! s:toFizzBuzz(x)
  return a:x%15 ? a:x%3 ? a:x%5 ? a:x : 'Buzz' : 'Fizz' : 'FizzBuzz'
endfunction

echo s:_._(range(20))
  \.chain()
  \.map('v:val + 1')
  \.filter('v:val % 2')
  \.map(function('s:toFizzBuzz'))
  \.value()
" => [1, 'Fizz', 'Buzz', 7, 'Fizz', 11, 13, 'FizzBuzz', 17, 19]

πŸ“¦ Installation πŸ“¦

  1. Install vital.vim and underscore.vim with your favorite plugin manager.
NeoBundle 'vim-jp/vital.vim'
NeoBundle 'haya14busa/underscore.vim'

Plugin 'vim-jp/vital.vim'
Plugin 'haya14busa/underscore.vim'

Plug 'vim-jp/vital.vim'
Plug 'haya14busa/underscore.vim'
  1. Embed underscore.vim into your plugin with :Vitalize.
:Vitalize . --name={plugin_name} Underscore
  1. Import underscore.vim in your plugins
let s:V = vital#of('vital')
let s:_ = s:V.import('Underscore').import()
echo s:_.filter([1, '2', '3', 4.0, 5], s:_.is_string)
" => ['2', '3']

πŸ“™ Documentation πŸ“™

:h underscore.txt

πŸŽ‰ Examples πŸŽ‰

###🌐 Real world(?) usage 🌐

let s:V = vital#of('vital')
let s:_ = s:V.import('Underscore').import()

function! s:scouter(...)
  let lines = readfile(expand(get(a:, 1, $MYVIMRC)))
  let p = '^\s*$\|^\s*["\\]'
  return s:_.chain(lines).reject(printf("v:val =~# '%s'", p)).length().value()
endfunction

" Count LOC of your vimrc
echo s:scouter()

" Return list of plugins in the given file or your vimrc
function! s:plugins(...)
  let lines = readfile(expand(get(a:, 1, $MYVIMRC)))
  let ignore = '^\s*$\|^\s*["\\]'
  let bundle = "\\v%(%(Neo)?Bundle%(Lazy)|Plug%(in)?) ''([^'']+%(/[^'']+)?)"
  return s:_.chain(lines)
    \.reject(printf("v:val =~# '%s'", ignore))
    \.select(printf("v:val =~# '%s'", bundle))
    \.map(printf("matchlist(v:val, '%s')[1]", bundle))
    \.sort()
    \.value()
endfunction

" Get installed plugins in vimrc
echo s:plugins()
echo len(s:plugins())

πŸ“ Memoize fibonacch πŸ“

let s:V = vital#of('vital')
let s:_ = s:V.import('Underscore').import()

function! s:_fib(n) abort
  return a:n < 2 ? a:n : s:fib(a:n-1) + s:fib(a:n-2)
endfunction

let s:fib = s:_.memoize(function('s:_fib'))
echo s:fib(24)
" => 46368

βœ‰οΈ With Vital.Data.Closure βœ‰οΈ

:h Vital.Data.Closure

let s:V = vital#of('vital')
let s:_ = s:V.import('Underscore').import()
let s:Closure = s:V.import('Data.Closure')
function! s:lambda(x, ...) abort
  return call(s:Closure.build, [a:x] + a:000).to_function()
endfunction

echo s:_.chain(range(1,100))
    \.select(s:lambda('= a:1 % 3 == 0'))
    \.tap(s:lambda(":echo 'len: ' . len(a:1)"))
    \.map(s:lambda('= a:1 * a:1'))
    \.reject(s:lambda('= a:1 < 500'))
    \.drop(3)
    \.foldl(0, s:lambda('+'))
    \.value()
" =>
"   len: 33
"   109296

⚑️ Extend to work with other library ⚑️

You can extend underscore.vim with _.mixin() ✨ See :h _.mixin()

underscore-string.vim

let s:V = vital#of('vital')
let s:_ = s:V.import('Underscore').import()
call s:_.mixin(s:V.import('Data.String'))
call s:_.mixin(s:V.import('Data.String.Interpolation'))
echo s:_.chain("  underscore-${module}.js!  \r\n")
    \.format({'module': 'string'})
    \.replace('.js', '.vim')
    \.chomp()
    \.trim()
    \.pad_left(25, '.')
    \.value()

underscore-random.vim with closure

let s:V = vital#of('vital')
let s:_ = s:V.import('Underscore').import()
call s:_.mixin(s:V.import('Random'))

let s:Closure = s:V.import('Data.Closure')
function! s:lambda(x, ...) abort
    return call(s:Closure.build, [a:x] + a:000).to_function()
endfunction

echo s:_.chain(range(100))
    \.shuffle()
    \.take(3)
    \.foldl(0, s:lambda('+'))
    \.value()
" => random: 155

If you want to see more examples, please see /example directory.

πŸ”— Links πŸ”—

The api and documentation are heavily inspired by Underscore.js, lodash and Underscore.lua. It's implementation are heavily inspired by and taken from vital.vim.

🐦 Author 🐦

haya14busa (https://github.com/haya14busa)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].