hashivim/vim-terraform

Terraform command not found

tasdikrahman opened this issue · 17 comments

Greetings,

Thanks for the creating the project, continuing #79

I have

Plugin 'hashivim/vim-terraform'
let g:terraform_fmt_on_save=1
let g:terraform_align=1

In my ~/.vimrc, installing the plugin shows up as successful when I do a :PluginInstall.

When I am trying to use the command :Terraform in any of the open .tf files, I get a response of E492: Not an editor command: Terraform

Terraform is already present on my machine.

$ which terraform
/usr/local/bin/terraform

Not sure where am I going wrong.

I'm having the same issue with NeoVim.

NVIM v0.3.4
Build type: Release
LuaJIT 2.0.5
Compilation: /usr/local/Homebrew/Library/Homebrew/shims/mac/super/clang -Wconversion -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNDEBUG -DMIN_LOG_LEVEL=3 -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -I/tmp/neovim-20190113-94620-d8vv4n/neovim-0.3.4/build/config -I/tmp/neovim-20190113-94620-d8vv4n/neovim-0.3.4/src -I/usr/local/include -I/usr/local/opt/gettext/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include -I/tmp/neovim-20190113-94620-d8vv4n/neovim-0.3.4/build/src/nvim/auto -I/tmp/neovim-20190113-94620-d8vv4n/neovim-0.3.4/build/include
Compiled by brew@Mojave.local

Features: +acl +iconv +jemalloc +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/Cellar/neovim/0.3.4/share/nvim"

Run :checkhealth for more info

checkhealth returns no issues

When running :Terraform command I get

E492: Not an editor command: Terraform

I inspected :scriptnames and I couldn't find any mention for terraform, not sure if I should see any.
and runtimepath shows I have vim-terraform found.

Question, should it have an autoload directory?
I installed vim-terraform using Vundle.

sorry, call vundle#end() was set at the wrong place.

@tasdikrahman
I sat down to play with Vundle and here's what I found out. Using this bare minimum ~/.vimrc

set nocompatible
filetype off

set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

Plugin 'hashivim/vim-terraform'

call vundle#end()
filetype plugin indent on

Opening vim, run :scriptnames and verify you see terraform.vim in the output

~                                                                  type  :help<Enter>  or  <F1>  for on-line help                                                                    
~                                                                  type  :help version8<Enter>   for version info                                                                    
~                                                                                                                                                                                    
~                                                                                                                                                                                    
~                                                                                                                                                                                    
~                                                                                                                                                                                    
~                                                                                                                                                                                    
~                                                                                                                                                                                    
~                                                                                                                                                                                    
~                                                                                                                                                                                    
~                                                                                                                                                                                    
~                                                                                                                                                                                    
~                                                                                                                                                                                    
~                                                                                                                                                                                    
  1: /etc/vimrc
  2: /usr/share/vim/vim81/syntax/syntax.vim
  3: /usr/share/vim/vim81/syntax/synload.vim
  4: /usr/share/vim/vim81/syntax/syncolor.vim
  5: /usr/share/vim/vim81/filetype.vim
  6: /usr/share/vim/vim81/ftplugin.vim
  7: ~/.vimrc
  8: /usr/share/vim/vim81/ftoff.vim
  9: ~/.vim/bundle/Vundle.vim/autoload/vundle.vim
 10: ~/.vim/bundle/Vundle.vim/autoload/vundle/config.vim
 11: ~/.vim/bundle/vim-terraform/ftdetect/terraform.vim
 12: /usr/share/vim/vim81/indent.vim
 13: /usr/share/vim/vim81/plugin/getscriptPlugin.vim
 14: /usr/share/vim/vim81/plugin/gzip.vim
 15: /usr/share/vim/vim81/plugin/logiPat.vim
 16: /usr/share/vim/vim81/plugin/manpager.vim
 17: /usr/share/vim/vim81/plugin/matchparen.vim
 18: /usr/share/vim/vim81/plugin/netrwPlugin.vim
 19: /usr/share/vim/vim81/plugin/rrhelper.vim
 20: /usr/share/vim/vim81/plugin/spellfile.vim
 21: /usr/share/vim/vim81/plugin/tarPlugin.vim
 22: /usr/share/vim/vim81/plugin/tohtml.vim
 23: /usr/share/vim/vim81/plugin/vimballPlugin.vim
 24: /usr/share/vim/vim81/plugin/zipPlugin.vim
