我ctm,今天配置不让tab转为空格,在_vimrc中set noexpandtab 不起效果。

set ts=4也不起效果。

但是在命令行中其效果。

我都不知道咋办了。

问人说我有可能使用的不是那个目录下的_vimrc

检查了,没问题。

后来在网上搜了半天都没找到原因。

最后,机智的我用英文搜了一下,

windows _vimrc set noexpandtab do not work

居然找到答案了。

大意就是使用了python插件,里面有一个什么标准,会在加载_vimrc之后去加载,所以就把它覆盖了。

就这么简单,下面是网址。

http://stackoverflow.com/questions/21073496/why-does-vim-not-obey-my-expandtab-in-python-files

11down voteaccepted

The problem is that your settings are being overridden by a filetype plugin that's part of Vim. The issue is in ftplugin/python.vim:

" As suggested by PEP8.
setlocal expandtab shiftwidth=4 softtabstop=4 tabstop=8

The python plugin attempts to setup your source code to be PEP8 compliant by default, so it's adjusting the tabstop. You'll want some of what these plugins have to offer, but you may need to setup your own autocommands to fixup anything you don't like.

There are two ways to go about doing this. If you have a ~/.vim folder, the easiest way is to add the file ~/.vim/after/ftplugin/python.vim:

" Here, you can set the setting directly, or call a command or function
" to help you. We'll call a command, and then implement that command in
" your top-level vimrc to help keep things in one place.
SetupPython

In your .vimrc, add:

function! SetupPython()
" Here, you can have the final say on what is set. So
" fixup any settings you don't like.
setlocal softtabstop=2
setlocal tabstop=2
setlocal shiftwidth=2
endfunction
command! -bar SetupPython call SetupPython()

The latter bit just allows you to call the function as SetupPython rather than call SetupPython() in the after file.

The other way, is to keep everything in your .vimrc, but you use the VimEnter autocommand to setup a FileType autocommand for python to set your preferences. By waiting until VimEnter is triggered, all the other plugins will have had time to setup their autocommands, so your's will be added to the end of the list. This allows you to run after the python plugin's FileTypeautocommand and set your own settings. This is a bit of a mess though, and the after/mechanism above is the preferred way of doing this.

FWIW, many common settings I keep in a SetupSource() function to be called from a number of different FileTypes. Then I'd have SetupPython() call SetupSource(). This helps to keep the specific functions a little cleaner and reduce some duplication. If it helps, take a look at the functions in my vimfiles here: https://github.com/jszakmeister/vimfiles/blob/master/vimrc#L5328

在_vimrc中 set noexpandtab python 不起效果的更多相关文章

  1. 在.bashrc中,使用python获取本机IP地址(现在只支持wlan)

    其实最好的办法是写个单独的脚本去查找IP,但是如果实在不愿意单写一个脚本文件,也可以直接将代码嵌入.bashrc中 在~/.bashrc下加入下面这行代码即可使用python获取本机的wlan的IP地 ...

  2. 如何使用python来模拟鼠标点击(将通过实例自动化模拟在360浏览器中自动搜索"python")

    一.准备工作: 安装pywin32,后面开发需要pywin32的支持,否则无法完成与windows层面相关的操作. pywin32的具体安装及注意事项: 1.整体开发环境: 基于windows7操作系 ...

  3. ArcGis Python脚本——ArcGIS 中使用的 Python 是什么版本

    Python 编程语言用于自 9.0 起的各版本 ArcGIS 中,并被整合到 ArcMap 和 ArcGIS for Server 的自动安装中. ArcGIS 将在完整安装过程中安装下列 Pyth ...

  4. MyEclipse10或者eclipse中配置开发Python的Pydev插件安装教程

    注意使用LiClipse的用户 PyDev已经预装在LiClipse中,所以可以跳过这一步(请注意,如果使用LiClipse,PyDev不能单独安装或更新,因为它必须始终作为一个整体更新). 必需品 ...

  5. VS Code设置中文和配置Python环境

    前言: Visual Studio Code(以下简称VSCode)是一个轻量且强大的代码编辑器,支持Windows,OS X和Linux.内置JavaScript.TypeScript和Node.j ...

  6. Ubuntu16.04系统中不同版本Python之间的转换

    Ubuntu系统自带的版本是2.7.12 安装好python3.6之后,改变一下Python的优先级(需要root权限). 在使用下面这个命令查看电脑里面有几个Python版本 update-alte ...

  7. 编程中遇到的Python错误和解决方法汇总整理

    这篇文章主要介绍了自己编程中遇到的Python错误和解决方法汇总整理,本文收集整理了较多的案例,需要的朋友可以参考下   开个贴,用于记录平时经常碰到的Python的错误同时对导致错误的原因进行分析, ...

  8. 设置 PyCharm 软件中 Terminal 窗口 中启动的 python 交互命令的版本

    设置 PyCharm 软件中 Terminal 窗口 中启动的 python 交互命令的版本 python2 和 python3 有很大的不同,使用python2 编写的程序,如果使用python3 ...

  9. html中如何使用python屏蔽一些基本功能

    进行数据解析的理由不计其数,相关的工具和技巧也同样如此.但是,当您需要用这些数据做一些新的事情时,即使有“合适的”工具可能也是不够的.这一担心对于异类数据源的集成同样存在.用来做这项工作的合适工具迟早 ...

随机推荐

  1. 数据库 数据库SQL语句一

    字符和日期 --字符和日期都要包含在单引号中 --字符大小写敏感,日期格式敏感 --默认的日期格式是DD-MON-RR --查询当前系统时间 SQL> select sysdate from d ...

  2. [LeetCode] K-th Smallest in Lexicographical Order 字典顺序的第K小数字

    Given integers n and k, find the lexicographically k-th smallest integer in the range from 1 to n. N ...

  3. [LeetCode] Combination Sum II 组合之和之二

    Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in ...

  4. 如何用TypeScript开发微信小程序

    微信小程序来了!这个号称干掉传统app的玩意儿虽然目前处于内测阶段,不过目前在应用号的官方文档里已经放出了没有内测号也能使用的模拟器了. 工具和文档可以参考官方文档:https://mp.weixin ...

  5. 尝试在你浏览器的Console(F12)中运行一下,你会发现页面被不同的颜色块高亮了(css调试中学到的js)

    现在到处都是JavaScript,每天都能知道点新东西.一旦你入了门,你总能从这里或是那里领悟到很多知识. 一旦我发现一些有意思的东西,我喜欢去感觉他们的源代码,看一看它是怎么办到的. 今天我想分享A ...

  6. UI输入控件

    --UI输入控件 -- 输入控件 cc.uii.UIInput.new(table) --[[ 参数 table{ image 输入框图像,可以为图片名或者display.newScale9Sprit ...

  7. Ubuntu14.04无法在var/www内新建文档

    /var/www文件夹的所有者属于www-data用户组. 要想用你自己的帐号在/var/www里面创建文件和文件夹,最好的办法是把自己的帐号纳入到www-data用户组中. 命令:sudo user ...

  8. Centos 7 使用jenkins 打包android项目

      1.配置java环境   在sun官网下载,解压后放入/usr/java下,并配置环境变量如 vi /etc/profile 在最底部加入如下配置(注:添加环境变量,都是在文件最底部添加)   J ...

  9. 【USACO 3.1】Stamps (完全背包)

    题意:给你n种价值不同的邮票,最大的不超过10000元,一次最多贴k张,求1到多少都能被表示出来?n≤50,k≤200. 题解:dp[i]表示i元最少可以用几张邮票表示,那么对于价值a的邮票,可以推出 ...

  10. Oracle中已有数据的字段类型修改

    创建测试表 create table t_person( id varchar2(200) primary key, name varchar2(200), address varchar2(200) ...