Customize vim for YAML

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Customize vim for YAML

Gary Fritz
I'm doing some Ansible work (on RHEL 8), so I want the YAML configs for vim.  I have a yaml.vim file containing the syntax/etc, and a ~/.vimrc file:

autocmd BufNewFile,BufRead *.yaml,*.yml so ~/.vim/yaml.vim
autocmd FileType yaml,yml set ai ts=2 sw=2 et number

While logged in as user ansible, that worked just peachy.  But then I copied the same files to the same places under ~ (root), and when I was root (via su or su -), vim was clueless about yaml.

I tried changing the ~root/.vim/yaml.vim in .vimrc to ~root/.vim/yaml.vim -- no joy.

With some digging I discovered that vi doesn't read .vimrc when you're root but vim does!!??  But vim didn't work either.

Out of exasperation I tried rebooting my Linux server.  Now it doesn't work for user ansible either!!??

I tried :source ~/.vimrc and it kinda worked.  That picked up the .vimrc settings but not the syntax-highlight stuff in yaml.vim, even if I did a :e! to force it to re-read the file and see the file suffix.  But that only worked for root!?  And only a few times.  Now it doesn't work.  :source ~/.vim/yaml.vim doesn't do anything either.

Help?

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/3c40a249-9481-4532-a283-4b13ad49d9df%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Customize vim for YAML

Gary Fritz
I discovered vim -V, which dumps out a running commentary about what it's doing as it comes up.  On the second page I see this:

Executing BufRead Auto commands for "*.yml"
autocommand so ~/.vim/yaml.vim
chdir(/home/ansible/.vim)
fchdir() to previous dir
line 0: sourcing "/home/ansible/.vim/yaml.vim"
finished sourcing /home/ansible/.vim/yaml.vim

(That was for a non-root user, but root is the same.)

So it's definitely sourcing the yaml.vim file.  That means the .vimrc file must have been sourced.  So why don't I see the settings from .vimrc (set ai ts=2 sw=2 et number)?  And since it sourced the yaml.vim file, why isn't it highlighting syntax??  Especially since this used to work for non-root users!?

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/4a543968-4ee2-4fde-8c5b-f3cc67582ac0%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Customize vim for YAML

Gary Fritz
In reply to this post by Gary Fritz
I got an answer from vi.stackexchange.com:

* I needed filetype on in .vimrc to get it to recognize the filetype.  (Don't think I had that before when it worked!??  And in fact once I had this all working, I deleted the filetype on and it still worked.  Go figger.)
* I needed syntax on in .vimrc to get it to highlight syntax.  (Also don't think I had this before, but I DO need this one.)
* I did NOT need the first autocommand to source ~/.vim/yaml.vim.  Without it, vim sources /usr/share/vim/vim80/syntax/yaml.vim.
* In the remaining autocommand they recommend I use setlocal instead of set, and sts=2 (softtabstop) instead of ts=2 (tabstop).

Works great now!

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/1c9a03d1-5063-44de-85bb-1891aa9f860f%40googlegroups.com.