-
-
Notifications
You must be signed in to change notification settings - Fork 447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature request] Comment by codes' indent #413
Comments
@zoumi I'm not sure that "indent" is actually what you are after here. Indent in particular is a very difficult thing the quantify in most language. It depends on your coding style of course, but I wondering if even your example wouldn't be better off with a different selection method. Have you considered using that the example you give would actually work fine with the existing paragraph text object and even play very nicely with a function closure based text object. For example I use kana/vim-textobj-function and haya14busa/vim-textobj-function-syntax plugins and it is very easy for me to select and comment out and function that I'm inside of. I'm happy to consider merging any PR that contributes such an indent feature that works reasonably well, but I will likely not be coding such a thing up myself. |
I have write a pieces of code,but I don't know how to pass the line start and end to nerdcommenter. func! s:GetIndent(str)
let l:cur_indent = ""
let l:cur_indent_end=matchend(a:str,'^\s*\S')
if l:cur_indent_end==-1
return -1
endif
echo l:cur_indent_end
if l:cur_indent_end>1
return strpart(a:str,0,l:cur_indent_end-1)
"return a:str[0:l:cur_indent_end-1]
endif
return l:cur_indent
endfunc
func! IndentComment()
let l:first_line_num=line('.')
let l:first_indent=s:GetIndent(getline('.'))
if l:first_indent==-1
let l:first_indent=''
endif
let l:differ_indent_found=0
let l:line_num=l:first_line_num+1
let l:line_content = getline(l:line_num)
let l:total_line = line('$')
while l:line_num < l:total_line
let l:indent=s:GetIndent(l:line_content)
if l:indent!=-1
if l:indent != l:first_indent
let l:differ_indent_found=1
else
if l:differ_indent_found==1
"find finished here
let l:end_line_num= l:line_num
echomsg l:line_num
"how to do here
"the code between first_line_num and end_line_num should be comment out
call NERDComment(1,'sexy')<CR>
return
endif
endif
endif
let l:line_num=l:line_num+1
let l:line_content = getline(l:line_num)
endwhile
endfunc
nmap <Leader>ic :call IndentComment()<CR> |
Assume we have these c codes, and the cursor is at the first line(normal mode)
after we trigger an "indent comment",we get
The text was updated successfully, but these errors were encountered: