Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filetype plugin not loaded when file opened from within vim rather than from command line #326

Closed
GoogleCodeExporter opened this issue Aug 18, 2015 · 18 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1. Use the following 3 lines as your .vimrc file:
filetype on
filetype plugin on
filetype indent on


2. Edit a python file:
foo@bar:~$ vim hamspam.py

3. Go in insert mode, then press the TAB key
(Notice that typing TAB inserts 4 spaces rather than a single tab character)

4. From within vim, edit a different file (:e foobar.py)

5. Go in insert mode, then press the TAB key


What is the expected output? What do you see instead?

Expected: Typing TAB inserts 4 spaces, just like it did for the first file.

What I see: This time, a tab character (^I) is inserted, messing up the indents 
for the interpreter.

What version of the product are you using? On what operating system?

VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Jan  2 2014 19:39:32)
Included patches: 1-52

Distributor ID: Ubuntu
Description:    Ubuntu 14.04.1 LTS
Release:    14.04
Codename:   trusty


Original issue reported on code.google.com by fmerci...@gmail.com on 9 Feb 2015 at 3:23

@GoogleCodeExporter
Copy link
Author

Why do you expect typing tab to insert 4 spaces? Where do you define this rule?

One of the big changes in Vim 7.4 when upgrading from 7.3 is that the default 
ftplugin file for python will set tab to actually insert real tab characters 
according to PEP8.

Probably you're actually hitting a problem where the filetype plugin IS firing, 
and it is overwriting the settings you really want. But I can't know that for 
certain without knowing how you told Vim to use 4-space indent in the first 
place.

Original comment by fritzoph...@gmail.com on 9 Feb 2015 at 4:36

@GoogleCodeExporter
Copy link
Author

According to https://www.python.org/dev/peps/pep-0008/#tabs-or-spaces

- Spaces are the preferred indentation method.
- Tabs should be used solely to remain consistent with code that is already 
indented with tabs.

Where in PEP8 do you see that real tab characters are the appropriate mean to 
indent?

Original comment by fmerci...@gmail.com on 9 Feb 2015 at 4:50

@GoogleCodeExporter
Copy link
Author

After you open a Python file from the command line, execute the following 
command.

:verbose set ts? sta? sts? et?

Note where each of those was set. On my system, they are all set from 
/usr/local/share/vim/vim74/ftplugin/python.vim except 'sta' which is unset 
('nosmarttab').

Then edit a different Python file from within Vim, repeat the :verbose command, 
and see what changed. On my system, the results are the same.

Original comment by gary....@gmail.com on 9 Feb 2015 at 3:42

@GoogleCodeExporter
Copy link
Author

I rescind my statement. Probably the problem is something in YOUR settings is 
overwriting the filetype plugin somehow. Apparently the ftplugin sets 
"expandtab tabstop=8 softtabstop=4 shiftwidth=4" which should be applying 
4-space indent.

I couldn't tell you where in PEP8 the tabstop of 8 comes from. I don't develop 
the python plugin nor do I code in python more than a couple times in a month. 
All I know is there was a change to the runtime files somewhat recently that 
applied these settings in the python file. I also know filetype plugins load 
perfectly fine on every single python file for almost every single Vim user. So 
probably something is wrong with your setup. Check ":verbose set expandtab?" to 
see where this was apparently unset in your config.

Original comment by fritzoph...@gmail.com on 9 Feb 2015 at 3:43

@GoogleCodeExporter
Copy link
Author

Found the tabstop of 8: 
https://docs.python.org/2/reference/lexical_analysis.html#indentation

