Vim 无法识别我的 vimrc 文件

Vim 无法识别我的 vimrc 文件

我正在尝试将我的本地 vimrc 配置复制到我刚刚设置的新 Linux 服务器:

scp -rp .vim/ nagios:~
scp .vimrc nagios:~

然后,在ls -hoal远程机器上的我的~目录中:

drwxr-xr-x 4 <me>   51 Jun 29 13:34 .vim
-rw-r--r-- 1 <me>   431 Jul  7 10:59 .vimrc

当我启动 vim 时vi(因为这是一个没有 vim 符号链接的 centos 服务器)我的 vimrc 无法加载。

我发现这个 StackOverflow 问题这提出了一些建议,但都没有奏效。例如:

在接受的答案中,我可以看到它找到并读取了我的 vimrc 文件,作为参考,这是我的 vimrc:

execute pathogen#infect()

set shiftwidth=2
set softtabstop=2
set tabstop=2

autocmd Filetype yml setlocal ts=2 sw=2 expandtab autoindent
syntax on
filetype plugin indent on

set autoindent

set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*

let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0

以下是我在 vim strace 文件中找到的内容:

fchdir(3)                               = 0
chdir("<my home>)        = 0
getcwd("<my home>", 4096) = 24
fchdir(3)                               = 0
close(3)                                = 0
stat("<my home>/.vimrc", {st_mode=S_IFREG|0644, st_size=431, ...}) = 0
open("<my home>/.vimrc", O_RDONLY) = 3
fcntl(3, F_GETFD)                       = 0
fcntl(3, F_SETFD, FD_CLOEXEC)           = 0
fcntl(3, F_GETFL)                       = 0x8000 (flags O_RDONLY|O_LARGEFILE)
fstat(3, {st_mode=S_IFREG|0644, st_size=431, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fadbac2e000
read(3, "execute pathogen#infect()\n\nset s"..., 4096) = 431
read(3, "", 4096)                       = 0
read(3, "", 4096)                       = 0
close(3)                                = 0

因此看起来它找到了它,读了几行,然后就死了。

但是,该问题中获得最多投票的答案建议检查其他几件事。当我:scriptnames在本地(工作)vim 安装上运行时,我看到:

  1: /usr/share/vim/vimrc
  2: /usr/share/vim/vim74/debian.vim
  3: /usr/share/vim/vim74/syntax/syntax.vim
  4: /usr/share/vim/vim74/syntax/synload.vim
  5: /usr/share/vim/vim74/syntax/syncolor.vim
  6: /usr/share/vim/vim74/filetype.vim
  7: ~/.vimrc
  8: ~/.vim/autoload/pathogen.vim

然后是其他一些内容,即加载我所有的其他插件以及其中的一些内容/usr/share/vim

运行:echo $HOME和/或:echo $MYVIMRC工作也按预期进行。

但是,当我在远程机器上尝试此操作时,上述三个命令均未获得任何输出。

我的本地机器是 Xubuntu 14.04,其输出如下vi --version

vi --version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Jan  2 2014 19:39:32)
Included patches: 1-52
Modified by [email protected]
Compiled by buildd@
Huge version without GUI.  Features included (+) or not (-):
... bunch of what's enabled ...
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  fall-back for $VIM: "/usr/share/vim"
... compilation options ...

在远程机器上,我正在运行具有精确版本centos-release-7-2.1511.el7.centos.2.10.x86_64和 vim 版本的 centos:

 vi --version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Jun 10 2014 06:56:12)
Included patches: 1-160
Modified by <[email protected]>
Compiled by <[email protected]>
Small version without GUI.  Features included (+) or not (-):
... what's included ...
   system vimrc file: "/etc/virc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  fall-back for $VIM: "/etc"
 f-b for $VIMRUNTIME: "/usr/share/vim/vim74"
... compilation options ...

所以问题归结为:如何让 vim 正确读取我.vimrc

编辑:

通过 yum安装vim-enhanced然后使用vim(而不是vi)已经“解决”了这个问题,但我仍然想知道是否有可能让它与开箱即用的 vi 一起工作,因为安装vim-enhanced并不总是一种选择。作为参考,以下是各种版本信息的完整输出:

Centos vi:

vi --version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Jun 10 2014 06:56:12)
Included patches: 1-160
Modified by <[email protected]>
Compiled by <[email protected]>
Small version without GUI.  Features included (+) or not (-):
+acl             -farsi           -mouse_sgr       -tag_old_static
-arabic          -file_in_path    -mouse_sysmouse  -tag_any_white
-autocmd         -find_in_path    -mouse_urxvt     -tcl
-balloon_eval    -float           -mouse_xterm     +terminfo
-browse          -folding         +multi_byte      -termresponse
+builtin_terms   -footer          -multi_lang      -textobjects
-byte_offset     +fork()          -mzscheme        -title
-cindent         -gettext         -netbeans_intg   -toolbar
-clientserver    -hangul_input    -path_extra      -user_commands
-clipboard       +iconv           -perl            -vertsplit
-cmdline_compl   -insert_expand   -persistent_undo -virtualedit
+cmdline_hist    +jumplist        -printer         +visual
-cmdline_info    -keymap          -profile         -visualextra
-comments        -langmap         -python          -viminfo
-conceal         -libcall         -python3         -vreplace
-cryptv          -linebreak       -quickfix        +wildignore
-cscope          -lispindent      -reltime         -wildmenu
-cursorbind      -listcmds        -rightleft       +windows
-cursorshape     -localmap        -ruby            +writebackup
-dialog          -lua             -scrollbind      -X11
-diff            -menu            -signs           -xfontset
-digraphs        -mksession       -smartindent     -xim
-dnd             -modify_fname    -sniff           -xsmp
-ebcdic          -mouse           -startuptime     -xterm_clipboard
-emacs_tags      -mouse_dec       -statusline      -xterm_save
-eval            -mouse_gpm       -sun_workshop    -xpm
-ex_extra        -mouse_jsbterm   -syntax          
-extra_search    -mouse_netterm   -tag_binary      
   system vimrc file: "/etc/virc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  fall-back for $VIM: "/etc"
 f-b for $VIMRUNTIME: "/usr/share/vim/vim74"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H     -O2 -g -pipe -Wall -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches   -m64 -mtune=generic -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1      
