Wikia

Vim Tips Wiki

Changes: Autocomplete with TAB when typing words

Edit

Back to page

(Move categories to tip template)
(Remove html character entities)
 
Line 17: Line 17:
   
 
"See help completion for source,
 
"See help completion for source,
"Note: usual completion is on <C-n> but more trouble to press all the time.
+
"Note: usual completion is on <C-n> but more trouble to press all the time.
 
"Never type the same word twice and maybe learn a new spellings!
 
"Never type the same word twice and maybe learn a new spellings!
 
"Use the Linux dictionary when spelling is in doubt.
 
"Use the Linux dictionary when spelling is in doubt.
 
"Window users can copy the file to their machine.
 
"Window users can copy the file to their machine.
 
function! Tab_Or_Complete()
 
function! Tab_Or_Complete()
if col('.')&gt;1 &amp;&amp; strpart( getline('.'), col('.')-2, 3 ) =~ '^\w'
+
if col('.')>1 && strpart( getline('.'), col('.')-2, 3 ) =~ '^\w'
return "\&lt;C-N&gt;"
+
return "\<C-N>"
 
else
 
else
return "\&lt;Tab&gt;"
+
return "\<Tab>"
 
endif
 
endif
 
endfunction
 
endfunction
:inoremap &lt;Tab&gt; &lt;C-R&gt;=Tab_Or_Complete()&lt;CR&gt;
+
:inoremap <Tab> <C-R>=Tab_Or_Complete()<CR>
 
:set dictionary="/usr/dict/words"
 
:set dictionary="/usr/dict/words"
 
</pre>
 
</pre>
Line 37: Line 37:
   
 
==Comments==
 
==Comments==
Even easier than &lt;Tab&gt; is to have words completed automatically. There are some drawbacks to this, but the {{script|id=73|text=word_complete.vim}} plugin works pretty well.
+
Even easier than <Tab> is to have words completed automatically. There are some drawbacks to this, but the {{script|id=73|text=word_complete.vim}} plugin works pretty well.
   
 
----
 
----

Latest revision as of 08:56, September 29, 2008

Tip 566 Printable Monobook Previous Next

created September 30, 2003 · complexity basic · author mohsin · version 6.0


"Use TAB to complete when typing words, else inserts TABs as usual.
"Uses dictionary and source files to find matching words to complete.

"See help completion for source,
"Note: usual completion is on <C-n> but more trouble to press all the time.
"Never type the same word twice and maybe learn a new spellings!
"Use the Linux dictionary when spelling is in doubt.
"Window users can copy the file to their machine.
function! Tab_Or_Complete()
  if col('.')>1 && strpart( getline('.'), col('.')-2, 3 ) =~ '^\w'
    return "\<C-N>"
  else
    return "\<Tab>"
  endif
endfunction
:inoremap <Tab> <C-R>=Tab_Or_Complete()<CR>
:set dictionary="/usr/dict/words"

ReferencesEdit

CommentsEdit

Even easier than <Tab> is to have words completed automatically. There are some drawbacks to this, but the word_complete.vim plugin works pretty well.


To use the dictionary, add 'k' to your ':set complete'. For language keywords (tags), also add ']'. See :help 'complete'.


Around Wikia's network

Random Wiki