{ pkgs, ... }:
pkgs.vim_configurable.customize {
  name = "vim-nit-latex";
  vimrcConfig.customRC = ''
    filetype on
    set encoding=utf-8
    set autoindent
    set smartindent
    set shiftwidth=4
    set tabstop=4
    set smarttab
    set expandtab
    set wrap

    syntax enable

    set cursorline
    set mousehide
    set ruler
    set number relativenumber
    set nospell

    set magic
    set ignorecase
    set smartcase
    set hlsearch
    set incsearch

    let g:eskk#directory = "~/.config/eskk"
    let g:eskk#dictionary = { 'path': "~/.config/eskk/jisyo", 'sorted': 1, 'encoding': 'utf-8', }
    let g:eskk#large_dictionary = { 'path': "~/.config/eskk/SKK-JISYO.L", 'sorted': 1, 'encoding': 'euc-jp', }
    let g:eskk#kakutei_when_unique_candidate = 0
    let g:eskk#enable_completion = 0
    let g:eskk#no_default_mappings = 1
    let g:eskk#keep_state = 0
    let g:eskk#egg_like_newline = 1

    let g:toggle_latex_eskk = 1
    function! s:latex_eskk() abort
        if &filetype == 'tex' && g:toggle_latex_eskk ==# 1
            call eskk#enable()
        endif
    endfunction

    function! s:latex_eskk_toggle() abort
        let g:toggle_latex_eskk = g:toggle_latex_eskk == 1 ? 0 : 1
        if g:toggle_latex_eskk ==# 1
            echomsg 'LaTeX Japanese Input Enabled'
        else
            echomsg 'LaTeX Japanese Input Disabled'
        endif
    endfunction

    augroup vimrc_eskk
        autocmd!
        autocmd Filetype tex nnoremap <buffer><silent> <F1> :call <SID>latex_eskk_toggle()<CR>
        autocmd User eskk-enable-post lmap <buffer> l <Plug>(eskk:disable)
    augroup END

    augroup latex_abbr
      autocmd!
      autocmd Filetype tex iabbrev <buffer> trm \textrm{}<Left>
      autocmd Filetype tex iabbrev <buffer> tsf \textsf{}<Left>
      autocmd Filetype tex iabbrev <buffer> ttt \texttt{}<Left>
      autocmd Filetype tex iabbrev <buffer> tit \textit{}<Left>
      autocmd Filetype tex iabbrev <buffer> tbf \textbf{}<Left>
      autocmd Filetype tex iabbrev <buffer> tup \textup{}<Left>
      autocmd Filetype tex iabbrev <buffer> ecl \begin{lstlisting}[language=, caption=]<CR><CR>\end{lstlisting}<ESC>2kf=a
      autocmd Filetype tex iabbrev <buffer> ecf \lstinputlisting[language=]{}
    augroup END
          
    imap jk <Plug>(eskk:toggle)
    cmap jk <Plug>(eskk:toggle)
  '';
  vimrcConfig.packages.myVimPackage = with pkgs.vimPlugins; {
    start = [ vim-eskk ];
    opt = [];
  };
}
