|
|
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
|
|
|
David Robie · VIM:寄存器中填充字符断点宏的有向图 1 年前 |
|
|
Haoshu · 打开文件时如何简化包含“..”的文件路径 1 年前 |
|
|
Paw-1 Poudel · 在窗口中显示neovim内部的隐藏文件 2 年前 |
|
|
Bippan Kumar · 保存时删除在nvim中添加的空白 2 年前 |
|
|
perpetual · 防止在git主分支上意外直接提交 2 年前 |
|
|
ashish singh · 如何删除VIM中的单词和以前的空白? 2 年前 |
|
|
farnsy · Vim如何将第二个参数添加到缓冲区列表(备用文件)? 2 年前 |
|
|
MdNihal05 · vim插件安装在linux中不工作如何安装插件 2 年前 |