Created
March 3, 2014 05:07
Revisions
-
sooop revised this gist
Mar 3, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -43,7 +43,7 @@ function! CheckIsComment(line_number) let c = 0 while c < strlen(sl) let d = c + strlen(s:comment_prefix) - 1 "sl[c] is space or tabe? if " \t" =~ sl[c] " ignore indentation " pass -
sooop revised this gist
Mar 3, 2014 . 1 changed file with 7 additions and 7 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,12 @@ " toggle comment line function! SetCommentPrefix() let s:comment_prefix = "#" if &filetype == "vim" " for vim, inline comment start with \" let s:comment_prefix = "\"" elseif &filetype ==? "c" || &filetype ==? "objc" || &filetype ==? "cpp" let s:comment_prefix = "//" endif endfunction @@ -18,7 +18,7 @@ function! CommentLine(line_number) " move to seletced line call setpos(".", [0, a:line_number, 0, 0]) " just insert comment prefix character at the front of given line exec "normal! I".s:comment_prefix "restore cursor position call setpos(".", cpos) endfunction @@ -30,7 +30,7 @@ function! UncommentLine(line_number) "move to selected line call setpos(".", [0, a:line_number, 0, 0]) " remove comment prefix charactor exec ".s/".escape(s:comment_prefix, s:comment_prefix[0])."//" " restore cursor position call setpos(".", cpos) endfunction @@ -42,12 +42,12 @@ function! CheckIsComment(line_number) let sl = getline(a:line_number) let c = 0 while c < strlen(sl) let d = c + strlen(s:comment_prefix) - 1 " sl[c] is space or tabe? if " \t" =~ sl[c] " ignore indentation " pass elseif sl[(c):(d)] == s:comment_prefix return 1 else return 0 -
sooop revised this gist
Mar 3, 2014 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -37,6 +37,7 @@ endfunction function! CheckIsComment(line_number) call SetCommentPrefix() " check the line for given line number is comment let sl = getline(a:line_number) let c = 0 -
sooop revised this gist
Mar 3, 2014 . 1 changed file with 1 addition and 5 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -30,11 +30,7 @@ function! UncommentLine(line_number) "move to selected line call setpos(".", [0, a:line_number, 0, 0]) " remove comment prefix charactor exec ".s/".escape(b:comment_prefix, b:comment_prefix[0])."//" " restore cursor position call setpos(".", cpos) endfunction -
sooop revised this gist
Mar 3, 2014 . 1 changed file with 10 additions and 3 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,6 +5,8 @@ function! SetCommentPrefix() if &filetype == "vim" " for vim, inline comment start with \" let b:comment_prefix = "\"" elseif &filetype ==? "c" || &filetype ==? "objc" || &filetype ==? "cpp" let b:comment_prefix = "//" endif endfunction @@ -17,7 +19,7 @@ function! CommentLine(line_number) call setpos(".", [0, a:line_number, 0, 0]) " just insert comment prefix character at the front of given line exec "normal! I".b:comment_prefix "restore cursor position call setpos(".", cpos) endfunction @@ -28,7 +30,11 @@ function! UncommentLine(line_number) "move to selected line call setpos(".", [0, a:line_number, 0, 0]) " remove comment prefix charactor if &filetype ==? 'c' || &filetype ==? "objc" || &filetype ==? "cpp" exec ".s/".escape(b:comment_prefix, '/')."//" else exec ".s/".b:comment_prefix."//" endif " restore cursor position call setpos(".", cpos) endfunction @@ -39,11 +45,12 @@ function! CheckIsComment(line_number) let sl = getline(a:line_number) let c = 0 while c < strlen(sl) let d = c + strlen(b:comment_prefix) - 1 " sl[c] is space or tabe? if " \t" =~ sl[c] " ignore indentation " pass elseif sl[(c):(d)] == b:comment_prefix return 1 else return 0 -
sooop revised this gist
Mar 3, 2014 . 1 changed file with 12 additions and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,36 +3,46 @@ function! SetCommentPrefix() let b:comment_prefix = "#" if &filetype == "vim" " for vim, inline comment start with \" let b:comment_prefix = "\"" endif endfunction function! CommentLine(line_number) call SetCommentPrefix() " remember current cursor position let cpos = getpos(".") " move to seletced line call setpos(".", [0, a:line_number, 0, 0]) " just insert comment prefix character at the front of given line exec "normal! I".b:comment_prefix " restore cursor position call setpos(".", cpos) endfunction function! UncommentLine(line_number) call SetCommentPrefix() " remember current cursor position let cpos = getpos(".") "move to selected line call setpos(".", [0, a:line_number, 0, 0]) " remove comment prefix charactor exec ".s/".b:comment_prefix."//" " restore cursor position call setpos(".", cpos) endfunction function! CheckIsComment(line_number) " check the line for given line number is comment let sl = getline(a:line_number) let c = 0 while c < strlen(sl) " sl[c] is space or tabe? if " \t" =~ sl[c] " ignore indentation " pass elseif sl[c] == b:comment_prefix return 1 else @@ -55,6 +65,7 @@ endfunction function! ToggleCommentRange() let line_begin = line("'<") let line_end = line("'>") " decide mode with first line in selection let mode_ = CheckIsComment(line_begin) let cpos = getpos(".") let i = line_begin -
sooop revised this gist
Mar 3, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -22,7 +22,7 @@ function! UncommentLine(line_number) let cpos = getpos(".") "move to selected line call setpos(".", [0, a:line_number, 0, 0]) exec ".s/".b:comment_prefix."//" call setpos(".", cpos) endfunction -
sooop created this gist
Mar 3, 2014 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,72 @@ " toggle comment line function! SetCommentPrefix() let b:comment_prefix = "#" if &filetype == "vim" let b:comment_prefix = "\"" endif endfunction function! CommentLine(line_number) call SetCommentPrefix() let cpos = getpos(".") " move to seletced line call setpos(".", [0, a:line_number, 0, 0]) exec "normal! I".b:comment_prefix call setpos(".", cpos) endfunction function! UncommentLine(line_number) call SetCommentPrefix() let cpos = getpos(".") "move to selected line call setpos(".", [0, a:line_number, 0, 0]) exec ".s/".b:comment_prefix."\\+//" call setpos(".", cpos) endfunction function! CheckIsComment(line_number) let sl = getline(a:line_number) let c = 0 while c < strlen(sl) if " \t" =~ sl[c] "pass elseif sl[c] == b:comment_prefix return 1 else return 0 endif let c += 1 endwhile return 0 endfunction function! ToggleCommentLine() let cl = line(".") if CheckIsComment(cl) call UncommentLine(cl) else call CommentLine(cl) endif endfunction function! ToggleCommentRange() let line_begin = line("'<") let line_end = line("'>") let mode_ = CheckIsComment(line_begin) let cpos = getpos(".") let i = line_begin while i < line_end + 1 if mode_ call UncommentLine(i) else call CommentLine(i) endif let i+=1 endwhile endfunction nnoremap <leader>\ :call ToggleCommentLine()<cr> vnoremap <leader>\ <esc> :call ToggleCommentRange()<cr>