I put in my ~/.vimrc file the next lines of code:
filetype plugin on
set omnifunc=syntaxcomplete#Complete
but nothing happened, when I created a file with .c extension and I pressed <Ctrl-X><Ctrl-O> the vim editor popped up a "pattern not found" message.
Here one can see my .vimrc:
You have two problems.
First problem
The command filetype plugin indent on tells Vim to:
detect the filetype of every buffer,
source the appropriate filetype plugin for the detected filetype,
source the appropriate indent script for the detected filetype.
Those things happen automatically, as you load a new buffer. In this specific case (and others) the C ftplugin contains this line:
setlocal ofu=ccomplete#Complete
which effectively overrides your:
set omnifunc=syntaxcomplete#Complete
There are several ways to solve this problem but the most sensible is to make your own filetype plugin:
Create ~/.vim/after/ftplugin/c.vim.
Add setlocal omnifunc=syntaxcomplete#Complete to it.
See :help filetype-plugin.
Second problem
As explained under :help ft-syntax-omni, syntaxcomplete#Complete pulls its suggestions from the current syntax definition. Since syntax highlighting is not enabled by default and you don't enable it explicitly, there is no "current syntax" and thus no syntax-based completion.
You are supposed to enable it explicitly, in your vimrc:
syntax on
Conclusion
This is how your vimrc should look like:
filetype plugin indent on
syntax on
And this is your brand new custom filetype plugin for C:
" ~/.vim/after/ftplugin/c.vim
setlocal omnifunc=syntaxcomplete#Complete
The syntax code completion uses current language keywords to complete the text. If the text doesn't match any keyword, it says "pattern not found". For example, in a .c file
func| -> function
abc| -> "pattern not found"
See :h ft-syntax-omni for details.
Related
I created a dedicated syntax file
.vim/syntax/foo.vim
and I would like to apply this syntax file for all files having the coresponding ending "myfile.foo"
For doing this, I added the following line in the .vimrc
au BufNewFile,BufRead *.foo setf foo
this is perfectly working, but...
If the text inside the file is starting with a "#", a different filetype is applied:
filetype=conf
I can override this by using :set filetype=foo to get my desired type.
It is a bit annoying and I don't know how can I overcome this workaround.
Do not put anything to your vimrc!
Insert your command into ~/.vim/ftdetect/foo.vim instead.
The point is that your command must get into filetypedetect auto-group, otherwise any subsequent :filetype detect will overwrite your filetype to the defaults.
I want to disable syntax highlighting for a particular programming language. I'm currently using this
au FileType foo syntax off
however this has the problem that it disables syntax highlighting for any new buffers that I open in the same window, even when they have different filetypes. Is it possible to disable syntax highlighting only for this filetype? (e.g. any other buffers in the same window that has different filetype should have syntax highlighting enabled)
One of the things that could solve this problem is to create a syntax/foo.vim file that doesn't highlight anything, but I'm not sure how to implement this when foo is one of the languages that vim highlights by default.
au FileType foo setlocal syntax=OFF
If you want to isolate the config a bit, create a file called ~/.vim/after/ftplugin/foo.vim and put this in it:
setlocal syntax=OFF
I'm happily loading either Notes and Txtfmt plugins in neovim, command line version, on Mac Os Sierra.
Both greatly working on their own, but no chance to have 'em loading together in a file of filetype notes.txtfmt as per Vim documentation about dot-separated filetypes.
First attempt I made was following Notes documentation to be able to work together with Txtfmt and creating the file
$/.vim/after/ftplugin/notes.vim
with the content:
" Enable Txtfmt formatting inside notes.
setlocal filetype=notes.txtfmt
As stated in this discussion this approach does not work, creating an infinite loop.
Next, as suggested by bpstahlman in the mentioned post, I added to my .vimrc the following autocommand:
augroup TxtfmtInNotes
au!
au FileType * if expand("<amatch>") == "notes" | setlocalft=notes.txtfmt|endif
augroup END
Now, it seemed that could be working, in that it declares a 'notes.txtfmt' filetype in Vim status bar, immediately after opening a new :Note buffer.
The bad news: txtfmt plugin does not load, no mapped command is working.
The funny: doing again :setlocal ft=notes.txtfmt
(which is supposed to have already been done by the suggested autocommand) everything gets properly loaded.
In other words it looks like in my case the autocommand works in changing filetype but not in loading the txtfmt plugin, which is loaded only repeating the filetype command.
Any suggestion on this?
Thanks
If the Notes plugin had a filetype detection (apparently it hasn't, and the filetype is only set by the commands the plugin provides), I would overwrite that to
:au BufNewFile,BufRead *.note setf notes.txtfmt
In your case, instead of using a compound filetype, I would simply emulate its effects in ~/.vim/after/ftplugin/notes.vim:
runtime! ftplugin/txtfmt.vim ftplugin/txtfmt_*.vim ftplugin/txtfmt/*.vim
I haven't tested it, but it's more straightforward and therefore hopefully more robust than your current solution of hooking into the FileType event.
I want to make a filetype plugin(in fact asm) of vim. After Searching for a while on the Internet, i found that i should add a asm.vim in ~/.vim/ftplugin folder. So I added that new file asm.vim in that folder and wrote the following codes:
map <F7> oTest<CR><Esc>
a very simple vim script, only output the Test string in the next line. but i failed, when i opened an xxx.asm file and pressed <F7> button, nothing happened. Anything wrong with the code? any help appreciated!
You need to ensure that Vim actually detects the filetype; asm is defined in $VIMRUNTIME/filetype.vim, and there is a syntax, but no filetype plugin yet. Check that
:set filetype?
outputs asm. If not, you need to work on the detection.
You also need to have :filetype plugin on (in your ~/.vimrc); otherwise, no filetype plugin scripts aren't loaded. Check with :scriptnames.
Also note that you should not define global mappings or commands in a filetype plugin. Use :noremap <buffer> <F7> ....
You can check your mapping exists with :verbose map <F7>.
The one IDE feature that I always missed and invariably plug into vim is tab completion.
I'm a big fan of SuperTab, but one thing I can't stand is the fact that it treats the parts of CSS class names and IDs with dashes as individual words.
I've found a couple of possible solutions for camelCase and underscore_completion but I can't seem to find anything that supports plain-old-dashes.
This is not a CSS-specific problem: Vim uses the value of iskeyword to perform completion.
Type :set iskeyword? to see what characters are considered to be part of keywords. The default on a Mac is supposed to be #,48-57,_,192-255.
You can add the dash to the list with this command:
:set iskeyword+=-
Add this line to your ~/.vimrc to make this setting stick:
set iskeyword+=-
This seems to work for me:
autocmd FileType css,scss set iskeyword=#,48-57,_,-,?,!,192-255
Taken from here: VIM: How to autocomplete in a CSS file with tag ids and class names declared in HTML file
For future readers: if you want the benefits of dashes for edit/movement commands, but want full property autocompletion, try adding this to your .vimrc:
augroup css_dash_autocompletion
autocmd FileType scss,css autocmd! css_dash_autocompletion InsertEnter <buffer> set isk+=-
autocmd FileType scss,css autocmd css_dash_autocompletion InsertLeave <buffer> set isk-=-
augroup END
The first ! prevents duplicate event firing. Thanks to ZyX for the structure. If you re-source your .vimrc, you will need to :e any (S)CSS files you have open to pick up the change.