(Noted in the thread introducing the PEP8 settings: 
https://groups.google.com/d/msg/vim_dev/vAAIicXPHlc/mPCkbBYaHRAJ)

Original comment by fritzoph...@gmail.com on 9 Feb 2015 at 3:50

@GoogleCodeExporter
Copy link
Author

Result of :verbose set ts? sta? sts? et?

When editing a file from the command line:

  tabstop=8
        Last set from /usr/share/vim/vim74/ftplugin/python.vim
nosmarttab
  softtabstop=4
        Last set from /usr/share/vim/vim74/ftplugin/python.vim
  expandtab
        Last set from /usr/share/vim/vim74/ftplugin/python.vim



When editing a different file from within Vim:

  tabstop=8
nosmarttab
  softtabstop=0
noexpandtab


So it does look like the filetype plugins do not get loaded when using :e to 
open a file.

Original comment by fmerci...@gmail.com on 9 Feb 2015 at 3:50

@GoogleCodeExporter
Copy link
Author

That is not what I was expecting. I'm not sure what to look at next. After 
using :e, what does

:verbose set ft?

say?

Original comment by gary....@gmail.com on 9 Feb 2015 at 4:06

@GoogleCodeExporter
Copy link
Author

Result of :verbose set ft?

  filetype=python
        Last set from /usr/share/vim/vim74/filetype.vim


It reports the same thing before and after using :e

Original comment by fmerci...@gmail.com on 10 Feb 2015 at 9:39

@GoogleCodeExporter
Copy link
Author

I'm not all that familiar with the internals of Vim. Is there some way or tools 
I could use to investigate the plugin further?

Original comment by fmerci...@gmail.com on 10 Feb 2015 at 9:46

@GoogleCodeExporter
Copy link
Author

Interestingly enough, if the first file I open is of a different type, the 
plugins load correctly the first time I use :e (but not the second time)

$ vim test.html
(I get HTML syntax and indent and stuff)

:e foo.py
:verbose set ts? sta? sts? et? ft?

  tabstop=8
        Last set from /usr/share/vim/vim74/ftplugin/python.vim
nosmarttab
  softtabstop=4
        Last set from /usr/share/vim/vim74/ftplugin/python.vim
  expandtab
        Last set from /usr/share/vim/vim74/ftplugin/python.vim
  filetype=python
        Last set from /usr/share/vim/vim74/filetype.vim

:e bar.py
:verbose set ts? sta? sts? et? ft?

  tabstop=4
nosmarttab
  softtabstop=0
noexpandtab
  filetype=python
        Last set from /usr/share/vim/vim74/filetype.vim



So it's only when opening a second file of the same type that the plugins don't 
get loaded. Actually, the same thing happens if I load a second HTML file with 
:e after the first one, so it is not limited to the python plugin.

Original comment by fmerci...@gmail.com on 10 Feb 2015 at 9:57

@GoogleCodeExporter
Copy link
Author

Please, before loading the second file, to :set verbose=10 and check, which 
files are loaded on :e
I assume, you can reproduce it, starting with 
vim -u NONE -i NONE -N --cmd ':filetype plugin on' foo.py
?

Original comment by chrisbr...@googlemail.com on 11 Feb 2015 at 6:23

@GoogleCodeExporter
Copy link
Author

I am having the same problem.

> I assume, you can reproduce it, starting with
> vim -u NONE -i NONE -N --cmd ':filetype plugin on' foo.py

Yes.

Output of :set verbose=10 and :e bar.py:

chdir(/tmp)
fchdir() to previous dir
"bar.py" 0 lines, 0 characters
Executing BufRead Auto commands for "*.py"
autocommand setf python
Executing FileType Auto commands for "*"
autocommand call s:LoadFTPlugin()
Searching for "ftplugin/python.vim ftplugin/python_*.vim ftplugin/python/*.vim" 
in "/home/username/.vim,/usr/sha
re/vim/vimfiles,/usr/share/vim/vim74,/usr/share/vim/vimfiles/after,/home/usernam
e/.vim/after"
Searching for "/home/username/.vim/ftplugin/python.vim"
Searching for "/home/username/.vim/ftplugin/python_*.vim"
Searching for "/home/username/.vim/ftplugin/python/*.vim"
Searching for "/usr/share/vim/vimfiles/ftplugin/python.vim"
Searching for "/usr/share/vim/vimfiles/ftplugin/python_*.vim"
Searching for "/usr/share/vim/vimfiles/ftplugin/python/*.vim"
Searching for "/usr/share/vim/vim74/ftplugin/python.vim"
chdir(/usr/share/vim/vim74/ftplugin)
fchdir() to previous dir
line 17: sourcing "/usr/share/vim/vim74/ftplugin/python.vim"
finished sourcing /usr/share/vim/vim74/ftplugin/python.vim
continuing in function <SNR>2_LoadFTPlugin
Searching for "/usr/share/vim/vim74/ftplugin/python_*.vim"
Searching for "/usr/share/vim/vim74/ftplugin/python/*.vim"
Searching for "/usr/share/vim/vimfiles/after/ftplugin/python.vim"
Searching for "/usr/share/vim/vimfiles/after/ftplugin/python_*.vim"
Searching for "/usr/share/vim/vimfiles/after/ftplugin/python/*.vim"
Searching for "/home/username/.vim/after/ftplugin/python.vim"
Searching for "/home/username/.vim/after/ftplugin/python_*.vim"
Searching for "/home/username/.vim/after/ftplugin/python/*.vim"
Executing BufRead Auto commands for "*"
autocommand if !did_filetype() && expand("<amatch>") !~ g:ft_ignore_pat | 
runtime! scripts.vim | endif
Executing BufRead Auto commands for "*"
autocommand if !did_filetype() && expand("<amatch>") !~ g:ft_ignore_pat    && 
(getline(1) =~ '^#' || getli
ne(2) =~ '^#' || getline(3) =~ '^#'^I|| getline(4) =~ '^#' || getline(5) =~ 
'^#') |   setf conf | endif

Press ENTER or type command to continue


Original comment by pbaec...@gmail.com on 31 Mar 2015 at 7:34

@sanscore
Copy link

I've hit this issue on an Ubuntu 14.04.2 box and I was able to correct it by compiling vim from source. If I had to guess, I think patch 860 was the fix. http://ftp.vim.org/pub/vim/patches/7.4/README

@martyychang
Copy link

I have the same issue.

~/.vim/after/ftplugin/py.vim

set expandtab
set tabstop=4
set shiftwidth=4

Steps to reproduce

With py.vim (see above) in place...

  1. vim foo.py
  2. Activate INSERT mode, then type "def foo():" and press Enter. The cursor will move down to the next line with the cursor at the 5th character, as expected.
  3. Open a new window with :new bar.py
  4. Activate INSERT mode, then type "def bar():" and press Enter. The cursor will move down to the next line but with the cursor at the 9th character, which is unexpected. The behavior should be the same as observed when editing foo.py above.

Build info

$ vim --version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Jan  2 2014 19:39:32)
Included patches: 1-52
Modified by pkg-vim-maintainers@lists.alioth.debian.org
Compiled by buildd@
Huge version without GUI.  Features included (+) or not (-):
+acl             +farsi           +mouse_netterm   +syntax
+arabic          +file_in_path    +mouse_sgr       +tag_binary
+autocmd         +find_in_path    -mouse_sysmouse  +tag_old_static
-balloon_eval    +float           +mouse_urxvt     -tag_any_white
-browse          +folding         +mouse_xterm     -tcl
++builtin_terms  -footer          +multi_byte      +terminfo
+byte_offset     +fork()          +multi_lang      +termresponse
+cindent         +gettext         -mzscheme        +textobjects
-clientserver    -hangul_input    +netbeans_intg   +title
-clipboard       +iconv           +path_extra      -toolbar
+cmdline_compl   +insert_expand   -perl            +user_commands
+cmdline_hist    +jumplist        +persistent_undo +vertsplit
+cmdline_info    +keymap          +postscript      +virtualedit
+comments        +langmap         +printer         +visual
+conceal         +libcall         +profile         +visualextra
+cryptv          +linebreak       +python          +viminfo
+cscope          +lispindent      -python3         +vreplace
+cursorbind      +listcmds        +quickfix        +wildignore
+cursorshape     +localmap        +reltime         +wildmenu
+dialog_con      -lua             +rightleft       +windows
+diff            +menu            -ruby            +writebackup
+digraphs        +mksession       +scrollbind      -X11
-dnd             +modify_fname    +signs           -xfontset
-ebcdic          +mouse           +smartindent     -xim
+emacs_tags      -mouseshape      -sniff           -xsmp
+eval            +mouse_dec       +startuptime     -xterm_clipboard
+ex_extra        +mouse_gpm       +statusline      -xterm_save
+extra_search    -mouse_jsbterm   -sun_workshop    -xpm
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H     -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1      
Linking: gcc   -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,--as-needed -o vim        -lm -ltinfo -lnsl  -lselinux  -lacl -lattr -lgpm -ldl    -L/usr/lib/python2.7/config-x86_64-linux-gnu -lpython2.7 -lpthread -ldl -lutil -lm -Xlinker -export-dynamic -Wl,-O1 -Wl,-Bsymbolic-functions      
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.5 LTS
Release:    14.04
Codename:   trusty

