vim に関数を追加する方法
関数 strip() を関数を追加するハック。
functions[] のテーブルに
{"strip", 1, 1, f_strip},
を追加。このテーブルはアルファベット順になっているので注意。
続いて以下の strip 本体を追加。プロトタイプ宣言も忘れずに。
/* * "strip()" function */ static void f_strip(argvars, rettv) typval_T *argvars; typval_T *rettv; { char_u *p; int n; int len; p = get_tv_string(&argvars[0]); len = (int)STRLEN(p); n = 0; while (vim_isspace(p[n])) n++; rettv->v_type = VAR_STRING; rettv->vval.v_string = vim_strnsave(p + n, len - n); }
以上。