|
|
| Line 1: |
Line 1: |
| − |
{{duplicate|765}} |
|
| − |
{{review}} |
|
| |
{{TipImported |
|
{{TipImported |
| |
|id=498 |
|
|id=498 |
| Line 13: |
Line 11: |
| |
|category2=Syntax |
|
|category2=Syntax |
| |
}} |
|
}} |
| − |
To use the Vim completion you can use a dictionary. |
+ |
To use the Vim completion a user can use a dictionary like so: |
| |
<pre> |
|
<pre> |
| |
:set complete=k |
|
:set complete=k |
| |
</pre> |
|
</pre> |
| |
|
|
|
| − |
As a dictionary you can use a syntax file (which are in the /syntax/ directory), so you can complete the reserved words. |
+ |
With a dictionary the user can use a syntax file (which are commonly stored in the /syntax/ directory), so that the user can complete reserved words for a particular language. If the user would like to automatically load a syntax file from the /syntax/ directory for the particular filetype they are working on, the following line can be inserted into the .vimrc file: |
| − |
|
|
| − |
Inserting in your [[vimrc]] a line like this: |
|
| |
<pre> |
|
<pre> |
| − |
autocmd Syntax * exec('set dict=/usr/share/vim/syntax/' .expand('<amatch>') .'.vim') |
+ |
au FileType * exe('setl dict+='.$VIMRUNTIME.'/syntax/'.&filetype.'.vim') |
| |
</pre> |
|
</pre> |
| |
|
|
|
| − |
you can avoid to select the dictionary for each filetype. |
+ |
==See Also== |
| − |
|
|
| − |
Don't forget to use your correct syntax directory for this. |
|
| − |
|
|
| − |
==References== |
|
| |
*{{help|:autocmd}} |
|
*{{help|:autocmd}} |
| |
*{{help|complete}} |
|
*{{help|complete}} |
| |
|
|
|
| |
==Comments== |
|
==Comments== |
| − |
This is not working. I also tried to use my old dictionary file in the 'set dict=' statement for testing, no success. |
|
| − |
|
|
| − |
A 'set cpt=k/path/to/your/dictionary/file' is working |
|
| − |
|
|
| − |
---- |
|
| − |
It is working. The condition is that you have to do <tt>:syn on</tt> first on your vimrc. |
|
| − |
|
|
| − |
The map I hacked is |
|
| − |
|
|
| − |
<pre> |
|
| − |
syn on |
|
| − |
au Syntax * exe("set dict+=".$VIMRUNTIME."/syntax/".expand('<amatch>').".vim") |
|
| − |
</pre> |
|
| − |
|
|
| − |
---- |
|
| − |
> How to make it work without "syn on" first? |
|
| − |
|
|
| − |
If you are using filetype detection (i.e., you have 'filetype on' or 'filetype plugin on' in your .vimrc) you can use 'au FileType' in place of 'au Syntax'. Also, I would suggest using 'setlocal' in place of 'set' and using += in place of just =, so that the change is local to the current buffer and file is added to the existing 'dict' list instead of replacing it. |
|
| − |
autocmd FileType * exec('setlocal dict+=/usr/share/vim/syntax/' .expand('<amatch>') .'.vim') |
|
| − |
|
|
| − |
---- |
|
| − |
My final version in my .vimrc, for both PC and unix: |
|
| − |
autocmd FileType * exec('setlocal dict+='.$VIMRUNTIME.'/syntax/'.expand('<amatch>').'.vim') |
|
| − |
|
|
| − |
---- |
|
| − |
> autocmd FileType * exec('setlocal dict+='.$VIMRUNTIME.'/syntax/'.expand('<amatch>').'.vim') |
|
| − |
|
|
| − |
This works. I replaced $VIMRUNTIME with its value for testing and it stops working, so this was the problem. |
|
| − |
|
|
| − |
---- |
|
| − |
I've just started a general keyword completion file (not filetype dependent) |
|
| − |
set cpt=kc:/cygwin/home/davidr/vimfiles/dictionary.txt |
|
| − |
set cpt+=kc:/cygwin/home/davidr/vimfiles/syntax/cf.vim (couldn't get the auto stuff to work) |
|
| − |
|
|
| − |
---- |
|
| − |
On the PC I had to change the reference to $VIMRUNTIME to escape('$VIMRUNTIME',' ') |
|
| − |
to get this to work. My vim path had spaces in, so I needed to escape both space and backslash |
|
| − |
characters. |
|
| − |
|
|
| − |
---- |
|
| − |
If the above example doesn't work for you (as it didn't for me) try this |
|
| − |
autocmd FileType * exe "setlocal dict+=".escape($VIMRUNTIME.'\syntax' .&filetype.'.vim',' \$,') |
|
| − |
|
|
| − |
Requires that you are using filetypes. |
|
| − |
|
|
| − |
---- |
|
| − |
Thanks for inspiration of &filetype. Now, I have one-line version (72 chars) in my vimrc: |
|
| − |
au FileType * exe('setl dict+='.$VIMRUNTIME.'/syntax/'.&filetype.'.vim') |
|
| − |
|
|
| − |
I tested it and it worked for me on W2K, cygwin console, and Unix. (I tested by checking :set dict?) |
|
| − |
|
|
| − |
---- |
|
| − |
The problem is not files are not exhaustive, it's just their lines are too long to be parsed by the dictionary parser which is limited to 511 char per line. |
|
| − |
I had this problem with the php language file and had to split the lines. To do it, I used this replacement patern you'll have to adapt for other language, beware that ^M are obtained by typing <C-V> then return and ^I by typing the tab key. |
|
| − |
:s/^\(syn keyword\tphpFunctions\t.\{460,490\}\) \(.*\)$/\1contained^Msyn keywords^IphpFunctions^I\2/g |
|
| − |
|
|
| − |
---- |
|
To use the Vim completion a user can use a dictionary like so:
:set complete=k
With a dictionary the user can use a syntax file (which are commonly stored in the /syntax/ directory), so that the user can complete reserved words for a particular language. If the user would like to automatically load a syntax file from the /syntax/ directory for the particular filetype they are working on, the following line can be inserted into the .vimrc file:
au FileType * exe('setl dict+='.$VIMRUNTIME.'/syntax/'.&filetype.'.vim')