Skip to content

Instantly share code, notes, and snippets.

@wolandark
Created November 14, 2024 09:42
Show Gist options
  • Select an option

  • Save wolandark/885c79374bb686f482ae3002cb630af8 to your computer and use it in GitHub Desktop.

Select an option

Save wolandark/885c79374bb686f482ae3002cb630af8 to your computer and use it in GitHub Desktop.

Revisions

  1. wolandark created this gist Nov 14, 2024.
    70 changes: 70 additions & 0 deletions text.vim
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,70 @@
    " ~/.vim/after/ftplugin/text.vim

    let line_count = line('$')
    let b:word_count = 0

    " TTS using vim-piper plugin. Point to your installation
    let g:piper_bin='/home/woland/tmp/piper/piper-bin/piper/piper'
    let g:piper_voice='/home/woland/tmp/piper/piper-voices/en/en_US/joe/medium/en_US-joe-medium.onnx'

    " This condition is for those who read large txt file in vim
    if line_count > 1000
    colorscheme habamax
    setlocal laststatus=0 showtabline=0
    syntax off
    filetype plugin indent off
    else
    colorscheme slate
    setlocal wrap textwidth=0
    setlocal linebreak showbreak=
    setlocal scrolloff=50 foldmethod=marker
    setlocal list listchars=tab:▷\ ,trail:.
    setlocal spell! spelllang=en_us spellsuggest=double,5
    setlocal wildmode=longest,list,full
    setlocal laststatus=2 pumheight=10

    syntax off
    filetype plugin indent off

    packadd vim-ddgpb " for searching ddg from vim either in xdg-browser or in w3m and tmux
    packadd vimdict " vim interface for dictd
    packadd vim-piper " vim interface to piper tts
    packadd vim-highlighter " highlighting plugin (not mine)

    nnoremap ]g ]s
    nnoremap [g [s
    nnoremap j gj
    nnoremap k gk
    inoremap <Tab> <C-n>
    inoremap <S-Tab> <C-p>
    nnoremap <ESC> :nohlsearch<CR><ESC>
    endif

    " Functions
    function! UpdateWordCount()
    let lines = getline(1, '$')
    let full_text = join(lines, " ")
    let words = split(full_text, '\W\+')
    let b:word_count = len(words)
    endfunction

    function FixSpell()
    normal! 1z=
    endfunction
    command! FixSpell call FixSpell()
    nnoremap gs :FixSpell<CR>
    " Autocmds
    augroup WordCount
    autocmd!
    autocmd VimEnter,BufReadPost,BufWritePost,TextChanged,TextChangedI * call UpdateWordCount()
    autocmd VimEnter * highlight SpellBad ctermfg=16 ctermbg=68 guifg=#000000 guibg=#5f87d7 cterm=italic
    autocmd VimEnter * :Hi load
    autocmd VimLeave * :Hi save
    augroup END

    " StatusLine
    setlocal statusline=%f\ %r%=%{b:word_count}w\ %l/%L

    highlight StatusLine guifg=#afaf87 guibg=#333333
    highlight StatusLineNC guifg=#afaf87 guibg=#333333