在Vim中计算缩进级别时如何在注释后忽略空格
发布时间:2020-12-15 22:34:00 所属栏目:安全 来源:网络整理
导读:考虑编写包含缩进列表的 JavaDoc样式注释(当设置expandtab并且softtabstop = 2时): /** * First line: * - Indented text */ 目前,在输入第一行:并点击返回后,Vim将正确插入* space.但是,当我按Tab键缩进第二行时,只会插入一个空格而不是两个空格. 是否可
考虑编写包含缩进列表的
JavaDoc样式注释(当设置expandtab并且softtabstop = 2时):
/** * First line: * - Indented text */ 目前,在输入第一行:并点击返回后,Vim将正确插入*< space>.但是,当我按Tab键缩进第二行时,只会插入一个空格而不是两个空格. 是否可以修复此问题,因此在缩进计算期间将忽略*之后的空格? 解决方法
我仍然是VimScript的初学者,但我为你做了这个.试一试,让我知道你的想法.
function AdjustSoftTabStop() " Only act if we are in a /* */ comment region if match(getline('.'),'s**') == 0 " Compensate for switching out of insert mode sometimes removing lone " final space if match(getline('.'),'*$') != -1 " Put back in the space that was removed substitute/*$/* / " Adjust position of the cursor accordingly normal l endif " Temporary new value for softtabstop; use the currect column like a " base to extend off of the normal distance let &softtabstop+=col('.') endif endfunction function ResetSoftTabStop() " Note that you will want to change this if you do not like your tabstop " and softtabstop equal. let &softtabstop=&tabstop endfunction " Create mapping to call the function when <TAB> is pressed. Note that because " this is mapped with inoremap (mapping in insert mode disallowing remapping of " character on the RHS),it does not result in infinite recursion. inoremap <TAB> <ESC>:call AdjustSoftTabStop()<CR>a<TAB><ESC>:call ResetSoftTabStop()<CR>a (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |