vimrc和viminfo是相同的文件,但名称不同吗?


29

.vimrc.viminfo相同的文件,但名称不同吗?

每个教程中都有更改建议.vimrc,但是我没有这个文件.viminfo。他们是一样的吗?

Answers:


40

它们不一样。vimrc是您编辑以更改vim行为的文件。这是一个配置文件。

viminfo就像一个高速缓存,用于永久存储剪切缓冲区等。

从文档(: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.

换句话说,Vim会写入此文件,而不是您。

这是一个示例(我自己的修改版本)。

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

2
我找不到vimrc,然后尝试找到〜-name * vimrc,结果为空,我应该创建它吗?
谢尔盖(Sergey)

8
@Sergey:传统上,配置文件只出现在的用户,创建它们。(为每个已安装的程序保留几十个空的rc文件绝对没有道理。)
grawity 2011年

如果您要麻烦自己发布.vimrc,可能有助于指出每一行的功能。(您已经评论了其中的一些内容)
Stewart

6

如果.vimrc不存在,则应创建它。我建议将配置文件托管在github中,并创建指向.vimrc的符号链接。


我目前将大多数rc文件都推送到github仓库中,这既便于在计算机之间复制配置,又可以与同事快速共享。该符号链接到底有什么帮助?
Qcom 2015年

2
@Qcom:符号链接使我们可以轻松维护〜/ .vimrc文件的一个规范版本。该版本存储在git中。我们可以编辑该文件,然后将其推送到我们的存储库。所有其他提取我们仓库最新副本的机器都将看到更改。否则,我们将编辑文件,将其复制到仓库中,然后推送。这是一个额外的步骤。这也容易出错,因为我们可能会“忘记”将其复制到存储库中。
ccalvert
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.