1. 19
  1. 11

    I usually put these 23 lines in a blank ~/.vimrc:

    syntax on
    colorscheme murphy
    set textwidth=72
    set tabstop=4
    set shiftwidth=0
    set expandtab
    set autoindent
    set number
    set hlsearch
    set incsearch
    set showcmd
    set hidden
    set ruler
    set autochdir
    set nojoinspaces
    set wildmenu
    set listchars=eol:$,tab:>-,nbsp:~,trail:~
    set guioptions=ic
    autocmd BufNewFile,BufRead *.md set filetype=markdown
    autocmd BufNewFile,BufRead *.html,*.css,*.js,*.json,*.yml,*.yaml setlocal tabstop=2
    autocmd BufNewFile,BufRead *.go,Makefile* setlocal tabstop=8 noexpandtab
    autocmd BufWinEnter * syntax keyword Todo TODO
    autocmd BufWinEnter * syntax match Error /\s\+$/

    My ~/.vimrc on my home system that I use for day-to-day activities is a little larger. Here is a copy of it: github.com/susam/dotfiles - vimrc.

    On similar lines, I recently shared a small 50 line ~/.emacs helpful for quickly setting up a Common Lisp development environment here: github.com/susam/emacs4cl.

    1. 2

      +1 for syntax on. I know “I don’t NEED syntax highlighting” is the new cool thing to do, but I need every bit of help I can get disambiguating syntax!

      Also wow I didn’t know about wildmenu. Thanks for that!

      1. 2

        It’s worse for me. At this point I get distracted by the highlighting. $work has a custom IDE, and ny first month there I found out how to turn off the highlighting.

        1. 3

          Brains and eyes are different. I’m partially blind so I need every single variation and hint I can get, and you get distracted. That’s why there’s a whole universe of tools and options :)

    2. 6
      1. smartcase is IMHO better than ignorecase
      2. numbers slow Vim, I prefer ruler as is less obstructive
      3. With NeoVim lines 1, 3, 5 are not needed, number 2 is IMHO better with smartcase and I do not like line 4
      1. 3

        I had to do the same thing for an algorithmics exam at university, I came up with

        """ Condensed vimrc for exams
        syntax on
        set ai ts=4 sw=4 et nowrap number relativenumber hlsearch incsearch
        color darkblue

        The problems were ACM-style competitive programming problems, and had to be solved in C++. You could use whatever was preinstalled in their custom Fedora exam environment (they even had Eclipse and VSCode, however many students complained that they were atrociously slow on the thin clients we had). I also remember my C++ template:

        using namespace std;
        int main() {
            int n;
            cin >> n;
            while (n-- > 0) { tc(); }
        1. 2

          Not sure I would recommend turning off swap files. It happens to me not infrequently that there is a crash while I’m editing code. Swap files are also useful as a signal when a file is opened by a Vim in the background but you accidentally open it again in another Vim instance. With swap files enabled you would get a nasty warning that a swap file already exists. Not sure what would happen in that case if swap files are disabled.

          1. 2

            I have a bad habit of backgrounding vim instances with unsaved state, so I’m really happy with the swap files for when I forget they’re there and reboot (or someone else reboots a shared machine). I’m also really happy with vim’s persistent undo. I have this in my vimrc:

            set dir=${XDG_CACHE_HOME}/vim/swap//
            set backupdir=${XDG_CACHE_HOME}/vim/backup//
            set undodir=${XDG_CACHE_HOME}/vim/undo//
            set undofile
            set undolevels=1000
            set undoreload=10000

            This means that if I kill a vim session (even with kill -9 or a hard reboot), I can generally recover exactly where I was and even if I just deleted a load of stuff and then saved, I can bring it back by hitting u.

            1. 1

              Neat! I was unaware of persistent undo. Going to add this now! :)

          2. 2

            To set it up, I would run vim ~/.vimrc, manually enter those 5 lines in whichever order that I remembered them, then quit and restart Vim to pick up the new configurations.

            You should be able to run :source % to get all of those without having to restart vim first!

            1. 2

              If you like set incsearch and use neovim, you may also like set inccommand=nosplit. Funny enough too how emacs evil mode sort of defaults to a lot of these properties out of the box as well. In terms of case insensitivity I prefer rebinding search with something like noremap / /\v\c so I can delete the flags instead of toggling them after typing /

              1. 0

                highlighted, incremental search? so gross

                1. 1

                  I use this:

                  set nocp bs=2 cot= hid is ru sm t_te= t_ti= vb wim=longest,list

                  Explained at http://leahneukirchen.org/blog/archive/2020/05/a-minimal-vimrc.html

                  1. 1
                    set ts=2 sw=2 et number
                    syn on