简体   繁体   中英

.vimrc file not working as expected

If I open a python file with vim, and set it to have a ruler and auto-line break with this command:

:set textwidth=109 colorcolumn=110

It works like a charm! However ... if I edit ~/.vimrc and add this line at the bottom

autocmd FileType py set textwidth=109 colorcolumn=110

exit the python file, and open it again, nothing happens. Seems like something is overriding my setting, but can't figure out what is doing that (because I'm fairly new to vim). My basic vimrc file is this: https://github.com/amix/vimrc/blob/master/vimrcs/basic.vim

Can someone point me in the right direction on what am I doing wrong?

Note: the same thing is happening for Javascript files when I try to "replace" Tabs with 2 spaces in indentation:

autocmd FileType js setlocal sw=2 sts=2 et

The issue is that the correct filetypes are python and javascript (or similar, like javascript.jsx if you have additional syntax files), not py and js . You can check the filetype used for a file by :set ft? .

Also, you may prefer setlocal (to affect only the current buffer) instead of set .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM