I have this in my vimrc to comment/uncomment lines or blocks of text
in visual with the characters - (comment) and _ (uncomment)

Have a look and you'll get the idea. You have to define the symbol for
the extension
of the file you're working on

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Per a comentar/descomentar blocs de text sencers
" "-" comenta i "_" el descomenta. Cal emprar-ho en
" mode "visual"

function! SimboletComentarZsh()
map - :s/^/# /<CR>:nohlsearch<CR>
map _ :s/^\s*# \=//<CR>:nohlsearch<CR>
set comments=:#
endfunction

function! SimboletComentarFortran()
map - :s/^/C /<CR>:nohlsearch<CR>
map _ :s/^\s*C \=//<CR>:nohlsearch<CR>
set comments=:C
endfunction

function! SimboletComentarLatex()
 map - :s/^/% /<CR>:nohlsearch<CR>
 map _ :s/^\s*% \=//<CR>:nohlsearch<CR>
 set comments=:%
endfunction

" AcĂ­ definim el tipus de "comment" segons el fitxer...

autocmd FileType zsh       call SimboletComentarZsh()
autocmd FileType python    call SimboletComentarZsh()
autocmd FileType perl      call SimboletComentarZsh()
autocmd FileType sh        call SimboletComentarZsh()
autocmd FileType octave    call SimboletComentarZsh()
autocmd FileType java      call SimboletComentarJava()
autocmd FileType fortran   call SimboletComentarFortran()
autocmd FileType tex       call SimboletComentarLatex()
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

Reply via email to