E492: UltiSnips not an editor command - vim

When I'm trying to use UltiSnips, it returns this error:
E492: Not an editor command: snippet test "Test Snippet"
E492: Not an editor command: Test
E492: Not an editor command: endsnippet
My .vimrc look like that: https://pastebin.com/0AwFks2J
What should I do to fix it?

There are two things.
You put Plugin “SirVer/UltiSnips” and Plugin “honza/vim-snippets” outside of your call vundle#begin()...call vundle#end() block, you’ll need to move those in order for those plugins to be loaded.
Snippets are not supposed to be defined in your vimrc. They are supposed to be defined in *.snippets files. By default, UltiSnips looks for an UltiSnips directory inside directories in your 'runtimepath'. You could create a ~/.vim/UltiSnips directory if it doesn’t exist and put your *.snippets flies there.

Related

native vim plugin load order

Sometimes Vim plugins suggest a load order, but Vim nowaday natively supports loading plugins with no plugin manager. You just put a submodule in a folder such as ~/.vim/pack/vendor/start and it'll automatically load. So, my question is how do you ensure a load order similar to how people would previously. Older way of doing things example below:
Plug 'preservim/nerdtree' |
\ Plug 'Xuyuanp/nerdtree-git-plugin' |
\ Plug 'ryanoasis/vim-devicons'
Taken from https://github.com/Xuyuanp/nerdtree-git-plugin#faq.
Let's try a little experiment…
Create the following dummy files with their corresponding content:
Filepath
Content
pack/dummy/start/nerdtree/plugin/foo.vim
echom "nerdtree"
pack/dummy/start/nerdtree-git-plugin/plugin/bar.vim
echom "nerdtree-git-plugin"
pack/dummy/start/vim-devicons/plugin/baz.vim
echom "vim-devicons"
Start Vim and you should see something like the following:
$ vim
nerdtree
nerdtree-git-plugin
vim-devicons
Press ENTER or type command to continue
which is consistant with:
:filter dummy scriptnames
40: ~/.vim/pack/dummy/start/nerdtree/plugin/foo.vim
41: ~/.vim/pack/dummy/start/nerdtree-git-plugin/plugin/bar.vim
42: ~/.vim/pack/dummy/start/vim-devicons/plugin/baz.vim
Press ENTER or type command to continue
Based on this experiment, we can conclude that the built-in "package" feature will "load" plugins found in start/ in the filesystem order which happens to be the same as the prescribed order anyway. Of course, your filesystem may order directories differently than mine, so YMMV.
In theory, the :help :packadd command should allow you to "manage" your plugins from your vimrc, like you would with a plugin manager. Let's experiment with it…
Rename start/ to opt/:
pack/dummy/opt/nerdtree/
pack/dummy/opt/nerdtree-git-plugin/
pack/dummy/opt/vim-devicons/
Add the following lines to your vimrc after any syntax on or filetype on line:
packadd! nerdtree
packadd! nerdtree-git-plugin
packadd! vim-devicons
Start Vim:
$ vim
vim-devicons
nerdtree-git-plugin
nerdtree
Press ENTER or type command to continue
What?
Well… I guess you could experiment with ordering, here, until you get the desired order but that reverse order looks like a bug to me.

Added new scripts for vim functionality that is not working

I am in a Mac OS and I just added some scripts to get new functionality from my vim editor and when I go back into the vimrc file I continue to get this error:
vim ~/.vimrc
Error detected while processing /Users/danale/.vimrc:
line 12:
E117: Unknown function: pathogen#infect
E15: Invalid expression: pathogen#infect()
I have looked at similar posts here that are not very helpful. Ultimately, I would like to use nerdtree configuration so I can use VIM as my IDE.
If I hit enter anyway, I get this error:
Error detected while processing VimEnter Auto commands for "*":
E492: Not an editor command: NERDTree | endif
and it does not take me to a nerdtree type of view just an empty welcome to vim view.
You need to install pathogen.

Why won't vim recognise a plugin command in the vimrc, but it will recognise it when running?

I've installed the vim-gitgutter plugin with pathogen.
I can type :GitGutterLineHighlightsEnable from inside vim and line highlights are turned on, great.
But I want line highlights to be automatically enabled at startup, so I added the command to my ~/.vimrc. However when I start vim, I get "E492: Not an editor command: GitGutterLineHighlightsEnable". Once vim has started up, I can run the command.
My vimrc looks like this:
execute pathogen#infect()
colorscheme railscasts
.. snip tabs and colors etc ..
GitGutterLineHighlightsEnable
hi GitGutterAddLine guibg=#222F22
hi GitGutterChangeLine guibg=#222239
hi GitGutterDeleteLine guibg=#2F2222
Figured it out.
.vimrc is executed before plugins are loaded. From this related question, I changed the commands to:
autocmd VimEnter * GitGutterLineHighlightsEnable
This executes the command after vim has started up.
Use
let g:gitgutter_highlight_lines = 1
instead of
GitGutterLineHighlightsEnable
As you determined yourself, plugins are processed after the .vimrc.
What you can do if you don't like using a VimEnter autocmd, is put a file in your ~/.vim/after/plugin directory for any commands that should run after plugins are loaded.

Unknown function: NERDTreeAddKeyMap

I'm trying to add a keymap to my NERDTree configuration which executes the current FileNode and displays the output. I put this script file in my ~/.vim/plugin directory.
The keymap actually works when I source the script file from within Vim, but displays the error "Unknown function: NERDTreeAddKeyMap" when starting Vim.
I used Pathogen for my plugins, and in my ~/.vimrc I have all the necessary :
" Enable filetype plugins
filetype plugin indent on
" Start Pathogen plugin to load bundle
call pathogen#infect()
call pathogen#helptags()
As well as NERDTree in my ~/.vim/bundle directory.
Where should I move the script so that it is automatically loaded on Vim startup, without this ugly error ?
The filetype plugin indent on line is supposed to come after the two Pathogen lines.
The relevant documentation says:
This code should sit in a file like ~/.vim/nerdtree_plugin/mymapping.vim.
So, since you use Pathogen, the right place is probably:
~/.vim/bundle/[nerdtree directory]/nerdtree_plugin/mymapping.vim

How to turn-off a plugin in Vim temporarily?

I have multiple plugins in Vim and some of them modify the default behavior of Vim. For example I use Vimacs plugin, which makes Vim behave like emacs in the insert mode alone. Sometime I want to turn off the Vimacs plugin without moving the vimacs.vim out of the plugins directory. Is there a way to do it?
You can do this if you use a plugin manager like Vundle or Pathogen, which will keep the plugin in its own directory underneath the ~/.vim/bundle/ directory.
In that case, just find out the runtimepath of the vimacs plugin with the following command:
set runtimepath?
Let's say it's ~/.vim/bundle/vimacs.
Then, put this command in your .vimrc:
set runtimepath-=~/.vim/bundle/vimacs
To load vimacs, just comment that line out and relaunch Vim (or source your .vimrc).
See which variable vimacs check on start. On the begin of the script file find something Like if exists('g:vimacs_is_loaded").... Then set this variable in your .vimrc or while start vim with vim --cmd "let g:vimacs_is_loaded = 1".
In case you are using pathogen, this post gives a better answer, in my opinion. Since I have frequent need to disable snippets when using latex, also added this in my ~/.config/ranger/rc.conf:
map bs shell vim --cmd "let g:pathogen_blacklist = [ 'ultisnips', 'vim-snipmate' ]" %f
This way, whenever I want to open a file with snippets disabled, it is easy.

Resources