adding new file type to ultisnips - vim

I am trying to add for the cuda (.cu) files. The basic objective is to first make all c,cpp snippets available for the cu files and then add additional support. The first thing I did to test is to set the filetype inside vim
set ft:cpp.c
and this works. Then I tried to go to the vim-snippets/snippets and vim-snippets/UltiSnips and tried to copy the cpp.snippets file to cu.snippets. But this is not working (not working as in --the snippets are not detected--) . I have also added
au BufNewFile,BufRead *.cu set ft=cuda
au BufNewFile,BufRead *.cuh set ft=cuda
in my .vimrc. Even after this it is not working.
I also checked the UltiSnipsSnippetDirectories. It is pointing to Ultisnips.
I also tried creating a cu.snippets which just tries to extend cpp (nothing else). This is also not working.
As a side question: As far I understand https://github.com/honza/vim-snippets has two folders with snippets. snippets/* for the snipmate based ones and UltiSnips/* for the ultisnips based ones. However the inc snippet is only provided on the c.snippets in snippets directory (not in ultisnips). But strangely inc works on c files for me. I am positive that I am not using snipmate. How could this happen? Am I missing something. or is it that ultisnips can understand both formats?

Ultisnips uses Vim's filetype detection system. So to see what filetype Vim thinks you have use the :set filetype? command.
If that's incorrect, you can try
autocmd BufRead,BufNewFile *.cu setfiletype cuda
Also, I used Vundle, and I used call vundle#rc(), but I needed to change that to call vundle#begin() and call vundle#end()

I think, some plugin in your plugins list conflicts with your custom filetype detection config. Just faced with the same issue (tried to declare custom filetype for Jest typescript tests for react). My filetype settings overrides by peitalin/vim-jsx-typescript plugin.
So you should to switch off some of yor installed cpp plugins for detect culprit.

Related

How filetype plugin on changes loading

What occurs when the filetype plugin option is changed? For example, from the docs it says:
When loading filetype plugins has been enabled :filetype-plugin-on, options
will be set and mappings defined.
Does this mean that if filetype plugin is off, then vim will not add certain directories to the vim runtime? Or what exactly does this parameter do, I'm a bit confused?
What this command does, it simply loads a relevant script from $VIMRUNTIME.
For filetype plugin on it's $VIMRUNTIME/ftplugin.vim; for filetype plugin off it's $VIMRUNTIME/ftplugof.vim; for filetype off it's $VIMRUNTIME/ftoff.vim, and so on.
Basically ftoff.vim clears filetypedetect auto-group (the one which traps BufRead); and ftplugof.vim clears filetypeplugin group (then one which traps FileType).
I suggest to everyone who is interested in internals to explore the code himself. The source worth a thousand words.

Vim plugins declared in ftplugin do not work

