farosis / vim

Automatically exported from code.google.com/p/vim
0 stars 0 forks source link

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

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
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 commented 9 years ago
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 commented 9 years ago
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 commented 9 years ago
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 commented 9 years ago
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 commented 9 years ago
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 commented 9 years ago
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 commented 9 years ago
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 commented 9 years ago
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 commented 9 years ago
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 commented 9 years ago
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 commented 9 years ago
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 commented 9 years ago
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