I got this from voyeg3r’s gist
He and @dave-kennedy made it 3 years ago.
I am here 'cause I couldn’t contact them
Can someone help me add a feature such that
this vimscript code puts comment out signs at the first of each line?
my init.vim code
let s:comment_map = {
\ "c": '\/\/',
\ "cpp": '\/\/',
\ "go": '\/\/',
\ "java": '\/\/',
\ "javascript": '\/\/',
\ "lua": '--',
\ "scala": '\/\/',
\ "php": '\/\/',
\ "python": '#',
\ "ruby": '#',
\ "rust": '\/\/',
\ "sh": '#',
\ "desktop": '#',
\ "fstab": '#',
\ "conf": '#',
\ "profile": '#',
\ "bashrc": '#',
\ "bash_profile": '#',
\ "mail": '>',
\ "eml": '>',
\ "bat": 'REM',
\ "ahk": ';',
\ "vim": '"',
\ "tex": '%',
\ }
function! ToggleComment()
if has_key(s:comment_map, &filetype)
let comment_leader = s:comment_map[&filetype]
if getline('.') =~ '^\s*$'
" Skip empty line
return
endif
if getline('.') =~ '^\s*' . comment_leader
" Uncomment the line
execute 'silent s/\v\s*\zs' . comment_leader . '\s*\ze//'
else
" Comment the line
execute 'silent s/\v^(\s*)/\1' . comment_leader . ' /'
endif
else
echo "No comment leader found for filetype"
endif
endfunction
nnoremap <Leader>t :call ToggleComment()<CR>
vnoremap <Leader>t :call ToggleComment()<CR>
PS: this works perfectly. But i need the extra feature which will put comment out signs at the first of each line