dracula / vim

πŸ§›πŸ»β€β™‚οΈ Dark theme for Vim
https://draculatheme.com/vim
MIT License
1.34k stars 455 forks source link

dracula vim not working via ~/.vimrc #149

Closed pjs59 closed 5 years ago

pjs59 commented 5 years ago

[Copied this over from stackoverflow - https://stackoverflow.com/questions/57219822/custom-syntax-highlighting-not-working-via-vimrc.]

I have dracula.vim in my ~/.vim/colors directory, and if I set :colorscheme dracula inside vim, then it works. However, if I try to replicate this via vimrc, I get errors.

Specifically, if I make my ~/.vimrc file either:

syntax enable
colorscheme dracula

or just:

colorscheme dracula

I get the following errors when I run vim:

E116: Invalid arguments for function <SNR>2_h
line  186:
E121: Undefined variable: s:green
E116: Invalid arguments for function <SNR>2_h
line  187:
E121: Undefined variable: s:comment
E116: Invalid arguments for function <SNR>2_h
line  188:
E121: Undefined variable: s:cyan
E116: Invalid arguments for function <SNR>2_h
line  190:
E121: Undefined variable: s:orange
E116: Invalid arguments for function <SNR>2_h
line  191:
E121: Undefined variable: s:bg
E116: Invalid arguments for function <SNR>2_h
line  192:
E121: Undefined variable: s:red
E116: Invalid arguments for function <SNR>2_h
line  202:
E121: Undefined variable: s:fg
E116: Invalid arguments for function <SNR>2_h
line  203:
E121: Undefined variable: s:bglighter
etc.

After the errors, vim opens but with no syntax highlighting.

I've also tried to use vundle. I've cloned vundle per the instructions on the git, and made my ~/.vimrc as follows:

set nocompatible
filetype off

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

Plugin 'VundleVim/Vundle.vim'

Plugin 'dracula/vim'

call vundle#end()
filetype plugin indent on

I've then run :PluginInstall with success. But no syntax highlighting. If I add the line syntax on to my vimrc, then I do get syntax highlighting, but it's the default colours rather than the dracula theme.

For reference,

$ vim --version
VIM - Vi IMproved 8.1 (2018 May 18, compiled Jul 26 2019 05:29:00)
Included patches: 1-1749
Compiled by [me]
Huge version without GUI.  Features included (+) or not (-):
+acl               -farsi             -mouse_sysmouse    -tag_any_white
+arabic            +file_in_path      +mouse_urxvt       -tcl
+autocmd           +find_in_path      +mouse_xterm       +termguicolors
+autochdir         +float             +multi_byte        +terminal
-autoservername    +folding           +multi_lang        +terminfo
-balloon_eval      -footer            -mzscheme          +termresponse
+balloon_eval_term +fork()            +netbeans_intg     +textobjects
-browse            +gettext           +num64             +textprop
++builtin_terms    -hangul_input      +packages          +timers
+byte_offset       +iconv             +path_extra        +title
+channel           +insert_expand     -perl              -toolbar
+cindent           +job               +persistent_undo   +user_commands
-clientserver      +jumplist          +postscript        +vartabs
-clipboard         +keymap            +printer           +vertsplit
+cmdline_compl     +lambda            +profile           +virtualedit
+cmdline_hist      +langmap           +python            +visual
+cmdline_info      +libcall           -python3           +visualextra
+comments          +linebreak         +quickfix          +viminfo
+conceal           +lispindent        +reltime           +vreplace
+cryptv            +listcmds          +rightleft         +wildignore
+cscope            +localmap          -ruby              +wildmenu
+cursorbind        -lua               +scrollbind        +windows
+cursorshape       +menu              +signs             +writebackup
+dialog_con        +mksession         +smartindent       -X11
+diff              +modify_fname      -sound             -xfontset
+digraphs          +mouse             +spell             -xim
-dnd               -mouseshape        +startuptime       -xpm
-ebcdic            +mouse_dec         +statusline        -xsmp
+emacs_tags        -mouse_gpm         -sun_workshop      -xterm_clipboard
+eval              -mouse_jsbterm     +syntax            -xterm_save
+ex_extra          +mouse_netterm     +tag_binary        
+extra_search      +mouse_sgr         -tag_old_static    
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/usr/local/share/vim"
Compilation: gcc -std=gnu99 -c -I. -Iproto -DHAVE_CONFIG_H     -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1       
Linking: gcc -std=gnu99   -L/usr/local/lib -Wl,--as-needed -o vim        -lm -ltinfo -lnsl  -lselinux  -ldl    -L/usr/lib64/python2.7/config -lpython2.7 -lpthread -ldl -lutil -lm -Xlinker -export-dynamic

I downloaded dracula.vim from the git and (separately) installed via vundle yesterday, 2019-07-26, so they should be the latest versions.

benknoble commented 5 years ago

Can you show the directory structure of wherever dracula is installed?

benknoble commented 5 years ago

An update to draculatheme.com that hasn't gone live yet includes these instructions for vundle users:

Plugin 'dracula/vim', { 'name': 'dracula' }
:PluginInstall
pjs59 commented 5 years ago

Here's the tree structure of the whole of my .vim directory.

β”œβ”€β”€ bundle
β”‚Β Β  β”œβ”€β”€ vim
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ after
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ plugin
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  └── dracula.vim
β”‚Β Β  β”‚Β Β  β”‚Β Β  └── syntax
β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ css.vim
β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ gitcommit.vim
β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ html.vim
β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ javascript.vim
β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ json.vim
β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ markdown.vim
β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ ocaml.vim
β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ perl.vim
β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ php.vim
β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ plantuml.vim
β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ python.vim
β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ ruby.vim
β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ rust.vim
β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ sass.vim
β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ sh.vim
β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ tex.vim
β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ tsx.vim
β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ typescript.vim
β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ vim.vim
β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ xml.vim
β”‚Β Β  β”‚Β Β  β”‚Β Β      └── yaml.vim
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ autoload
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ airline
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  └── themes
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      └── dracula.vim
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ dracula.vim
β”‚Β Β  β”‚Β Β  β”‚Β Β  └── lightline
β”‚Β Β  β”‚Β Β  β”‚Β Β      └── colorscheme
β”‚Β Β  β”‚Β Β  β”‚Β Β          └── dracula.vim
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ colors
β”‚Β Β  β”‚Β Β  β”‚Β Β  └── dracula.vim
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ doc
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ dracula.txt
β”‚Β Β  β”‚Β Β  β”‚Β Β  └── tags
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ LICENSE
β”‚Β Β  β”‚Β Β  └── README.md
β”‚Β Β  └── Vundle.vim
β”‚Β Β      β”œβ”€β”€ autoload
β”‚Β Β      β”‚Β Β  β”œβ”€β”€ vundle
β”‚Β Β      β”‚Β Β  β”‚Β Β  β”œβ”€β”€ config.vim
β”‚Β Β      β”‚Β Β  β”‚Β Β  β”œβ”€β”€ installer.vim
β”‚Β Β      β”‚Β Β  β”‚Β Β  └── scripts.vim
β”‚Β Β      β”‚Β Β  └── vundle.vim
β”‚Β Β      β”œβ”€β”€ changelog.md
β”‚Β Β      β”œβ”€β”€ CONTRIBUTING.md
β”‚Β Β      β”œβ”€β”€ doc
β”‚Β Β      β”‚Β Β  β”œβ”€β”€ tags
β”‚Β Β      β”‚Β Β  └── vundle.txt
β”‚Β Β      β”œβ”€β”€ ftplugin
β”‚Β Β      β”‚Β Β  └── vundlelog.vim
β”‚Β Β      β”œβ”€β”€ LICENSE-MIT.txt
β”‚Β Β      β”œβ”€β”€ README_KR.md
β”‚Β Β      β”œβ”€β”€ README.md
β”‚Β Β      β”œβ”€β”€ README_ZH_CN.md
β”‚Β Β      β”œβ”€β”€ README_ZH_TW.md
β”‚Β Β      β”œβ”€β”€ syntax
β”‚Β Β      β”‚Β Β  └── vundlelog.vim
β”‚Β Β      └── test
β”‚Β Β          β”œβ”€β”€ files
β”‚Β Β          β”‚Β Β  └── test.erl
β”‚Β Β          β”œβ”€β”€ minirc.vim
β”‚Β Β          └── vimrc
└── colors
    └── dracula.vim
pjs59 commented 5 years ago

Just tried adding , { 'name': 'dracula' } - no change.

dsifford commented 5 years ago

You have two colors/dracula.vim files. The first one (the outermost one nearest the top level) is being loaded first. Delete that.

pjs59 commented 5 years ago

Still the same - i.e. works as soon as I run :colorscheme dracula inside vim, but not otherwise. (If I comment out Plugin 'dracula/vim', { 'name': 'dracula' } in my vimrc then :colorscheme dracula no longer works though.)

pjs59 commented 5 years ago

Ah, so I should have guessed this earlier given that it works with :colorscheme dracula inside vim, but the following vimrc now works:

set nocompatible
filetype off

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

Plugin 'VundleVim/Vundle.vim'

Plugin 'dracula/vim'

call vundle#end()
filetype plugin indent on

colorscheme dracula
benknoble commented 5 years ago

Sounds like your issue is resolved @pjs59 ? Going to close; please re-open if not resolved.

pjs59 commented 5 years ago

Strange though. Am I really the only one who's had to do this? I didn't mention, but this has actually resolved the same issue on two different machines I use. Could be worth adding as a troubleshooting measure somewhere?

benknoble commented 5 years ago

Strange that having two different colorscheme files for the same colorscheme in multiple locations causes issues? To be honest, I'm not surprised, even if it seems like it could work: the errors themselves are bizarre, but having the same file in two different similar spots seems like a recipe for a problem to me.

In general, the situation seems similar to using more than one plugin-manager, or to manually managing plugins alongside a plugin-manager.

@pjs59 Can you clarify how you ended up in this situation (~/.vim/colors/dracula and vundle dracula) so we can identify what needs to be clarified to future installees?

pjs59 commented 5 years ago

It wasn't deleting one of the two copies that resolved the issue though. It was adding colorscheme dracula to the bottom of my vimrc, after the end vundle line, that did it.

On how I ended up with two copies: I only tried the manual version, adding ~/.vim/colors/dracula, after I'd failed to get dracula to work via vundle. I should have deleted the vundle version when I did that.

benknoble commented 5 years ago

In your original post, you said this was your vimrc

set nocompatible
filetype off

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

Plugin 'VundleVim/Vundle.vim'

Plugin 'dracula/vim'

call vundle#end()
filetype plugin indent on

So I'm not sure that any of us caught that colorscheme dracula was inside the vundle lines. That said, the screenshot on the Vundle repo says plugins will be available after vundle#end. Perhaps the real problem is that this was not made clear?


For the non-vundle users, we have notes on the README and in the help on how to use, e.g., packages with vim8. The crucial change from v2.0 requires that dracula is fully on the runtime path before colorscheme dracula executesβ€”this is not always the case during execution of vimrc, particularly with packages. However, if you place the files into your .vim directory directly (like in the old days), theoretically things will work without issue.

dsifford commented 5 years ago

Just adding a bit to @benknoble's response.

@pjs59 It appears that you might be new to vim. Vim is tricky at baseline. There's lots of places where loading your init files can go wrong and a lot of quirks that take time to get used to.

It sounds like the problem you had was twofold:

  1. You weren't initially registering this plugin correctly in your runtimepath.
  2. You ran colorscheme dracula before vundle fixed # 1.

Finally: Just a quick comment about your pasted configuration...

Why do you set filetype off and then filetype plugin indent on? That's a redundancy. Looks like it's likely a copy/paste from stackoverflow without understanding what it does.

So in short: Because this can be attributed to growing pains. We're not going to adjust our docs. They should be clear enough.

pjs59 commented 5 years ago

@dsifford Re filetype, it is indeed a copy and paste, but from https://github.com/VundleVim/Vundle.vim (both lines are annotated with 'required'). The whole of my current vimrc is copied from there.

I'm not new to vim (I've been using it for about 10 years), but I am new to customizing vim, which is maybe what you meant. I don't know why that's relevant though. Shouldn't anyone be able to follow the instructions and get it installed?

