Vim 设置不断重置 [英] Vim settings constantly getting reset

查看:30
本文介绍了Vim 设置不断重置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 tmux 中使用 vim.出于某种原因,我的 vim 设置不断被重置.--EDIT-- 更多细节:具体来说,tabstop 和 autoindent 被设置为默认值,即 tabstop=8noautoindent.我不认为我的设置中的某些东西将它们设置为那样,因为当我键入 :so $MYVIMRC 时,它会从我的 vimrc 中重置为正确的值.我认为 vim 以某种方式忘记"了我的设置?

I am using vim inside tmux. For some reason, my vim settings are getting constantly reset. --EDIT-- more detail: specifically, tabstop and autoindent are being set to default values, namely tabstop=8 and noautoindent. I don't think its something in my settings that is setting them to that, because when I type :so $MYVIMRC it resets to the proper values from my vimrc. I think vim is somehow "forgetting" my settings?

我一直无法弄清楚到底是什么导致了它,但它发生的频率很高,几乎每隔几分钟就会发生一次.当我专注于另一个窗口或在 tmux 中切换窗格时,它似乎最常发生.但它不会每次都发生,有时它只是在打字时发生.我不知道问题是什么,但它非常令人沮丧.此外,它似乎在 python 中发生得最多,在 javascript 中稍少发生,在 PHP 或其他语言中发生的频率更低.虽然这可能是因为我大部分时间都在用 Python 和 javascript 工作...

I haven't been able to figure out exactly what is causing it, but it happens pretty frequently, almost every couple of minutes. It seems to happen most often when I focus on another window, or switch panes in tmux. But it doesn't happen every time, and sometimes it just happens while typing. I have no idea what the problem is but its very frustrating. Also, it seems to happen most with python, slightly less with javascript, and even less frequently with PHP or other languages. Though this could be that I spend most of my time working in python and javascript...

我之前遇到了一个问题,我的状态栏输入了乱码:Tmux 中的 Vim:<C-w>l(在 vim 拆分之间交换)将 ^]lfilename^] 输入到 vim.这解决了这个问题,但似乎导致了这个新问题.

I was having a problem earlier where I was getting gibberish entered into my status bar: Vim inside Tmux: <C-w>l (swapping between vim splits) enters ^]lfilename^] into vim. That fixed that issue, but seems to have caused this new one.

以下是我认为的 .vimrc、.tmux.con 和 .bashrc 的相关部分.这些都是我的设置,我没有包括键绑定.

Here are what I think are the relevant parts of my .vimrc, .tmux.con and .bashrc. These are all of my settings, I didn't include keybindings.

set nocompatible
set showmatch
execute pathogen#infect()
syntax enable
filetype plugin indent on
colorscheme desert
set t_Co=256

set shiftwidth=4
set softtabstop=4
set backspace=indent,eol,start   " consume expanded tabs if possible
set expandtab
set shiftround
set autoindent
set relativenumber
set showmode
set showcmd
set hidden
set autoread
set ignorecase
set smartcase
set incsearch
set autochdir
set laststatus=2
set statusline=%<%F\ %h%m%r%=%-14.(%l,%c%V%)\ %13.L\ %P 
set titlestring=%F
set splitbelow

.bashrc:

export TERM=screen-256color

.tmux.conf

export TERM=screen-256color

推荐答案

某些设置是缓冲区或窗口的本地设置.缩进设置,例如'shiftwidth''softtabstop''expandtab' 对缓冲区来说是局部的,而不是全局的.这是有道理的,因为不同的文件类型有不同的需求.需要完全不同缩进设置的类型的一个很好的例子是 python 和 makefile.

Some settings are local to a buffer or window. Indent settings, e.g. 'shiftwidth', 'softtabstop', and 'expandtab', are local to a buffer and not global. This makes sense because different filetypes have different needs. A good example of types that need completely different indent settings would be python and makefile.

设置每个文件类型的缩进设置通常通过以下方式之一完成:

Setting up indent setting per filetype are usually done one of the following ways:

  • 为每个文件使用模式行.总的!(:h 模型行)
  • ~/.vimrc 中使用autocmd.例如autocmd FileType c,cpp,cs,java setlocal shiftwidt=4 softtabstop=4 expandtab
  • 将这些设置放在 ~/.vim/after/ftplugin/python.vim 中.将 python 替换为您想要为其设置特定设置的任何文件类型.
  • Use modelines for each file. Gross! (:h modeline)
  • Use autocmd's in your ~/.vimrc. e.g. autocmd FileType c,cpp,cs,java setlocal shiftwidt=4 softtabstop=4 expandtab
  • Put these setting in ~/.vim/after/ftplugin/python.vim. Replace python with any filetype you want to have specific settings for.

注意:您可以通过 :set ft?

就我个人而言,我喜欢 after 目录结构,因为它既美观又整洁,并且不会让我的 ~/.vimrc 文件变得混乱.

Personally I like the after directory structure as it is nice and neat and keeps the clutter out of my ~/.vimrc file.

有关更多帮助,请参阅:

For more help see:

:h local-options
:h 'sw
:h 'rtp
:h after-directory
:h ftplugin-overrule

这篇关于Vim 设置不断重置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