@martyychang
Copy link

Actually I ran :scriptnames inside Vim as suggested on another thread and found that the py.vim file I put inside ~/.vim/ftplugin didn't even execute.

  1: /usr/share/vim/vimrc
  2: /usr/share/vim/vim74/debian.vim
  3: /usr/share/vim/vim74/syntax/syntax.vim
  4: /usr/share/vim/vim74/syntax/synload.vim
  5: /usr/share/vim/vim74/syntax/syncolor.vim
  6: /usr/share/vim/vim74/filetype.vim
  7: ~/.vimrc
  8: /usr/share/vim/vim74/ftplugin.vim
  9: /usr/share/vim/vim74/indent.vim
 10: /usr/share/vim/vim74/plugin/getscriptPlugin.vim
 11: /usr/share/vim/vim74/plugin/gzip.vim
 12: /usr/share/vim/vim74/plugin/matchparen.vim
 13: /usr/share/vim/vim74/plugin/netrwPlugin.vim
 14: /usr/share/vim/vim74/plugin/rrhelper.vim
 15: /usr/share/vim/vim74/plugin/spellfile.vim
 16: /usr/share/vim/vim74/plugin/tarPlugin.vim
 17: /usr/share/vim/vim74/plugin/tohtml.vim
 18: /usr/share/vim/vim74/plugin/vimballPlugin.vim
 19: /usr/share/vim/vim74/plugin/zipPlugin.vim
 20: /usr/share/vim/vim74/syntax/python.vim
 21: /usr/share/vim/vim74/ftplugin/python.vim
 22: /usr/share/vim/vim74/indent/python.vim

