nvim: plugins: Drop AnsiEsc and add a simpler replacement

Sanitises buffer by removing ANSI codes.

Idea taken from
https://www.reddit.com/r/neovim/comments/qqf4nn/comment/hk1nwnk
https://superuser.com/questions/1445805/removing-ansi-color-codes-from-a-text-file-in-vi
This commit is contained in:
Sanchayan Maity 2021-11-18 10:31:17 +05:30
parent c84e620795
commit ee584495dc
2 changed files with 16 additions and 5 deletions

View file

@ -131,11 +131,6 @@ local init = function ()
use { use {
'chentau/marks.nvim', 'chentau/marks.nvim',
} }
-- For files with ANSI escape sequences
use {
'powerman/vim-plugin-AnsiEsc',
cmd = 'AnsiEsc'
}
end end
return require('packer').startup(init) return require('packer').startup(init)

View file

@ -0,0 +1,16 @@
function! DeleteAnsiColorCodes()
set modifiable
set noconfirm
" Clean ascii/ansi code (starts with ^[)
silent! %s/\e\[[0-9:;]*m//g
silent! %s/[^[:alnum:][:punct:][:space:]]//g
silent! %s/\e\[[^\s]*\s//g
" Remove empty spaces from end
silent! %s/\s*$//
let @/ = ""
set rnu
" Map q to force quit
cnoremap q q!
endfunction
command! AnsiEsc call DeleteAnsiColorCodes()