![]() |
1
1
你可以使用 identexpr 通过计算 expression (即编写VIM脚本函数)。这个函数应该接受一个字符串——行——并返回要缩进的空格数。这使您能够灵活地为此模板条件返回缩进级别,或者返回到 autoindent , smartindent 或 cindent 在正常情况下,C类情况。 Here is an example that was created to handle the signals and slots extension of Qt. 它演示了返回到cident函数。 |
![]() |
2
4
我的解决方案: " Don't indent namespace and template function! CppNoNamespaceAndTemplateIndent() let l:cline_num = line('.') let l:cline = getline(l:cline_num) let l:pline_num = prevnonblank(l:cline_num - 1) let l:pline = getline(l:pline_num) while l:pline =~# '\(^\s*{\s*\|^\s*//\|^\s*/\*\|\*/\s*$\)' let l:pline_num = prevnonblank(l:pline_num - 1) let l:pline = getline(l:pline_num) endwhile let l:retv = cindent('.') let l:pindent = indent(l:pline_num) if l:pline =~# '^\s*template\s*\s*$' let l:retv = l:pindent elseif l:pline =~# '\s*typename\s*.*,\s*$' let l:retv = l:pindent elseif l:cline =~# '^\s*>\s*$' let l:retv = l:pindent - &shiftwidth elseif l:pline =~# '\s*typename\s*.*>\s*$' let l:retv = l:pindent - &shiftwidth elseif l:pline =~# '^\s*namespace.*' let l:retv = 0 endif return l:retv endfunction if has("autocmd") autocmd BufEnter *.{cc,cxx,cpp,h,hh,hpp,hxx} setlocal indentexpr=CppNoNamespaceAndTemplateIndent() endif |
![]() |
ChynaJake · Python 2.7,智能调节 7 年前 |
![]() |
Aleksandar K. · 如何在网页上显示JSON中的数据? 7 年前 |
![]() |
serv-inc · 在mongo shell中设置漂亮打印的缩进级别 7 年前 |
![]() |
Kohei TAMURA · 如何在HTML中编写XML 7 年前 |
![]() |
user3240588 · 在ocaml顶层打印多态容器 11 年前 |