VIM defaults.vim没有按预期工作;一些命令只在家里工作

时间:2018-05-21 01:34:32

标签: vim raspbian

系统:Raspberry pi运行Raspbian Stretch,完全更新。

这是我的整个〜/ .vimrc代码。强调底线,这是我用来验证我正在加载正确的VIMRC文件。当我以用户身份运行vim时,这个VIMRC中的所有内容都可以正常运行。

" All system-wide defaults are set in $VIMRUNTIME/debian.vim (usually just
" /usr/share/vim/vimcurrent/debian.vim) and sourced by the call to :runtime
" you can find below.  If you wish to change any of those settings, you should
" do it in this file (/etc/vim/vimrc), since debian.vim will be overwritten
" everytime an upgrade of the vim packages is performed.  It is recommended to
" make changes after sourcing debian.vim since it alters the value of the
" 'compatible' option.

" This line should not be removed as it ensures that various options are
" properly set to work with the Vim-related packages available in Debian.
runtime! debian.vim

" Uncomment the next line to make Vim more Vi-compatible
" NOTE: debian.vim sets 'nocompatible'.  Setting 'compatible' changes numerous
" options, so any other options should be set AFTER setting 'compatible'.
"set compatible

" Vim5 and later versions support syntax highlighting. Uncommenting the next
" line enables syntax highlighting by default.
"syntax on

" If using a dark background within the editing area and syntax highlighting
" turn on this option as well
set background=dark

" Uncomment the following to have Vim jump to the last position when
" reopening a file
if has("autocmd")
  au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
endif

" Uncomment the following to have Vim load indentation rules and plugins
" according to the detected filetype.
"if has("autocmd")
"  filetype plugin indent on
"endif

" The following are commented out as they cause vim to behave a lot
" differently from regular Vi. They are highly recommended though.
"set showcmd            " Show (partial) command in status line.
"set showmatch          " Show matching brackets.
"set ignorecase         " Do case insensitive matching
"set smartcase          " Do smart case matching
"set incsearch          " Incremental search
"set autowrite          " Automatically save before commands like :next and :make
"set hidden             " Hide buffers when they are abandoned
"set mouse=a            " Enable mouse usage (all modes)

" Source a global configuration file if available
if filereadable("/etc/vim/vimrc.local")
  source /etc/vim/vimrc.local
endif

syntax on

set mouse-=a

set backspace=indent,eol,start

echo "home vimrc loaded"

然而,当我删除〜/ .vimrc的副本,或者(更重要的是因为它是我遇到的问题),如果我运行sudo vim,我的全局默认版本的vimrc( /usr/share/vim/vim80/defaults.vim,与/ etc / vim / vimrc硬连接)无法按预期工作。特别是,我注意到以下两个问题:

-set mouse- = a即使在注释掉该行时似乎也能正常工作。

-set backspace = indent,eol,start不起作用。

它回应我正在加载全局vimrc,如果我编辑它,则相应地修改回声。

这是我的全局vimrc文件。

" All system-wide defaults are set in $VIMRUNTIME/debian.vim (usually just
" /usr/share/vim/vimcurrent/debian.vim) and sourced by the call to :runtime
" you can find below.  If you wish to change any of those settings, you should
" do it in this file (/etc/vim/vimrc), since debian.vim will be overwritten
" everytime an upgrade of the vim packages is performed.  It is recommended to
" make changes after sourcing debian.vim since it alters the value of the
" 'compatible' option.

" This line should not be removed as it ensures that various options are
" properly set to work with the Vim-related packages available in Debian.
runtime! debian.vim

" Uncomment the next line to make Vim more Vi-compatible
" NOTE: debian.vim sets 'nocompatible'.  Setting 'compatible' changes numerous
" options, so any other options should be set AFTER setting 'compatible'.
"set compatible

" Vim5 and later versions support syntax highlighting. Uncommenting the next
" line enables syntax highlighting by default.
"syntax on

" If using a dark background within the editing area and syntax highlighting
" turn on this option as well
set background=dark

" Uncomment the following to have Vim jump to the last position when
" reopening a file
if has("autocmd")
  au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
endif

" Uncomment the following to have Vim load indentation rules and plugins
" according to the detected filetype.
"if has("autocmd")
"  filetype plugin indent on
"endif

" The following are commented out as they cause vim to behave a lot
" differently from regular Vi. They are highly recommended though.
"set showcmd            " Show (partial) command in status line.
"set showmatch          " Show matching brackets.
"set ignorecase         " Do case insensitive matching
"set smartcase          " Do smart case matching
"set incsearch          " Incremental search
"set autowrite          " Automatically save before commands like :next and :make
"set hidden             " Hide buffers when they are abandoned
"set mouse=a            " Enable mouse usage (all modes)

" Source a global configuration file if available
if filereadable("/etc/vim/vimrc.local")
  source /etc/vim/vimrc.local
endif

syntax on

set mouse-=a

set backspace=indent,eol,start

echo "global vimrc loaded"

我觉得我必须误解vimrc的默认设置是如何工作的。任何帮助赞赏。

编辑更多信息:

当我创建一个文件/root/.vimrc然后运行sudo vim时,它确实正确地使用了该vimrc,并且当以root身份运行时,一切正常。当我删除本地vimrc时,全局文件仍然无法正常工作。因此,用户权限绝对没有任何意义。除了vimrc之外还有第二个vim文件可能是个问题吗?

EDIT2:

输出:版本

VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Sep 30 2017 18:21:38)
Included patches: 1-197, 322, 377-378, 550, 703, 706-707
Modified by pkg-vim-maintainers@lists.alioth.debian.org
Compiled by pkg-vim-maintainers@lists.alioth.debian.org
Huge version without GUI.  Features included (+) or not (-):
+acl             -clipboard       +dialog_con      +file_in_path    +job             -lua             +mouse_sgr       +path_extra      +rightleft       +tag_old_static  +user_commands   +writebackup
+arabic          +cmdline_compl   +diff            +find_in_path    +jumplist        +menu            -mouse_sysmouse  -perl            -ruby            -tag_any_white   +vertsplit       -X11
+autocmd         +cmdline_hist    +digraphs        +float           +keymap          +mksession       +mouse_urxvt     +persistent_undo +scrollbind      -tcl             +virtualedit     -xfontset
-balloon_eval    +cmdline_info    -dnd             +folding         +lambda          +modify_fname    +mouse_xterm     +postscript      +signs           +termguicolors   +visual          -xim
-browse          +comments        -ebcdic          -footer          +langmap         +mouse           +multi_byte      +printer         +smartindent     +terminfo        +visualextra     -xpm
++builtin_terms  +conceal         +emacs_tags      +fork()          +libcall         -mouseshape      +multi_lang      +profile         +startuptime     +termresponse    +viminfo         -xsmp
+byte_offset     +cryptv          +eval            +gettext         +linebreak       +mouse_dec       -mzscheme        -python          +statusline      +textobjects     +vreplace        -xterm_clipboard
+channel         +cscope          +ex_extra        -hangul_input    +lispindent      +mouse_gpm       +netbeans_intg   -python3         -sun_workshop    +timers          +wildignore      -xterm_save
+cindent         +cursorbind      +extra_search    +iconv           +listcmds        -mouse_jsbterm   +num64           +quickfix        +syntax          +title           +wildmenu
-clientserver    +cursorshape     +farsi           +insert_expand   +localmap        +mouse_netterm   +packages        +reltime         +tag_binary      -toolbar         +windows
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H   -Wdate-time  -g -O2 -fdebug-prefix-map=/build/vim-UkjqTY/vim-8.0.0197=. -fstack-protector-strong -Wformat -Werror=format-security -U_FORTIFY_SOURCE -D_FORTIFY_SO
URCE=1
Linking: gcc   -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -o vim        -lm -ltinfo -lnsl  -lselinux -lacl -lattr -lgpm -ldl

输出:scriptnames

1: /usr/share/vim/vim80/defaults.vim
  2: /usr/share/vim/vim80/syntax/syntax.vim
  3: /usr/share/vim/vim80/syntax/synload.vim
  4: /usr/share/vim/vim80/syntax/syncolor.vim
  5: /usr/share/vim/vim80/filetype.vim
  6: /usr/share/vim/vim80/plugin/getscriptPlugin.vim
  7: /usr/share/vim/vim80/plugin/gzip.vim
  8: /usr/share/vim/vim80/plugin/logiPat.vim
  9: /usr/share/vim/vim80/plugin/manpager.vim
 10: /usr/share/vim/vim80/plugin/matchparen.vim
 11: /usr/share/vim/vim80/plugin/netrwPlugin.vim
 12: /usr/share/vim/vim80/plugin/rrhelper.vim
 13: /usr/share/vim/vim80/plugin/spellfile.vim
 14: /usr/share/vim/vim80/plugin/tarPlugin.vim
 15: /usr/share/vim/vim80/plugin/tohtml.vim
 16: /usr/share/vim/vim80/plugin/vimballPlugin.vim
 17: /usr/share/vim/vim80/plugin/zipPlugin.vim
 18: /usr/share/vim/vim80/syntax/vim.vim

1 个答案:

答案 0 :(得分:1)

Sub MacroText() Dim xlRng As Range Dim rng As Range Dim xlSht As Worksheet Dim sht As Worksheet Dim iLastRow As Long Dim iRow As Long Dim bFound As Boolean Dim xCell As Range Dim xlCell As Range Dim valueToFind As String Dim FoundRange As Range bFound = False Set sht = ActiveWorkbook.Worksheets("Sheet3") Set xlSht = ActiveWorkbook.Worksheets("Sheet2") Set rng = Selection Set xlRng = ActiveWorkbook.Worksheets("Sheet2").Range("A:A") iLastRow = xlSht.Range("A1").End(xlDown).Row Set xlRng = xlSht.Range("A1:A" & iLastRow) For Each xCell In rng Set FoundRange = Nothing Set FoundRange = xlRng.Find(what:=xCell.Value2) If Not FoundRange Is Nothing Then FoundRange.EntireRow.Font.Bold = True End If Next xCell End Sub (扩展为$VIMRUNTIME/defaults.vim不是您的全局vimrc(除非raspbian以不同的方式设置它)。通常在debian系统/usr/share/vim/vim80/runtime/defaults.vim上硬链接到/etc/vim/vimrc,这是默认的系统 vimrc文件。无论您是谁,都会获取此文件始终(请参阅/usr/share/vim/vimrc)。 :h system-vimrc是一个具有奇怪行为的特殊文件;来自defaults.vim

:h defaults

所以If Vim is started normally and no user vimrc file is found, the $VIMRUNTIME/defaults.vim script is loaded. This will set 'compatible' off, switch on syntax highlighting and a few more things. 将为每个没有自己的vimrc的用户提供源代码,并设置defaults.vim等。这就是为什么创建mouse=a使事情按预期工作的原因。

我建议不要更改/root/.vimrc/usr/share/vim/vimrc,因为这些文件在vim更新时都会被覆盖。如果你想以root身份使用你的vimrc,那么你可以使用像defaults.vim这样的东西而不是登录root,或者用sudoedit之类的东西从root开始vim。