Skip to content

Instantly share code, notes, and snippets.

Avatar
⌨️
Happy Vimming!

thinca thinca

⌨️
Happy Vimming!
View GitHub Profile
View wordcount.vim
let s:S = vital#vital#import('Data.String')
let s:L = vital#vital#import('Data.List')
function! s:count_words(text) abort
let F = { memo, x -> extend(memo, {x: get(memo, x, 0) + 1}) }
return s:L.foldl(F, {}, s:S.scan(a:text, '\w\+'))
endfunction
echo s:count_words('this is a pen or not a pen')
" {'this': 1, 'is': 1, 'a': 2, 'pen': 2, ...}
View trailing-whitespace
#!/bin/sh
if git-rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
View test.rb
Signal.trap(:QUIT) do
puts "QUIT signal sent."
exit 0
end
puts "Signal.list['QUIT'] => #{Signal.list['QUIT']}"
puts "My pid is #{$$}\n"
loop do
puts 'I\'m alive!'
View $HOME-.vim-syntax-markdown.vim
" ~/.vim/syntax/markdown.vim
" \c で 大文字小文字無視します :help /\c
" todo: TODO: をハイライトしたい
syntax match myTodo /\ctodo:/ containedin=ALL
" done: DONE: をハイライトしたい
syntax match myDone /\cdone:/ containedin=ALL
" 適当に色付け
highlight link myTodo Todo
@thinca
thinca / fmv.vim
Created Jan 27, 2012 — forked from h-east/fmv.vim
Create vimdoc-ja folder structure and move files. (for iOS Vim ja-help)
View fmv.vim
call mkdir("vimdoc-ja/doc", "p")
call mkdir("vimdoc-ja/syntax", "p")
call rename("help_ja.vim","vimdoc-ja/syntax/help_ja.vim")
for s:file in split(glob('*.jax'), "\n")
call rename(s:file, "vimdoc-ja/doc/" . s:file)
endfor
View doyagao.vim
vnew
setlocal bufhidden=hide buftype=nofile noswapfile nobuflisted
let s:doyagao = {'counter': 0, 'save_updatetime': &updatetime, 'bufnr': bufnr('%')}
function! s:doyagao.funcall() dict
if self.bufnr !=# bufnr('%')
call self.clear()
return
View .vimrc
" <Space><C-n>, <Space><C-p>: Move window position {{{
nnoremap <silent> <Space><C-n> :<C-u> call <SID>swap_window(v:count1)<CR>
nnoremap <silent> <Space><C-p> :<C-u> call <SID>swap_window(-v:count1)<CR>
function! s:modulo(n, m) "{{{
let d = a:n * a:m < 0 ? 1 : 0
return a:n + (-(a:n + (0 < a:m ? d : -d)) / a:m + d) * a:m
endfunction "}}}
function! s:swap_window(n) "{{{
View .vimrc
function! s:uniq(list) "{{{
let s:dict = {}
let counter = 1
for i in a:list
if !has_key(s:dict, i)
let s:dict[i] = counter
let counter += 1
endif
endfor
View gist:261452
function! s:ParseMarkdown()
return map(split(join(getline(1, '$'), "\n"), '\v(^|\n)\ze#+'), 'split(v:val, "\n")')
endfunction
" Usage
let s:pages = s:ParseMarkdown()
let s:max_page_number = len(s:pages) - 1
View poslist.vim
"=============================================================================
" FILE: poslist.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" MODIFIED BY: thinca <thinca@gmail.com>
" Last Modified: 23 Jan 2010
" Usage: Just source this file.
" License: MIT license {{{
" Permission is hereby granted, free of charge, to any person obtaining
" a copy of this software and associated documentation files (the
" "Software"), to deal in the Software without restriction, including