Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- " Comments and Uncomment lines
- " ******************************
- " Usage:
- " To comment lines by pressing CTRL-K with/without visual selection (CTRL-V)
- " To uncomment lines by pressing CTRL-L with/without visual selection (CTRL-V)
- " Author: Anjishnu Sarkar
- " Version: 1.0
- " Date: 15/04/07
- " Vim Version: 6.0+
- " Installation: Copy this file in your $HOME/.vim/plugin directory
- " Acknowledgement: www.vim.org -> Vim_Tip #271, comments.vim
- " ##############################################################
- "
- " BUG: (i) Same filebuffer used when different kind of file opened using
- " :sp command. As such comments in 2nd file are not according to filetype
- " -> Soln: Recognize file type ?
- "
- " TODO: To fix the above bug
- " ##############################################################
- if v:version < 600 " Exit if Vim version is less than 6.0
- " echohl WarningMsg
- " echo "You need vim version 6.0 or higher"
- " echohl None
- finish
- elseif exists ("g:loaded_lines_comment") || &cp
- " Exit quickly when:
- " - when 'compatible' is set
- " - this plugin was already loaded (or disabled)
- finish
- else " Load the script
- let g:loaded_lines_comment = 1
- endif
- " ### Comment and Uncomment vim script starts ###
- "let file_ext = buffer_name("%")
- let file_ext = bufname("%") " bufname = buffer_name
- " lhs comments
- " For Fortran files: .for, .f90: !
- if file_ext =~ '\.f$' || file_ext =~ '\.for$' || file_ext =~ '\.f90$' || file_ext =~ '\.f95$' || file_ext =~ '\.nml$'
- map <c-k> :s/^/! /<CR>:nohlsearch<CR><CR>
- map <c-l> :s/^\s*! \=//<CR>:nohlsearch<CR><CR>
- " For latex files: .tex, .bib, .sty, .bbl: %
- elseif file_ext =~ '\.tex$' || file_ext =~ '\.bib$' || file_ext =~ '\.sty$' || file_ext =~ '\.bbl$' || file_ext =~ '\.cls$' || file_ext =~ '\.not$' || file_ext =~ '\.clo$' || file_ext =~ '\.ldf$'
- map <c-k> :s/^/% /<CR>:nohlsearch<CR><CR>
- map <c-l> :s/^\s*% \=//<CR>:nohlsearch<CR><CR>
- " For latex files: .frm : *
- elseif file_ext =~ '\.frm$'
- map <c-k> :s/^/* /<CR>:nohlsearch<CR><CR>
- map <c-l> :s/^\s*\* \=//<CR>:nohlsearch<CR><CR>
- " For batch files: .bat, .com: REM/rem
- elseif file_ext =~ '\.bat$' || file_ext =~ '\.cmd$'
- map <c-k> :s/^/REM /<CR>:nohlsearch<CR><CR>
- map <c-l> :set ignorecase<CR>:s/^\s*rem \=//<CR>:nohlsearch<CR><CR>
- " For vim files: .vim, .vimrc, .gvimrc: "
- elseif file_ext =~ '\.vim$' || file_ext =~ '\.vimrc$' || file_ext =~ '\.gvimrc$'
- map <c-k> :s/^/" /<CR>:nohlsearch<CR><CR>
- map <c-l> :s/^\s*" \=//<CR>:nohlsearch<CR><CR>
- " For .cc, .cpp, .hpp, .java, .php[23] files: //
- elseif file_ext =~ '\.cc$' || file_ext =~ '\.cpp$' || file_ext =~ '\.hpp$' || file_ext =~ '\.java$' || file_ext =~ '\.php[23]\?$'
- map <c-k> :s/^/\/\/ /<CR>:nohlsearch<CR><CR>
- map <c-l> :s/^\s*\/\/ \=//<CR>:nohlsearch<CR><CR>
- " For .plt, .gnu, .gpi files: #
- elseif file_ext =~ '\.plt$' || file_ext =~ '\.gnu$' || file_ext =~ '\.gpi$'
- map <c-k> :s/^/# /<CR>:nohlsearch<CR><CR>
- map <c-l> :s/^\s*# \=//<CR>:nohlsearch<CR><CR>
- " For .sql files: --
- elseif file_ext =~ '\.sql$'
- map <c-k> :s/^/-- /<CR>:nohlsearch<CR><CR>
- map <c-l> :s/^\s*-- \=//<CR>:nohlsearch<CR><CR>
- " For .ksh .sh, .csh, .pl, .pm files: #
- elseif file_ext =~ '\.ksh$' || file_ext =~ '\.sh$' || file_ext =~ '\.csh$' || file_ext =~ '\.pl$' || file_ext =~ '\.pm$'
- map <c-k> :s/^/# /<CR>:nohlsearch<CR><CR>
- map <c-l> :s/^\s*# \=//<CR>:nohlsearch<CR><CR>
- " For .eps, .ps, .map files: %
- elseif file_ext =~ '\.ps$' || file_ext =~ '\.eps$' || file_ext =~ '\.map$'
- map <c-k> :s/^/% /<CR>:nohlsearch<CR><CR>
- map <c-l> :s/^\s*% \=//<CR>:nohlsearch<CR><CR>
- " For ~/.Xdefaults ~/.XResources files: >
- elseif file_ext =~ '\.Xdefaults$' || file_ext =~ '\.XResources$'
- map <c-k> :s/^/! /<CR>:nohlsearch<CR><CR>
- map <c-l> :s/^\s*! \=//<CR>:nohlsearch<CR><CR>
- " For .msg files: >
- elseif file_ext =~ '\.msg$'
- map <c-k> :s/^/> /<CR>:nohlsearch<CR><CR>
- map <c-l> :s/^\s*> \=//<CR>:nohlsearch<CR><CR>
- " For .m (Matlab) files: %
- elseif file_ext =~ '\.m$'
- map <c-k> :s/^/% /<CR>:nohlsearch<CR><CR>
- map <c-l> :s/^\s*% \=//<CR>:nohlsearch<CR><CR>
- " For .sce, .sci (Scilab) files: %
- elseif file_ext =~ '\.sce$' || file_ext =~ '\.sci$'
- map <c-k> :s/^/\/\/ /<CR>:nohlsearch<CR><CR>
- map <c-l> :s/^\s*\/\/ \=//<CR>:nohlsearch<CR><CR>
- " For .lua (Lua script) files: --
- elseif file_ext =~ '\.lua$'
- map <c-k> :s/^/-- /<CR>:nohlsearch<CR><CR>
- map <c-l> :s/^\s*-- \=//<CR>:nohlsearch<CR><CR>
- " Wrapping comments
- " For .m (Mathematica files): (* *)
- " elseif file_ext =~ '\.m$'
- " map <c-k> :s/^\(.*\)$/\(\* \1 \*\)/<CR>:nohlsearch<CR><CR>
- " map <c-l> :s/^\([/(]\*\\|<!--\) \(.*\) \(\*[/)]\\|-->\)$/\2/<CR>:nohlsearch<CR><CR>
- " For .c, .h, .pc, .css, .js: /* */
- elseif file_ext =~ '\.c$' || file_ext =~ '\.h$' || file_ext =~ '\.pc$' || file_ext =~ '\.css$' || file_ext =~ '\.js$'
- map <c-k> :s/^\(.*\)$/\/\* \1 \*\//<CR>:nohlsearch<CR><CR>
- map <c-l> :s/^\([/(]\*\\|<!--\) \(.*\) \(\*[/)]\\|-->\)$/\2/<CR>:nohlsearch<CR><CR>
- " For .mac, .wxm, .mxm (Maxima files): /* */
- elseif file_ext =~ '\.mac$' || file_ext =~ '\.wxm$' || file_ext =~ '\.mxm$'
- map <c-k> :s/^\(.*\)$/\/\* \1 \*\//<CR>:nohlsearch<CR><CR>
- map <c-l> :s/^\([/(]\*\\|<!--\) \(.*\) \(\*[/)]\\|-->\)$/\2/<CR>:nohlsearch<CR><CR>
- " For .html, .htm, .xhtml, .xml files: <!-- -->
- elseif file_ext =~ '\.html$' || file_ext =~ '\.htm$' || file_ext =~ '\.xml$' || file_ext =~ '\.xhtml$'
- map <c-k> :s/^\(.*\)$/<!-- \1 -->/<CR>:nohlsearch<CR><CR>
- map <c-l> :s/^\([/(]\*\\|<!--\) \(.*\) \(\*[/)]\\|-->\)$/\2/<CR>:nohlsearch<CR><CR>
- " For all other files (Eg: .bashrc, .bash_profile): #
- else
- map <c-k> :s/^/# /<CR>:nohlsearch<CR><CR>
- map <c-l> :s/^\s*# \=//<CR>:nohlsearch<CR><CR>
- endif
- " ### Comment and Uncomment vim script ends ###
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement