Created
September 8, 2021 15:40
-
-
Save lgalke/8d2a69ee7b69c5c7b34291e005e10965 to your computer and use it in GitHub Desktop.
Command to properly delete all comments from a latex file
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 characters
function! s:DeleteAllComments() range | |
" Deletes all tex comments (trailing and full line) | |
" without changing paragraph formatting. | |
" Put this function in $HOME/.vim/ftplugin/tex.vim | |
let l:save = winsaveview() " Save cursor position | |
" First: Remove full comment lines completely (to retain formatting) | |
global/\m^\s*%.*$/delete | |
" Second: Remove trailing comments (but dont match escaped \%) | |
%smagic/[^\\]\zs%.*//eI | |
" Third: Join multiple blank lines to one (aesthetics) | |
%smagic/\(\n\s*\)\{3,}/\r\r/eI | |
call winrestview(l:save) " Restore cursor position | |
endfunction | |
command! -buffer -nargs=0 DeleteAllComments :call <SID>DeleteAllComments() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment