How do I get NERDCommenter to add comments in a particular column?

我只是一个虾纸丫 提交于 2019-12-04 00:57:35

问题


NERDCommenter works like this by default:

//level1
    //level2
        //level3

How do I get to work like this?

//level1
//    level2
//        level3

回答1:


From the documentation:

[count]<leader>cl  
[count]<leader>cb    |NERDComAlignedComment|  

Same as |NERDComComment| except that the delimiters are aligned down the left side (cl) or both sides (cb).




回答2:


It is possible to change the default behaviour of ToggleComment (<leader>c<space>) to use left alignment. However this means changing two lines in $vimfiles/bundle/nerdcommenter/plugin/NERDCommenter.vim (assuming the usual pathogen setup for managing plugins).

Find the definition of function function s:CommentLinesToggle. As the first line add the following to determine the correct indentation index:

let leftAlignIndx = s:LeftMostIndx(a:forceNested, 0, a:firstLine, a:lastLine).

You can now use this index for setting the comment alignment. For this change the line:

let theLine = s:AddLeftDelim(s:Left({'space': 1}), theLine) to
let theLine = s:AddLeftDelimAligned(s:Left({'space': 1}), theLine, leftAlignIndx).

Done. Toggling comments now gives you:

for i in range(10):
    #if i / 2 == 0:
    #    print "Ciao"
print "finito"


来源:https://stackoverflow.com/questions/8983138/how-do-i-get-nerdcommenter-to-add-comments-in-a-particular-column

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!