Press ENTER or type command to continue

Now when you open any of the terraform detected file types such as whatever.tf, you'll be able to use :Terraform functions.

Let me know if this isn't working for you and I'll re-open this issue.

I am having this problem since cleaning out my plugins and starting a fresh. Also tried with bare vimrc above:

E492: Not an editor command: TerraformFmt

~/.vimrc

set nocompatible
filetype off

set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

Plugin 'hashivim/vim-terraform'

call vundle#end()
filetype plugin indent on

vim --version

VIM - Vi IMproved 8.1 (2018 May 18, compiled May 27 2019 02:11:37)
macOS version
Included patches: 1-1400

:PluginList

" My Plugins
Plugin 'hashivim/vim-terraform'

@thenom
Can you run :scriptnames to see what vim is loading please?

@pgporada Thanks for your response, here is the output:

:scriptnames

  1: ~/.vimrc
  2: /usr/local/Cellar/vim/8.1.1400/share/vim/vim81/ftoff.vim
  3: ~/.vim/bundle/Vundle.vim/autoload/vundle.vim
  4: ~/.vim/bundle/Vundle.vim/autoload/vundle/config.vim
  5: /usr/local/Cellar/vim/8.1.1400/share/vim/vim81/filetype.vim
  6: ~/.vim/bundle/vim-terraform/ftdetect/terraform.vim
  7: /usr/local/Cellar/vim/8.1.1400/share/vim/vim81/ftplugin.vim
  8: /usr/local/Cellar/vim/8.1.1400/share/vim/vim81/indent.vim
  9: /usr/local/Cellar/vim/8.1.1400/share/vim/vim81/plugin/getscriptPlugin.vim
 10: /usr/local/Cellar/vim/8.1.1400/share/vim/vim81/plugin/gzip.vim
 11: /usr/local/Cellar/vim/8.1.1400/share/vim/vim81/plugin/logiPat.vim
 12: /usr/local/Cellar/vim/8.1.1400/share/vim/vim81/plugin/manpager.vim
 13: /usr/local/Cellar/vim/8.1.1400/share/vim/vim81/plugin/matchparen.vim
 14: /usr/local/Cellar/vim/8.1.1400/share/vim/vim81/plugin/netrwPlugin.vim
 15: /usr/local/Cellar/vim/8.1.1400/share/vim/vim81/plugin/rrhelper.vim
 16: /usr/local/Cellar/vim/8.1.1400/share/vim/vim81/plugin/spellfile.vim
 17: /usr/local/Cellar/vim/8.1.1400/share/vim/vim81/plugin/tarPlugin.vim
 18: /usr/local/Cellar/vim/8.1.1400/share/vim/vim81/plugin/tohtml.vim
 19: /usr/local/Cellar/vim/8.1.1400/share/vim/vim81/plugin/vimballPlugin.vim
 20: /usr/local/Cellar/vim/8.1.1400/share/vim/vim81/plugin/zipPlugin.vim
 21: ~/.vim/bundle/Vundle.vim/autoload/vundle/installer.vim
 22: ~/.vim/bundle/Vundle.vim/autoload/vundle/scripts.vim
 23: /usr/local/Cellar/vim/8.1.1400/share/vim/vim81/scripts.vim

I'm also experiencing this issue. :scriptnames shows vim-terraform:

...
11: ~/.vim/bundle/vim-terraform/ftdetect/terraform.vim
...

Found the bad commit. After each vim terraform.tf execution, I checked for existence of the :Terraform* commands.

# master is commit ffdee14ef1babdb45acf0710e0aaf54fcfc65de0
~/.vim/bundle/vim-terraform [ master ]
→ git bisect start

~/.vim/bundle/vim-terraform [ master ]
→ git bisect bad

~/.vim/bundle/vim-terraform [ master ]
→ git checkout HEAD~1
Note: checking out 'HEAD~1'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

HEAD is now at c686536 Merge pull request #87 from minamijoyo/hcl2-syntax

~/.vim/bundle/vim-terraform [ c686536 ]
→ vim /tmp/terraform.tf

~/.vim/bundle/vim-terraform [ c686536 ]
→ git bisect good
Bisecting: 7 revisions left to test after this (roughly 3 steps)
[94a8ffcb318ce351efc70d4cd62a3b164edfff1b] more vint, set undo_indent, do the cpo dance again

~/.vim/bundle/vim-terraform [ 94a8ffc ]
→ vim /tmp/terraform.tf

