Complete the vim Dictionary (automatically completed)

Source: Internet
Author: User
Vim can be automatically completed based on the dictionary of the user's meaning. 1) dictionary: Vim uses a series of words in a text file. If it is written in the same line, vim will automatically split according to the delimiter in iskeyword. If some special characters are required during full-time completion, such as entering PR, printf will appear after completion. (, you not only need to add printf. (, you also need to set the symbol in iskeyword. and symbol (add, the method is to add set iskeyword + =. To the vimrc file ., (2) Use: After compiling the dictionary, add such a line of code to the vimrc file (change the path to the path of the dictionary file) set dictionary-= $ Vim/dic.txt dictionary + = $ Vim/dic.txt enter a part of the word in input mode, and then press <Ctrl-x> <Ctrl-k>, the auto-completion option is displayed. If there are multiple options, you can use ctrl-N and Ctrl-P to select 3) shortcut key: if the <Ctrl-x> <Ctrl-k> combination key is too troublesome, you can add the dictionary Completion list directly to the default Completion list, in vimrc, add the following code set complete-= K Complete + = K. in input mode, enter a part of the word, press <Ctrl-N> to start auto-completion. If you are used to using the tab key to complete, here is a code for intelligent tab completion, which can be added to vimrc, it automatically selects the completion mode based on the context:
inoremap <tab> <c-r>=Smart_TabComplete()<CR>
function! Smart_TabComplete()  let line = getline('.')                         " current line  let substr = strpart(line, -1, col('.')+1)      " from the start of the current                                                  " line to one character right                                                  " of the cursor  let substr = matchstr(substr, "[^ \t]*$")       " word till cursor  if (strlen(substr)==0)                          " nothing to match on empty string    return "\<tab>"  endif  let has_period = match(substr, '\.') != -1      " position of period, if any  let has_slash = match(substr, '\/') != -1       " position of slash, if any  if (!has_period && !has_slash)    return "\<C-X>\<C-P>"                         " existing text matching  elseif ( has_slash )    return "\<C-X>\<C-F>"                         " file matching  else    return "\<C-X>\<C-O>"                         " plugin matching  endifendfunction

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.