Linking: gcc   -Wl,-z,relro  -L/usr/local/lib -Wl,--as-needed -o vim        -lm  -lselinux -lncurses -lacl -lattr -ldl  

Centos vim:

vim --version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Jun 10 2014 06:55:55)
Included patches: 1-160
Modified by <[email protected]>
Compiled by <[email protected]>
Huge version without GUI.  Features included (+) or not (-):
+acl             +farsi           +mouse_netterm   +syntax
+arabic          +file_in_path    +mouse_sgr       +tag_binary
+autocmd         +find_in_path    -mouse_sysmouse  +tag_old_static
-balloon_eval    +float           +mouse_urxvt     -tag_any_white
-browse          +folding         +mouse_xterm     -tcl
++builtin_terms  -footer          +multi_byte      +terminfo
+byte_offset     +fork()          +multi_lang      +termresponse
+cindent         +gettext         -mzscheme        +textobjects
-clientserver    -hangul_input    +netbeans_intg   +title
-clipboard       +iconv           +path_extra      -toolbar
+cmdline_compl   +insert_expand   +perl            +user_commands
+cmdline_hist    +jumplist        +persistent_undo +vertsplit
+cmdline_info    +keymap          +postscript      +virtualedit
+comments        +langmap         +printer         +visual
+conceal         +libcall         +profile         +visualextra
+cryptv          +linebreak       +python/dyn      +viminfo
+cscope          +lispindent      -python3         +vreplace
+cursorbind      +listcmds        +quickfix        +wildignore
+cursorshape     +localmap        +reltime         +wildmenu
+dialog_con      -lua             +rightleft       +windows
+diff            +menu            +ruby/dyn        +writebackup
+digraphs        +mksession       +scrollbind      -X11
-dnd             +modify_fname    +signs           -xfontset
-ebcdic          +mouse           +smartindent     -xim
+emacs_tags      -mouseshape      -sniff           -xsmp
+eval            +mouse_dec       +startuptime     -xterm_clipboard
+ex_extra        +mouse_gpm       +statusline      -xterm_save
+extra_search    -mouse_jsbterm   -sun_workshop    -xpm
   system vimrc file: "/etc/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  fall-back for $VIM: "/etc"
 f-b for $VIMRUNTIME: "/usr/share/vim/vim74"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H     -O2 -g -pipe -Wall -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches   -m64 -mtune=generic -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1      