~/.vim/bundle/vim-terraform [ 94a8ffc ]
→ git bisect bad
Bisecting: 3 revisions left to test after this (roughly 2 steps)
[48880faa2c8234ce1e4a898b28443f87f538da30] vint - mostly, prefer single-quoted strings

~/.vim/bundle/vim-terraform [ 48880fa ]
→ vim /tmp/terraform.tf

~/.vim/bundle/vim-terraform [ 48880fa ]
→ git bisect good
Bisecting: 1 revision left to test after this (roughly 1 step)
[2ee3c898f11f5ccd280c9876fafafd51bd5960f9] Vim plugin conventions

~/.vim/bundle/vim-terraform [ 2ee3c89 ]
→ vim /tmp/terraform.tf

~/.vim/bundle/vim-terraform [ 2ee3c89 ]
→ git bisect bad
Bisecting: 0 revisions left to test after this (roughly 0 steps)
[ba6d630339ce5e39d7fa893e8e766a8395414b59] Move terraform#fmt() to autoload

~/.vim/bundle/vim-terraform [ ba6d630 ]
→ vim /tmp/terraform.tf

~/.vim/bundle/vim-terraform [ ba6d630 ]
→ git bisect good
2ee3c898f11f5ccd280c9876fafafd51bd5960f9 is the first bad commit
commit 2ee3c898f11f5ccd280c9876fafafd51bd5960f9
Author: David Hotham <david.hotham@metaswitch.com>
Date:   Sat Jun 1 12:47:29 2019 +0100

    Vim plugin conventions

    - signal that the plugin is loaded via b:did_ftplugin
    - some ceremony with cpoptions, so that we're not exposed to unexpected
    settings
    - settings should be local, not global
    - undo settings when unloading plugin

:040000 040000 6bd1fc2a188395a33b3bf43d6001d4a5f265c851 a8b7c4ad4b53772234f354fd52344fa442985628 M      ftplugin

Don't have time to dig in further today, but hopefully that helps

git bisect... my new best friend :)

But this is the commit i found:

commit 9e0e3e3a8ee855d1c327864b0e8a168d1c1a4e42
Author: Danilo <dabio@users.noreply.github.com>
Date:   Tue Jun 26 11:33:34 2018 +0200

    Move plugin to ftplugin.

    ftplugin runs automatically when vim detects the type of file to be
    terraform. This makes vim-terraform compatible to
      https://github.com/sheerun/vim-polyglot
    vim-polyglot strips `plugin` folders - to prevent being loaded regardless
    of filetype.

:000000 040000 0000000000000000000000000000000000000000 1c5c67a6a527ac76ddaefc053d517e360676260e A	ftplugin
:040000 000000 1c5c67a6a527ac76ddaefc053d517e360676260e 0000000000000000000000000000000000000000 D	plugin```

On the previous commit it works fine but not with TF12 but thats another issue...

@sudoforge I reckon that #93 has a good chance of resolving your problem.

(The theory is that Vim is getting in with its default treatment of .tf files as belonging to the TinyFugue MUD client (whatever that is) before the terraform plugin gets a chance...)

Stale. Please open a new issue if there's still a problem.

If anyone is still having this issue, my problem was that I was using vim-polyglot. I just uninstalled that and installed this and it worked.

Still having this issue

I'm not using Vundle, but just started using minpac and I have the same problem. The syntax highlighting works, but when I run a Terraform command I get the same error message as described by the other people in this thread.

:scriptnames output:

...
  7: /usr/share/vim/vim82/syntax/tf.vim
...
 22: ~/.vim/pack/minpac/start/vim-terraform/ftdetect/hcl.vim
...
 25: ~/.vim/pack/minpac/start/vim-terraform/syntax/terraform.vim
 26: ~/.vim/pack/minpac/start/vim-terraform/syntax/hcl.vim
...

Plugins:

~/.vim
~/.vim/pack/minpac/start/vim-unimpaired
~/.vim/pack/minpac/start/vim-terraform
~/.vim/pack/minpac/opt/minpac
/usr/share/vim/vimfiles
/usr/share/vim/vim82
/usr/share/vim/vimfiles/after
~/.vim/after

You haven't shown vim-terraform/ftplugin/terraform.vim being sourced.

You'll probably have to figure out for yourself why that is, but do please consider submitting an MR, even if only to clear up instructions, if and when you get there.