Skip to content

Instantly share code, notes, and snippets.

View tyru's full-sized avatar
🏠
Working from home

Fujiwara Takuya tyru

🏠
Working from home
View GitHub Profile
function! HasKey(dict, key)
return has_key(a:dict, a:key)
endfunction
function! s:has_key(dict, key)
return has_key(a:dict, a:key)
endfunction
function! Fold(list, init, f)
let l:V = a:init
for l:Elem in a:list
@tyru
tyru / profile.txt
Created August 1, 2019 19:42
Add readable name to numbered-function (and vim-jp/vim-vimlparser profiling result)
SCRIPT /Users/tyru/config/home/volt/repos/github.com/vim-jp/vim-vimlparser/autoload/vimlparser.vim
Sourced 1 time
Total time: 0.011356
Self time: 0.011356
count total (s) self (s)
" vim:set ts=8 sts=2 sw=2 tw=0 et:
"
" VimL parser - Vim Script Parser
"
@tyru
tyru / require.vim
Last active July 2, 2019 17:02
require() function for deeply nested very loooooooooong named autoload function
let s:L = vital#of('vital').import('Data.List')
function! s:require(ns, ...) abort
let ns = strtrans(a:ns)
let fnlist = map(
\ split(execute('function /' . ns), '\n'),
\ {_,l -> matchstr(l, '^function ' . ns . '#\zs\w\+\ze(')}
\)
call filter(fnlist, '!empty(v:val)')
if a:0
@tyru
tyru / search-decl-php-ftplugin-2.patch
Last active June 6, 2019 11:25
Searching declaration in PHP ftplugin (Fix [[, ]] mappings problems, added [], ][ mappings)
--- php.vim.bak 2018-10-10 14:08:25.875669800 +0900
+++ php.vim 2018-10-10 14:04:30.777334700 +0900
@@ -61,15 +61,107 @@
setlocal omnifunc=phpcomplete#CompletePHP
endif
-" Section jumping: [[ and ]] provided by Antony Scriven <adscriven at gmail dot com>
-let s:function = '\(abstract\s\+\|final\s\+\|private\s\+\|protected\s\+\|public\s\+\|static\s\+\)*function'
-let s:class = '\(abstract\s\+\|final\s\+\)*class'
+" Section jumping: [[ and ]] provided by:
@tyru
tyru / run.gs
Last active March 21, 2019 05:34
Google Apps Script で Gmail の添付ファイルを Google Drive に保存
// Google Drive でフォルダに移動した時のURLで分かる
// https://drive.google.com/drive/u/1/folders/{フォルダのID}
var SAVE_FOLDER_ID = 'フォルダのID';
var READ_LABEL_NAME = '添付ファイル保存済み';
var SEARCH_CONDITION = 'has:attachment -label:' + READ_LABEL_NAME;
var THREADS_PER_PAGE = 100;
function saveAttachments() {
Logger.clear();
Logger.log('start');
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef enum _type_t {
INT_T,
STRING_T,
LIST_T,
} type_t;
@tyru
tyru / vimrc
Last active November 26, 2018 06:05
set laststatus=2
let &statusline = '%!StatusLine()'
function! StatusLine() abort
if &hlsearch
" XXX: 'l', 'h' do not move current cursor!
let searchcount = matchstr(execute('keepjumps keepmarks %s//&/gne', 'silent'), '\d\+')
let searchcount = printf(' (%s/%s)', searchcount !=# '' ? searchcount : '0', @/)
else
let searchcount = ''
@tyru
tyru / sid_snr.vim
Last active November 11, 2018 09:59
Bizarre <SID> and <SNR> conversion (https://github.com/vim-jp/issues/issues/1201)
function! s:get_next_tab(n) abort
let last = tabpagenr('$')
let i = (tabpagenr() - 1 + a:n) % last
let i = i < 0 ? last + i : i
return i ==# 0 || i + 2 ==# tabpagenr() ? i : i + 1
endfunction
" =============== Error ===============
diff --git a/src/eval.c b/src/eval.c
index 4a3cf9912..cdb1d2f4e 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -8109,6 +8109,7 @@ ex_echohl(exarg_T *eap)
ex_execute(exarg_T *eap)
{
char_u *arg = eap->arg;
+ char_u *trans_arg;
typval_T rettv;
@tyru
tyru / vimrc.vim
Created October 10, 2018 02:40
Toggle current tab's terminal window modes
nnoremap <Plug>(vimrc:prefix:excmd)oT :<C-u>call <SID>toggle_terminal_modes()<CR>
function! s:toggle_terminal_modes()
let prevwinnr = winnr()
" -1: undefined, 0: terminal normal mode, 1: terminal job mode
" Change all terminal window's modes to this mode.
" It is determined by the first terminal window's mode.
let dest_mode = -1
try
for bufnr in tabpagebuflist()