Linking: gcc   -L. -Wl,-z,relro -fstack-protector -rdynamic -Wl,-export-dynamic -Wl,--enable-new-dtags -Wl,-rpath,/usr/lib64/perl5/CORE  -Wl,-z,relro  -L/usr/local/lib -Wl,--as-needed -o vim        -lm -lnsl  -lselinux  -lncurses -lacl -lattr -lgpm -ldl   -Wl,--enable-new-dtags -Wl,-rpath,/usr/lib64/perl5/CORE  -fstack-protector  -L/usr/lib64/perl5/CORE -lperl -lresolv -lnsl -ldl -lm -lcrypt -lutil -lpthread -lc       


Ubuntu vim/vi:

vi --version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Jan  2 2014 19:39:32)
Included patches: 1-52
Modified by [email protected]
Compiled by buildd@
Huge version without GUI.  Features included (+) or not (-):
+acl             +farsi           +mouse_netterm   +syntax
+arabic          +file_in_path    +mouse_sgr       +tag_binary
+autocmd         +find_in_path    -mouse_sysmouse  +tag_old_static
-balloon_eval    +float           +mouse_urxvt     -tag_any_white
-browse          +folding         +mouse_xterm     -tcl
++builtin_terms  -footer          +multi_byte      +terminfo
+byte_offset     +fork()          +multi_lang      +termresponse
+cindent         +gettext         -mzscheme        +textobjects
-clientserver    -hangul_input    +netbeans_intg   +title
-clipboard       +iconv           +path_extra      -toolbar
+cmdline_compl   +insert_expand   -perl            +user_commands
+cmdline_hist    +jumplist        +persistent_undo +vertsplit
+cmdline_info    +keymap          +postscript      +virtualedit
+comments        +langmap         +printer         +visual
+conceal         +libcall         +profile         +visualextra
+cryptv          +linebreak       +python          +viminfo
+cscope          +lispindent      -python3         +vreplace
+cursorbind      +listcmds        +quickfix        +wildignore
+cursorshape     +localmap        +reltime         +wildmenu
+dialog_con      -lua             +rightleft       +windows
+diff            +menu            -ruby            +writebackup
+digraphs        +mksession       +scrollbind      -X11
-dnd             +modify_fname    +signs           -xfontset
-ebcdic          +mouse           +smartindent     -xim
+emacs_tags      -mouseshape      -sniff           -xsmp
+eval            +mouse_dec       +startuptime     -xterm_clipboard
+ex_extra        +mouse_gpm       +statusline      -xterm_save
+extra_search    -mouse_jsbterm   -sun_workshop    -xpm
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H     -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1      
Linking: gcc   -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,--as-needed -o vim        -lm -ltinfo -lnsl  -lselinux  -lacl -lattr -lgpm -ldl    -L/usr/lib/python2.7/config-x86_64-linux-gnu -lpython2.7 -lpthread -ldl -lutil -lm -Xlinker -export-dynamic -Wl,-O1 -Wl,-Bsymbolic-functions  

答案1

您遇到的问题是,所有 RedHat 发行版及其衍生产品(包括 CentOS)/bin/vi都提供“微型”/“小型”版本的 Vim,其功能非常有限。它缺乏执行任何类型的评估、设置多个选项、进行语法突出显示等功能。您的 vimrc正在被阅读,但其中很大一部分却被默默忽略了。

您的解决方案是运行/usr/bin/vim而不是/bin/vi。我已添加alias vi=vim~/.bashrc。您可能必须安装vim-enhanced和/或vim-X11

答案2

跑步vi --version表演

VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Feb 28 2023 00:00:00)

但后来也表明:

   system vimrc file: "/etc/virc"
     user vimrc file: "$HOME/.virc"
 2nd user vimrc file: "~/.vim/virc"
      user exrc file: "$HOME/.exrc"

我只需要.vimrc记住。例如。.vircmv .vimrc .virc

相关内容