Vim settings constantly getting reset

2019-02-20 03:11发布

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?

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...

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.

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.

.vimrc

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

标签: vim tmux
2条回答
家丑人穷心不美
2楼-- · 2019-02-20 03:44

You said you work in javascript and python and that you notice the difference when changing between them. Are you sure this is changing and not that you get different behavior for javascript and python?

Note the pathogen#infect(). You probably have something like syntastic installed which in turn will have lint tools for javascript and python. Those tools may have file type specific indentation settings. If you have something following PEP8 for python it's probably defaulting to spacing instead of tabs for indentation.

Check .vim/ftplugin and .vim/ftdetect, filetype specific settings can be put there which will override the default behavior specified in your .vimrc.

查看更多
霸刀☆藐视天下
3楼-- · 2019-02-20 04:02

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:

  • 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.

Note: You can find a buffer's file type via :set ft?

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
查看更多
登录 后发表回答