I tried editing /usr/share/vim/vim74/ftplugin/python.vim and /usr/share/vim/vim74/indent/python.vim to remove the "did load already" checks, but that didn't make a difference on the unexpected behavior.

My workaround is to manually execute :set shiftwidth=4 tabstop=4 manually in every new window opened after the first one.

@vim-ml
Copy link

vim-ml commented Sep 21, 2016

Op 21 sep. 2016 23:40 schreef "Marty Chang" vim-dev-github@256bit.org:

Actually I ran :scriptnames inside Vim as suggested on another thread and
found that the py.vim file I put inside ~/.vim/ftplugin didn't even execute.

Shouldn't it be called python.vim then?

Christ van Willegen

@sanscore
Copy link

@martyychang: You don't have the necessary patch that (I suspect) fixed this problem. See my response here: #326 (comment)

There's this question How can I update vim in ubuntu 10.04LTS over at askubuntu.com that says to use ppa:pkg-vim/vim-daily. Or, you could do a git clone https://github.com/vim/vim/ and build vim yourself from whichever point in time that you want. Otherwise, you could apt-get source vim, apply the necessary patches from the ftp site, then build it that way.

@chrisbra
Copy link
Member

@martyychang I suspect a user question here. Please ask on the appropriate forum. thanks. I am closing this issue as it seems unreproducible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants