Are vimrc and viminfo the same files but with different names?

29

11

Are .vimrc and .viminfo the same files but with different names?

In every tutorial there are advices to change .vimrc, but I don't have this file, only .viminfo. Are they the same?

Sergey

Posted 2011-08-15T10:29:16.933

Reputation: 1 495

Answers

40

They are not the same. The vimrc is the file you edit to change vim's behavior. It is a the configuration file.

The viminfo is like a cache, to store cut buffers persistently, and other things.

From the docs (:help viminfo):

The viminfo file is used to store:
- The command line history.
- The search string history.
- The input-line history.
- Contents of non-empty registers.
- Marks for several files.
- File marks, pointing to locations in files.
- Last search/substitute pattern (for 'n' and '&').
- The buffer list.
- Global variables.

In other words, Vim writes this file, not you.

Here's an example one (modified version of my own).

if has("python")
    python import sys
    python import os
    python import vim
    python sys.argv = [vim.eval("v:progname")] 
endif

set nocompatible            " Use Vim defaults (much better!)
set bs=2                    " allow backspacing over everything in insert mode
set nobackup                " Don't keep a backup file
set viminfo='20,\"90,h,%    " read/write a .viminfo file
set history=500
set statusline=%<%f%m%r%y%=%b\ 0x%B\ \ %l,%c%V\ %P
set laststatus=2            " always a status line

set dir=~/.vim/tmp//        " Put all swap files in common location (out of workspace and NFS volumes)
" set undodir=~/.vim/tmp/undo//
" set undofile
set hidden                  " allow editing in multiple buffers

set incsearch
set ignorecase
set smartcase

set scrolloff=3

" GUI options that need to be set here first
" Remove exta, useless button bar.
set guioptions-=T
set guioptions+=t

set encoding=utf-8

" Don't use Ex mode, use Q for formatting
map Q gq

" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
  syntax enable
  set hlsearch
  " colorscheme mycolors
endif

filetype plugin on
filetype indent on

augroup cprog
  " Remove all cprog autocommands
  au!

  " When starting to edit a file:
  "   For C and C++ files set formatting of comments and set C-indenting on.
  "   For other files switch it off.
  "   Don't change the order, it's important that the line with * comes first.
  autocmd FileType *      set formatoptions=tcql nocindent comments&
  autocmd FileType c,cpp  set formatoptions=croql cindent comments=sr:/*,mb:*,el:*/,://
augroup END

augroup newfile 
  au!
  autocmd BufNewFile            *.html  0r      ~/Templates/HTML4.html
  autocmd BufNewFile            *.xhtml 0r      ~/Templates/XHTML.xhtml
  autocmd BufNewFile            *.c     0r      ~/Templates/C.c
  autocmd BufNewFile            *.py    0r      ~/Templates/Python.py
  autocmd BufNewFile            *.js    0r      ~/Templates/Javascript.js
  autocmd BufNewFile            *.txt   0r      ~/Templates/RST.rst
  autocmd BufNewFile            *.rst   0r      ~/Templates/RST.rst
augroup END

Keith

Posted 2011-08-15T10:29:16.933

Reputation: 7 263

If you're going to the trouble of posting your own .vimrc, might be useful to indicate what each line does. (You've already commented some of them) – Stewart – 2018-09-29T20:27:27.580

2I cannot find vimrc then, I'm trying find ~ -name *vimrc, the result is empty, should I create it? – Sergey – 2011-08-15T12:21:33.277

8@Sergey: Traditionally, configuration files only appear when you, the user, create them. (It makes absolutely no sense to keep a few dozen of empty rc files for every installed program.) – user1686 – 2011-08-15T12:27:04.790

6

If .vimrc does not exist, you should create it. I recommend to host the configuration file in github, and create a symbolic link to your .vimrc

LittleSweet

Posted 2011-08-15T10:29:16.933

Reputation: 161

I currently push most of my rc files to a github repo both for the ease of duplicating my configuration across machines and for quick sharing with coworkers. What would the symbolic link help with exactly? – Qcom – 2015-08-02T23:51:48.217

2@Qcom: The symbolic link allows us to easily maintain one canonical version of our ~/.vimrc file. That version is stored in git. We can edit that file, then push it to our repository. All the other machines that pull the most recent copy of our repo will see the change. Otherwise, we would edit the file, copy it to the repo, and then push it. That's an extra step. It's also error prone since we are likely to "forget" to copy it to the repo. – ccalvert – 2015-10-02T15:29:41.110