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

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

Related

adding new file type to ultisnips

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.

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()

Does Vim automatically load filetype-specific plugins for custom filetypes?

I understand that the recommended method for defining filetype-specific behavior in Vim is with .vim files and filetype plugin option. To add settings for .html files, for instance, I would add filetype plugin on in my .vimrc and add the settings to ~/.vim/ftplugin/html.vim.
All examples of this method that I can find, however, are about popular existing filetypes like .html or .sql. Would the same fix work for custom-defined file types? Let's say I want to use a new filetype with the extension .newft. If I create ~/.vim/ftplugin/newft.vim with the settings for this new type and load somefile.newft, would Vim automatically detect its type and load newft.vim?
I'm asking this because this is exactly what I'm doing and it's not working so far. I'd like to know whether this is an error or an expected behavior of Vim.
:h new-filetype outlines the different ways to add support for a new filetype.
I recommend method A which is as simple as writing the following in ~/.vim/ftdetect/newft.vim:
autocmd BufRead,BufNewFile *.newft set filetype=newft
and letting Vim deal with the rest.
Assuming you have filetype plugin on in your ~/.vimrc, the example above will make Vim try to source ~/.vim/ftplugin/newft.vim each time you read or create a buffer associated with a *.newft file or do :setfiletype newft/:set filetype=newft on an existing buffer.

VIM: set filetype=txt for every new file [No Name]

I tried all possible things to let vim set filetype to 'txt' to all new files I create (in a new tab) but it doesn't work.
This is p.e. what I've read on the web a few times:
au BufRead,BufNewFile *.txt setlocal ft=txt
(to put in _vimrc)
However it doesn't work.
Can anyone help me?
The following line, added to your .vimrc, will set the filetype to text if it is not already set.
autocmd BufEnter * if &filetype == "" | setlocal ft=text | endif
All files are considered plain text unless you have file-type detection turned on or explicitly set the file-type. However, Vim lets you set the file-type to any old text, so are you absolutely sure it is not working?
:set filetype=banana
:set filetype?
filetype=banana
Setting the filetype is not going to have any noticable effect unless there is a corresponding file in the ftplugin Vim directory and Vim does not ship with a txt.vim file-type file. You could, of couse, add a txt.vim here but I am not sure what this will gain you over default settings — what special behaviour would you want for text files that you would not want for the default behaviour?
(If you want syntax highlighting (whatever that may mean for text file!) then you will also have to create a txt.vim file in the syntax Vim directory.)
What effect are you trying to achieve?
It's actually way simpler than all this. Just put this as one of the first lines in your .vimrc.
set ft=txt
Whenever opening a new file, the filetype will be set to txt. But if you open a file with an known existing type it will still be overridden no problem.

How can I disable code folding in vim with vim-latex?

I have tried the usual approaches, and have read :help tex.vim
(see : http://vimdoc.sourceforge.net/htmldoc/syntax.html )
I've taken a brief look at syntax/tex.vim, but can't see how to disable it without rebuilding vim without folding. I'm sick of hitting 'zE'.
Lines I've tried in my .vimrc:
set foldlevel=manual
set foldlevelstart=99
let g:tex_fold_enabled=0
Just noticed that there are variables to control folding in vim-latex-suite, at least as of v1.6 of the plugin. The functionality is documented here:
http://vim-latex.sourceforge.net/documentation/latex-suite.html#latex-folding
In short you should be able to change three global variables to get rid of all folding:
:let Tex_FoldedSections=""
:let Tex_FoldedEnvironments=""
:let Tex_FoldedMisc=""
That should get rid of all folding. If you want to disable some folding but not all then you can control things by setting the appropriate values for each variable, as described in the documentation link above. Hope that helps.
What about
autocmd Filetype tex setlocal nofoldenable
The folding functionality all seems to located in folding.vim file of latex-suite distribution. This file is referenced in line 825 of my main.vim file in the latex-suite folder of the ftplugin folder. That line reads:
exe 'source '.fnameescape(s:path.'/folding.vim')
Comment out that line and, as far as I can tell, it strips out all the folding in latex-suite plugin. I don't think it affects anything else, but I haven't checked.

Resources