| 关键词: nbsp Eatchar iab mxa xa 字符 InsertTabWrapper case return 注释 |
"Auto completion using the TAB key"This function determines, wether we are on the start of the line text(then tab indents) or"if we want to try auto completionfunction! InsertTabWrapper()let col=col('.')-1if !col || getline('.')[col-1] !~ '\k' return "\<TAB>"else return "\<C-N>"endifendfunction"Remap the tab key to select action with InsertTabWrapperinoremap <TAB> <C-R>=InsertTabWrapper()<CR>这个函数的作用是判断当前光标前的一个字符是否为一个 Keyword 字符(:help iskeyword),vim 中用 \k 表示,这个字符的范围大约是所有非空白的可打印的字符,但除开某些特殊字符,比如 @ * " 等等。于是效果就出来了,当前导字符为空白或者 @ * 等字符时,Tab 就映射为 <TAB> 成为缩进键。否则就映射为 <C-N> ,也就是 CTRL+N 调用自动完成功能。**************************************************************" 自定义缩写function! Eatchar(pat) let s:c = nr2char(getchar()) return (s:c =~ a:pat) ? '' : s:cendfunction" C 文件头注释iab /** /<Esc>75a*<Esc>o<Esc>0c$ * <Esc>yyADescrīption:<Esc>pmxpAAuthor : wplxb<Esc>pALanguage: C<Esc>pADate : <C-R>=strftime("%Y-%m-%d")<CR><Esc>p$r/74i*<Esc>0vyo<Esc>`x$9pa" C 注释iab /// /* <Esc>mxa */<Esc>`xa<C-R>=Eatchar('\s')<CR>iab *** /*<Esc>yyppr A/<Esc>k0r A <C-R>=Eatchar('\s')<CR>" C 预处理iab #i #include <<Esc>mxa><Esc>`xa<C-R>=Eatchar('\s')<CR>iab #d #define" C 关键字iab if( if (<Esc>mxa)<CR>{<CR>}<Esc>`xa<C-R>=Eatchar('\s')<CR>iab el{ else<CR>{<Esc>mxa<CR>}<Esc>`xa<CR><C-R>=Eatchar('\s')<CR>iab ie( if (<Esc>mxa)<CR>{<CR>}<CR>else<CR>{<CR>}<Esc>`xa<C-R>=Eatchar('\s')<CR>iab fo( for (<Esc>mxa; ; )<CR>{<CR>}<Esc>`xa<C-R>=Eatchar('\s')<CR>iab fi( for (i = 0; i < <Esc>mxa; ++i)<CR>{<CR>}<Esc>`xa<C-R>=Eatchar('\s')<CR>iab fi1( for (i = 1; i <= <Esc>mxa; ++i)<CR>{<CR>}<Esc>`xa<C-R>=Eatchar('\s')<CR>iab fj( for (j = 0; j < <Esc>mxa; ++j)<CR>{<CR>}<Esc>`xa<C-R>=Eatchar('\s')<CR>iab fj1( for (j = 1; j <= <Esc>mxa; ++j)<CR>{<CR>}<Esc>`xa<C-R>=Eatchar('\s')<CR>iab ma( int main(int argc, char * argv[])<CR>{<Esc>mxa<CR>}<Esc>`xa<CR><CR>return 0;<Esc>`xa<CR><C-R>=Eatchar('\s')<CR>iab wh( while (<Esc>mxa)<CR>{<CR>}<Esc>`xa<C-R>=Eatchar('\s')<CR>iab sw( switch (<Esc>mxa)<CR>{<CR>case <Esc>mya<CR>break;<CR>case <Esc>mza<CR>break;:<Esc>xa<CR>}<Esc>`yp`zp`xa<C-R>=Eatchar('\s')<CR>iab sd( switch (<Esc>mxa)<CR>{<CR>case <Esc>mya<CR>break;<CR>case <Esc>mza<CR>break;<CR>default:<Esc>vya<CR>}<Esc>`yp`zp`xa<C-R>=Eatchar('\s')<CR>" C 常用库函数iab sc( scanf("<Esc>mxa", );<Esc>`xa<C-R>=Eatchar('\s')<CR>iab fs( fscanf(<Esc>mxa, "", );<Esc>`xa<C-R>=Eatchar('\s')<CR>iab ss( sscanf(<Esc>mxa, "", );<Esc>`xa<C-R>=Eatchar('\s')<CR>iab pr( printf("<Esc>mxa", );<Esc>`xa<C-R>=Eatchar('\s')<CR>iab prn( printf("<Esc>mxa\n");<Esc>`x<C-R>=Eatchar('\s')<CR>iab fp( fprintf(<Esc>mxa, "", );<Esc>`xa<C-R>=Eatchar('\s')<CR>iab sp( sprintf(<Esc>mxa, "", );<Esc>`xa<C-R>=Eatchar('\s')<CR>iab cpy( strcpy(<Esc>mxa, );<Esc>`xa<C-R>=Eatchar('\s')<CR>iab cat( strcat(<Esc>mxa, );<Esc>`xa<C-R>=Eatchar('\s')<CR>iab len( strlen(<Esc>mxa);<Esc>`xa<C-R>=Eatchar('\s')<CR>iab cmp( strcmp(<Esc>mxa, );<Esc>`xa<C-R>=Eatchar('\s')<CR>iab qs( qsort(<Esc>mxa, , , );<Esc>`xa<C-R>=Eatchar('\s')<CR>" C++ 常用iab co cout << <Esc>mxa << endl;<Esc>`xa<C-R>=Eatchar('\s')<CR>iab --- <Esc>75A-<Esc>a<C-R>=Eatchar('\s')<CR>cab tn tabnew |
|
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系
[邮箱地址] 删除
|