When you say 'You weren't initially registering this plugin correctly in your runtimepath', I'm not sure what I could have done differently given the publicly available documentation? I followed the instructions for using vundle and then the instructions for using dracula with vundle to the letter. I admit I went off piste by adding .vim/colors/dracula.vim, but that was only after I'd established that it wasn't working under the combination of the vundle and dracula instructions. And I still can't get it to work without colorscheme dracula at the end of my vimrc. What I'm trying to say is I don't know how just following the vundle and dracula instructions could ever have got me to a point where this was working.

benknoble commented 5 years ago

As I've mentioned, the instructions on draculatheme.com/vim are out of date wrt Vundle and a few other plugin-management techniques. I've opened https://github.com/dracula/dracula.github.io/issues/85 to address this, which should get changes from https://github.com/dracula/dracula.github.io/pull/75 onto the site.

In the meantime, I believe the core difficulties were

  1. A slight misunderstanding of how Vundle works. This is common: plugin-managers are tough to understand, and Vundle requires things to done in a specific way. In particular, plugins aren't "available" (whatever that means) until after vundle#end has been called.
  2. Dracula using autoloaded files that need to be on the 'runtimepath' before colorscheme dracula is called. The variables that caused your failure are loaded as part of these files.

These two things combine to mean that colorscheme dracula must come after vundle#end. Even in the updated instructions, the maintainers assume that users of Vundle (or other plugin-managers) know how their manager/setup works.