Gvim is behaving weird and I can't find the reason. I use Vundle, and all the plugins declared in my .vimrc are working fine. I declared some additional settings and plugins in .vim/after/ftplugin/java.vim.
The mappings work fine, but the plugins do not work. If I choose a different file in my current gvim session, I get those error messages:
Error detected while processing function vundle#config#bundle[2]..<SNR>14_check_bundle_name:
line 2:
Vundle error: Name collision for Plugin Raimondi/delimitMate. Plugin Raimondi/delimitMate previously used the name "delimitMate". Skipping Plugin Raimondi/delimitMate.
Vundle error: Name collision for Plugin artur-shaik/vim-javacomplete2...
[comment: same error message for all plugins declared in the ftplugin]
I noticed, that if I run :VundleInstall the plugins are suddenly working (the error messages stay when I change the file, no plugins are installed when I use the command).
Here is the beginning of my .vimrc:
syntax on
set guifont=Inconsolata\ Medium\ 12
set nocompatible
set t_Co=256
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
"[comment: all plugins I use for every filetype]
call vundle#end() " required
filetype plugin indent on
and this is my java.vim file:
filetype off
"to automatically close brackets
Plugin 'Raimondi/delimitMate'
"omni-complete for Java
Plugin 'artur-shaik/vim-javacomplete2'
"use tab to navigate through insert completion
Plugin 'ervandew/supertab'
filetype plugin indent on
"needed to make javacomplete2 working properly
autocmd FileType java setlocal omnifunc=javacomplete#Complete
My OS is Ubuntu 16.04.
You're mistaken regarding what ftplugins are doing and what they should contain.
Ftplugins are loaded once per buffer, every time a new buffer is created/opened.
They are meant to contain buffer local definitions:
:map <buffer> keybinding action
:iab <buffer> keybinding expanded sequence
:setlocal option[=value]
:command -b CommandName :Action
:let b:option = value
set the localleader (but be certain it's done before any other ftplugin for the same filetype) (EDIT: localleader is actually a global setting, my mistake)
They could then load other things that work the same way with :runtime or :so. They could contain functions, but it's best to define them into autoload plugins since Vim7. They may contain buffer local menu definitions, but this requires a plugin as this is not standard.
They are definitively not meant to contain global definition like the ones you have defined. It's not really the place to load global plugins that'll stay activated afterwards.
I know that some plugins manager load plugins on the fly depending on the type of the file we work on. I've never shared this need when we are using properly defined ftplugins, and lightweight plugins that only define a few mappings and keep their functions into autoload plugins.
Last thing, ftplugins are supposed to contain anti reinclusion guards. On a typical scenario this is not that useful. Many use b:did_ftplugin for that purpose, but I avoid this variable as I prefer to have as many ftplugins (for a same filetype) as themes (one that specializes the brackets pairs, one that defines the mapping to automatically expand a switch statement from the type of a variable, one that defines abbreviations for control statements, and so on). As a consequence I cannot use the same guard for all files.
All your :Plugin commands are supposed to be between these two lines:
call vundle#begin()
" :Plugin commands go here
call vundle#end()
Try another plugin manager if you absolutely need lazy loading.

Using the VIM JavaScript syntax file

I tried including the following syntax file into my vim.
I installed this plugin using Pathogen as per instruction:
git clone https://github.com/jelera/vim-javascript-syntax.git ~/.vim/bundle/vim-javascript-syntax
Then included the following in my .virc file
au FileType javascript call JavaScriptFold()
After restarting vim and opening a JavaScript file I am not able to fold using the standard zo, zc commands .. any clue ?
Check whether the fold settings have been activated:
:verbose set foldmethod?
:syntax list foldBraces
The first should yield syntax, and the syntax group should be defined.
Note that only { ... } blocks spanning multiple lines are folded by this.
For anyone else who may come across this scenario; I had the exact same problem. The fix, for me, was to edit my .vimrc by moving
syntax enable
above
au FileType javascript call JavaScriptFold()

Vim Vundle - load ftplugin for different filetype

How, using Vundle, can I load a ftplugin for a filtype it wasn't written for?
In my old .vimrc (before I started using Vundle), I would do something like this:
au FileType xquery ru fplugin/xhtml.vim
But that doesn't seem to be doing the trick.
...any thoughts?
Thanks!
(Not a Vundle user, and I think it should not affect your command.)
Instead of the :autocmd, create a file ftplugin/xquery.vim (either under ~/.vim/ or as a bundle), with the following contents:
runtime! ftplugin/xhtml.vim
runtime! ftplugin/xhtml_*.vim ftplugin/xhtml/*.vim
(This assumes you have :filetype plugin on.)
OK, so I'm just coming back to this, and it turns out that what I had up there actually does work. Except that the line that I'm actually using in Vim uses a lower case "t" in "Filetype". Not sure if that was the issue, but it works perfectly now:
au Filetype xquery ru ftplugin/xhtml.vim

How to enable go.vim by default (automatically)?

The instructions on the Vim site says to just put the file in the /syntax folder. This works all right and well. But, for me to use the syntax I must set the following
:set syntax=go
Every single time. So, I know I am doing something wrong. I just don't know what.
Here are some things from looking around,
My HTML5 syntax set is from Rodrigo's HTML5 omnicomplete function and syntax vimball file. Though this uses some installation script to get it going.
As far as I can tell this would be my first manual adding of syntax file.
Also, my VIMRUNTIME is not set, well because there is no syntax.vim file, so from reading the documentation I see it checks for files via synload.vim
I even read the "Making Your Own Syntax Files" section, which says that same as above with the syntax=go option. Am I supposed to be detecting the .go filetype as described in new filetype section?
How can I enable syntax highlighting for GO by default?
This is for Mac Snow Leopard.
I don't think it is this complicated but I decided to leave all the different documentation I skimmed. GO and Vim say to just add the file. But it is definitely not detecting it automatically
If you are using filetype detection in your ~/.vimrc file with the following line:
filetype plugin indent on
then you can place the file in the following folder:
~/.vim/after/ftplugin/go.vim
or for windows
~/vimfiles/...
For the filetype detection to work, would would want the autocmd in a file in the ftdetect folder:
~/.vim/ftdetect/go.vim
and the contents would be:
autocmd BufNewFile,BufReadPost *.go set filetype=go
Use autocmd:
au BufRead,BufNewFile *.go setlocal filetype=go

Resources