You'll have to write a bit of custom code for this:
:echo getline(1, '$')->join(' ')->substitute('\[.\{-}]', ' ', 'g')->split('')->len()
getline(1, '$')
gets all lines as an array, join(' ')
joins all the lines to a single string, substitute('\[.\{-}]', ' ', 'g')
replaces everything between […]
with a space, split('')
splits the string to an array on whitespace, and len()
gets the array length (i.e. the word count).
You can of course map this to a command or keybind:
:command WordCount :echo getline(1, '$')->join(' ')->substitute('\[.\{-}]', ' ', 'g')->split('')->len()
nnoremap <Leader>w :echo getline(1, '$')->join(' ')->substitute('\[.\{-}]', ' ', 'g')->split('')->len()<CR>
You can, if you want to, also override the default g<C-g>
mapping, and use a bit more advanced code to duplicate the functionality from g<C-g>
.
wordcount()
function? If so, probably the simplest thing to do is filter the buffer to remove the bracketed text, run the wordcount, then restore the removed text. Otherwise I'm not sure what you mean by word count.wc
? Another tool?