How would you suggest we clarify this? Would asking Vundle to be more clear about its plugin-loading be helpful?

pjs59 commented 5 years ago

I think the main thing is that I didn't see anywhere in either the vundle documentation or the dracula documentation that colorscheme dracula needed to be in the vimrc file (on dracula it's mentioned for manual installation but not vundle). Perhaps I missed it? I don't know where it would be best to put it (vundle if it's standard for all colour schemes? dracula if not?).

benknoble commented 5 years ago

Aha: that is a far different source of confusion. Do you expect vim to know what colorscheme you want? If so, I recommend checking out :help usr_06.txt, particularly :help 06.3.

pjs59 commented 5 years ago

That help file is very interesting, thank you for that. But I don't think I agree with the premise of the question, which seems to me to be that the other two steps in the dracula/vundle installation guide (Plugin '...' and :PluginInstall) are less obvious than colorscheme dracula. I mean, I don't see how your argument doesn't extend to 'Why have any installation instructions?' (Do you expect vundle to know to load the plugin?' 'Do you expect the plugin magically to be installed?')

benknoble commented 5 years ago

Ok, let me back up and try to make sure I'm on your page.

1) You ran PluginInstall via Vundle 2) You expected dracula to load, but it didn't 3) You discovered that you need to use colorscheme dracula to load dracula

Is that a (really brief) summary of what happened?


The truth is, yes, I think that the command colorscheme dracula is fairly obvious to vim users looking at colorschemes. In addition, the very beginning of doc/dracula.txt mentions it.

Would you prefer to see it in the README/website as well?

benknoble commented 5 years ago

@pjs59 Just wanted to drop you a note to say thanks for having the time and patience to help us improve Dracula. We care about our community of users and appreciate your feedback.