23

I've read plenty of post on how to change the tab length in my vim editor, but only temporary changes.

I want to make the configuration permanent and my understanding is that I can configure it in the file mentioned above.

I've tried:

vim ~/.vimrc

In my home directory with no results. This just opens a new file with the name.

guntbert
  • 12,914
  • 37
  • 45
  • 86
Øystein Seel
  • 549
  • 2
  • 5
  • 19

3 Answers3

32

The path is correct but the file doesn't exist yet. It is not created by default because it's an optional way to configure your own settings.

Like with any text editor, when you call vim and enter the name of a file that doesn't exist (or is blank) it opens a blank file with that name, that's why

vim ~/.vimrc

opens an empty file. Press i, write something, and then save the file somehow by typing esc:wenter and now you have a ~/.vimrc

Should you need one, you will find an example for ~/.vimrc somewhere in /usr/share/vim/. On my system it's /usr/share/vim/vim74/vimrc_example.vim

Inside it tells you what to do if you want to use it:

" An example for a vimrc file.
"
" Maintainer:   Bram Moolenaar <Bram@vim.org>
" Last change:  2016 Mar 25
"
" To use it, copy it to
"     for Unix and OS/2:  ~/.vimrc

Lazy way to find it:

sudo updatedb && locate vimrc

Otherwise, you can make your own from scratch. Here's one wiki with some guidance on making ~/.vimrc.

Zanna
  • 69,223
  • 56
  • 216
  • 327
  • 1
    +1 for the wiki, but there is no need to copy the file. just create a new one. – LittleByBlue Jul 15 '16 at 10:03
  • 2
    what you needed to say was , if you try to open a file that doesn't exist with vi it will open an empty file which if saved (Esc : w enter) will create the file you want. – Amias Jul 15 '16 at 10:21
  • @Amias thanks for that, I couldn't quite get my words out ^_^ I have edited to make it clearer thanks to your input – Zanna Jul 15 '16 at 12:52
6

The easiest way to create a ~/.vimrc file, and have an excellent starting point for your own explorations, is to run the following from a Terminal window:

cp -v /usr/share/vim/vim*/vimrc_example.vim ~/.vimrc

Open this file with you favorite text editor and start exploring, the file is well commented and there are also endless examples on the Internet to experiment with...

andrew.46
  • 37,085
  • 25
  • 149
  • 228
0

Using following command we can find the path , it mentions the paths of vimrc along with packages (works for vim version 8.1) -

vim --version 

Kindly refer this image link

Aniruddha
  • 1
  • 1