Vim 写入时覆盖文件名 [英] Vim overwrites filename when writing
问题描述
假设我有一个名为 FooBar.java 的文件.当我使用
Let's say I have a file called FooBar.java. When I open the file in a powershell window with
>vim foobar.java
> vim foobar.java
编辑后写入文件,文件重命名为FooBar.java ->foobar.java.
and write the file after editing it, the file gets renamed FooBar.java -> foobar.java.
如果我用
>vim FOOBAR.java
> vim FOOBAR.java
它被重命名为 FooBar.java ->FOOBAR.java.
it gets renamed FooBar.java -> FOOBAR.java.
因此,当我使用 powershell 命令打开文件时,Vim 将名称更改为区分大小写.这对我来说是不受欢迎的行为,在我全新安装操作系统(Windows 10)之前,我没有遇到过这个问题.我正在使用与以前完全相同的 .vimrc.这是一个巨大的痛苦,因为 java 的文件名区分大小写.
So Vim changes the name to be case sensitive to how I spelled it when I opened the file with a powershell command. This is undesired behaviour for me, and I did not have this problem earlier, before I did a clean install of my OS (Windows 10). I am using the exact same .vimrc as before. This is a huge pain in the ass since java is case sensitive with it's filenames.
然而,它似乎只发生在 .java 文件中.对于 .cpp 或 .txt 或 .csv 文件,无论我如何键入,文件的大小写都保持不变.
However, it seems to only happen with .java files. With .cpp or .txt or .csv files, the capitalization of the file remains the same regardless of how I type it.
我的问题分为两部分:
- 为什么 Vim 突然执行此操作,而之前没有使用相同的 .vimrc 执行此操作?
- 如何永久禁用此行为,最好使用 .vimrc 行?
有一个 3 个月前的副本,但由于我的互联网点数较低,我无法对其发表评论,并且它有 0 个答案,我做了一个新的.
There is a 3 month old duplicate, but as I cannot comment to it because of my low internet-points, and it has 0 answers, I made a new one.
这是我的 .vimrc 的内容:
Here are the contents of my .vimrc:
"Created for Vim version 8.2
set clipboard+=unnamed
set backspace=indent,eol,start
set noswapfile
set undofile
set undodir=~\vimfiles\undodir
set encoding=utf8
set fileencoding=utf8
set autoindent
set smartindent
set tabstop=4
set shiftwidth=4
set hlsearch
set incsearch
set ignorecase
set smartcase
set number
set ruler
set linebreak
set showbreak=+
"set listchars=tab:>-,trail:.,extends:>
"set list
:nnoremap U :echo " < < ===== C H E C K C A P S L O C K ===== > > "<CR>
syntax on
set cursorline
hi cursorline ctermbg=darkblue
hi cursorline ctermfg=white
hi colorcolumn ctermbg=darkblue
hi linenr ctermfg=blue
hi preproc ctermfg=magenta
hi type ctermfg=yellow
hi statement ctermfg=magenta
hi constant ctermfg=darkgreen
hi special ctermfg=green
hi comment ctermfg=darkgrey
hi number ctermfg=red
filetype on
autocmd filetype cpp set colorcolumn=80,101
autocmd filetype cpp set nowrap
autocmd filetype hpp set colorcolumn=80,101
autocmd filetype hpp set nowrap
autocmd filetype c set colorcolumn=80,101
autocmd filetype c set nowrap
autocmd filetype h set colorcolumn=80,101
autocmd filetype h set nowrap
autocmd filetype java set colorcolumn=80,101
autocmd filetype java set nowrap
autocmd filetype python set colorcolumn=80
autocmd filetype python set nowrap
autocmd filetype gitcommit set colorcolumn=51,73
autocmd filetype gitcommit set nowrap
推荐答案
您可以通过以下方式解决此问题:
You can fix this with:
set backupcopy=yes
将此选项设置为默认值后,Vim 最终会通过重命名原始文件来备份它,然后创建一个与您正在编辑的文件同名的新文件.但是在文件名不区分大小写的文件系统(通常是 Windows)中,如果您通过不同大小写的名称来引用文件,Vim 最终可能会创建具有不同大小写的新文件.
With this option set to its default value, Vim ends up backing up the original file by renaming it and then creating a new file with the same name as the one you're editing. But in filesystems with case-insensitive filenames (typically, Windows) and if you refer to files by a name with a different case, Vim might end up creating the new file with the different case.
使用 backupcopy=yes
将使 Vim 将备份创建为新副本(而不是重命名原始文件),然后覆盖原始文件.执行该操作时,文件名的大小写不会改变,因为 Vim 并不是真正创建新文件,而是写入现有文件,因此文件系统将保留原始名称(以及原始文件的任何属性).)
Using backupcopy=yes
will have Vim create the backup as a new copy (instead of a rename of the original file) and then it will overwrite the original file. When that operation is performed, the case of the filename won't change, since Vim isn't really creating a new file but writing to an existing one, so the filesystem will preserve the original name (and any attributes the of the original file.)
参见 :help 'backupcopy'
了解更多详情.
See :help 'backupcopy'
for more details.
这篇关于Vim 写入时覆盖文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!