【发布时间】:2018-05-21 01:34:31
【问题描述】:
系统:运行 Raspbian Stretch 的 Raspberry pi,已全面更新。
这是我的整个 ~/.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:
:version 的输出
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
【问题讨论】:
-
:version的完整输出是什么?:scriptnames的完整输出是多少?你知道$ sudo -e吗? -
romainl,我已经编辑了带有输出的原始帖子。我相信 sudo -e 会完成与 sudoedit 类似的事情,它会在哪里维护我的设置?如果是这样,我知道该选项并且可能会长期使用它,只是希望了解为什么 defaults.vim 无法按预期工作。