Search code examples
vimautocmd

How do I tidy up my vimrc file?


My Vim configuration file is getting bigger (15KB+). And I try not to make my vim launch slower by sourcing more (larger) files at startup. For the same purpose I use only essential plugins and I try to keep the number of plugin as less as possible.

So, somewhere in my .vimrc file, I have these lines:

autocmd FileType python setlocal expandtab shiftwidth=4 tabstop=4 softtabstop=4
autocmd FileType python setlocal textwidth=78
autocmd FileType python match ErrorMsg '\%>80v.\+'
autocmd FileType python inoremap <F5> <esc>:upd\|!python %<cr>
autocmd FileType python nnoremap <F5> :upd\|!python %<cr>
autocmd FileType python nnoremap <leader>8 :w\|call Flake8()<cr>
autocmd FileType python setlocal formatoptions-=t
autocmd BufWritePost *.py call Flake8()

Now I see in first 7 lines, all lines have autocmd FileType python in common. So my thinking is, if we manage to replace all those word with something less then Vim will fire up faster. But I don't know how to do that.

Can we group them? How? Anything else?


Solution

  • Just put

    setlocal expandtab shiftwidth=4 tabstop=4 softtabstop=4 textwidth=78 formatoptions-=t
    match ErrorMsg '\%>80v.\+'
    inoremap <F5> <esc>:upd\|!python %<cr>
    nnoremap <F5> :upd\|!python %<cr>
    nnoremap <leader>8 :w\|call Flake8()<cr>
    

    in ~/.vim/after/ftplugin/python.vim.

    Vim will read this file only when you open a Python file.

    I've been meaning to do this for some time, actually. And for the same reasons.