Skip to content

Instantly share code, notes, and snippets.

@r00k
Last active May 13, 2023 09:34
Show Gist options
  • Star 46 You must be signed in to star a gist
  • Fork 17 You must be signed in to fork a gist
  • Save r00k/8fc7e4e9d35ccbfb64aa to your computer and use it in GitHub Desktop.
Save r00k/8fc7e4e9d35ccbfb64aa to your computer and use it in GitHub Desktop.
A minimal vimrc for beginners
" A minimal vimrc for new vim users to start with.
"
" Referenced here: http://www.benorenstein.com/blog/your-first-vimrc-should-be-nearly-empty/
" Original Author: Bram Moolenaar <Bram@vim.org>
" Made more minimal by: Ben Orenstein
" Last change: 2012 Jan 20
"
" To use it, copy it to
" for Unix and OS/2: ~/.vimrc
" for MS-DOS and Win32: $VIM\_vimrc
"
" If you don't understand a setting in here, just type ':h setting'.
" Switch syntax highlighting on
syntax on
" Make backspace behave in a sane manner.
set backspace=indent,eol,start
" Enable file type detection and do language-dependent indenting.
filetype plugin indent on
@munyari
Copy link

munyari commented Apr 6, 2016

Hey Ben, would you recommend this over vim-sensible? Also, no line numbers?

@ryanolsonx
Copy link

When Vim detects a .vimrc, it automatically sets nocompatible. So - line 17 isn't needed in this vimrc.

@r00k
Copy link
Author

r00k commented Dec 28, 2019

When Vim detects a .vimrc, it automatically sets nocompatible. So - line 17 isn't needed in this vimrc.

Interesting!

Any chance you can link to some docs saying this just so I can confirm before deleting it?

@ryanolsonx
Copy link

ryanolsonx commented Dec 30, 2019

:help 'nocompatible'

'compatible' 'cp' 'nocompatible' 'nocp'
'compatible' 'cp' boolean (default on, off when a |vimrc| or |gvimrc|
file is found, reset in |defaults.vim|)
global

@ryanolsonx
Copy link

Another thing you could do (if desired) is change set backspace=indent,eol,start to set backspace=2. It's the same as the previous one.

@ryanolsonx
Copy link

" If you don't understand a setting in here, just type ':h setting'.

The correct way to find one of these settings should be :h 'setting'. For example, if you ran :h backspace, it doesn't give you what you want. However, if you run :h 'backspace', it'll find the configuration option that you can set.

@goalaleo
Copy link

It seems like set backspace=indent,eol,start is the default behaviour. If I run :help 'backspace' :

                                                        *'backspace'* *'bs'*
'backspace' 'bs'        string  (default "", set to "indent,eol,start"
                                                            in |defaults.vim|)
                        global
                        {not in Vi}
...

Here's the line in the vim repo

@r00k
Copy link
Author

r00k commented Jan 27, 2020

Thanks for the pointers, @ryanolsonx and @goalaleo. I've removed those settings. Getting even more minimal!

@ryanolsonx
Copy link

@goalaleo You're wrong. (I tried to think of a nice way to say this - please don't take this in an aggressive manner)

TLDR: set backspace=indent,eol,start is not the default. set backspace= is. If you don't have a vimrc, defaults.vim will run, which will change backspace (to what you mentioned). If you have a vimrc, Vim will not run defaults.vim and so your backspace will use the default ("").

More explanation:

It seems like set backspace=indent,eol,start is the default behaviour. If I run :help 'backspace' :

It's more complicated than that.

'backspace' 'bs' string (default "", set to "indent,eol,start"

As you can see, the default is "". This means that your backspace functionality will be limited.

This leads me to defaults.vim.

'backspace' 'bs' string (default "", set to "indent,eol,start"
in |defaults.vim|)

Your configuration was changed in defaults.vim. To explore why it was set in defaults.vim, you need to understand when defaults.vim is applied.

In the vim repo, it says:

" This is loaded if no vimrc file was found.
" Except when Vim is run with "-u NONE" or "-C".

So - once you create a vimrc file, the defaults.vim will not run (unless you do something fancy that I'll list below).

If you do want to use the Vim defaults.vim (which is an opt-in sort of thing so that configs don't break that rely on previous Vim behavior), you can put this in your Vim config near the top:

unlet! skip_defaults_vim
source $VIMRUNTIME/defaults.vim

@ryanolsonx
Copy link

ryanolsonx commented Jan 27, 2020

Getting even more minimal!

That's awesome. It's nice getting things more minimal! Just for fun, here's my current minimalist configuration that I use for serious, day-to-day frontend and backend development.

@goalaleo
Copy link

goalaleo commented Jan 28, 2020

Thanks for the explanation @ryanolsonx and no offence taken :) I'm just starting to learn vim and misunderstood the docs (didn't realise that defaults.vim is not loaded if .vimrc is found)!

@aiformds
Copy link

For beginners, maybe split the last setting into its parts to be more explicit? Or not, no strong feelings here.

" Enable file type detection and do language-dependent indenting.
filetype plugin on
filetype indent on

@vvznz
Copy link

vvznz commented Sep 25, 2021

@ryanolsonx Thanks for the elaboration. Just letting you know that your link is broken. I started to learn (or rather re-learn) Vim again and want to do it this time from scratch.

@ryanolsonx
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment