Questions tagged [autocompletion]

For questions about the several commands to complete part of a keyword or line that has been typed.

In and , there are several commands to complete part of a keyword or line that has been typed. This is useful if you are using complicated keywords (e.g., function names with capitals and underscores).

Completion can be done for:

  1. whole lines |i_CTRL-X_CTRL-L|
  2. keywords in the current file |i_CTRL-X_CTRL-N|
  3. keywords in |i_CTRL-X_CTRL-K|
  4. keywords in , thesaurus-style |i_CTRL-X_CTRL-T|
  5. keywords in the current and included files |i_CTRL-X_CTRL-I|
  6. |i_CTRL-X_CTRL-]|
  7. file names |i_CTRL-X_CTRL-F|
  8. definitions or s |i_CTRL-X_CTRL-D|
  9. Vim |i_CTRL-X_CTRL-V|
  10. user defined completion |i_CTRL-X_CTRL-U|
  11. omni completion |i_CTRL-X_CTRL-O|
  12. suggestions |i_CTRL-X_s|
  13. keywords in 'complete' |i_CTRL-N|

All these (except 2) are done in CTRL-X mode. This is a sub-mode of Insert and Replace modes. You enter CTRL-X mode by typing CTRL-X and one of the CTRL-X commands. You exit CTRL-X mode by typing a key that is not a valid CTRL-X mode command. Valid keys are the CTRL-X command itself, CTRL-N (next), and CTRL-P (previous).

When completion is active you can use CTRL-E to stop it and go back to the originally typed text. The CTRL-E will not be inserted.

When the popup menu is displayed you can use CTRL-Y to stop completion and accept the currently selected entry. The CTRL-Y is not inserted. Typing a space, Enter, or some other unprintable character will leave completion mode and insert that typed character.

Full documentation: vimdoc ins-completion

357 questions
31
votes
3 answers

How to create my own autocomplete function?

How do I create my own list of auto-completion for certain filetypes? For example I would like css and html to autocomplete from the list of css classes in FontAwesome.
firedev
  • 2,392
  • 2
  • 19
  • 31
30
votes
7 answers

How can I get Vim to show documentation of a C/C++ function?

Most editors have a feature like when you press some keys by placing caret over a function, it pops the documentation of that function along with number and type of arguments that function takes. I was wondering whether Vim offers such support. For…
sherelock
  • 401
  • 1
  • 4
  • 3
19
votes
1 answer

Ctrl-n completion takes a long time for “scanning included file”

I'm brushing up on my vim skills and fiddling with completion using the Ctrl-n command. I'm programming in Perl. When I am in insert mode and hit Ctrl-n, I get a message that it is "Scanning included file" down at the bottom of the terminal and it…
StevieD
  • 1,492
  • 1
  • 16
  • 24
16
votes
1 answer

How do I exclude certain file extensions from completion?

Is there a way to configure vim regarding what file types it considers "suitable" for opening? Let me clarify by an example. Imagine you are working on a latex document. Once you build your file, you have the following in your directory (along with…
Shahbaz
  • 549
  • 3
  • 14
13
votes
1 answer

Vim filename/path completion

I know I can complete filenames/paths from the current directory using Ctrl+X, Ctrl+F (compl-filename). That works great in combination with set autochdir, which changes the current directory to the directory of the active buffer. However, I started…
Rafael Barbosa
  • 233
  • 2
  • 5
13
votes
1 answer

Dynamic completion

I'm trying to enhance an old completion function. I'd like it to update the choices displayed in the popup menu as I type new characters My completion function is function! lh#icomplete#ecm(findstart, base) abort if a:findstart let l =…
Luc Hermitte
  • 17,351
  • 1
  • 33
  • 49
12
votes
1 answer

Ins-completion of WORDs

and allow the completion of words found within the current document. I am taking some notes and writing say {0,1}^n and (E,D) many times. These are WORDs constituted by several words. Is there a way to complete WORDs with and
Gonçalo Ribeiro
  • 1,991
  • 1
  • 18
  • 28
12
votes
1 answer

cancel complete

Usually insert mode completion () inserts the right word the first time I press , but not always. Therefore, I would like Vim to insert the match it deems best when I press , but still allow me to cancel this insertion afterwards…
Octaviour
  • 962
  • 6
  • 18
11
votes
2 answers

How can Vim help me remember the trailing commas in BibTeX files?

I edit quite a few BibTeX files, and I regularly forget the trailing commas: For example: @Book{cooke2015british, author = {Cooke, Lez}, title = {British Television Drama}, publisher = {Palgrave on behalf of the British Film Institute}, year =…
10
votes
2 answers

How to select a matched autocompletion item

I want to select the 6th item (here readImage) in the auto-completion items. The normal way i knew is pressing ctrln for 6 times until the matched word is selected and then press enter. I tried different solutions: With the mouse: :set mouse=a…
showkey
  • 1,130
  • 2
  • 11
  • 30
9
votes
1 answer

Smart word completion when in the middle of a word

Consider a file with the following two lines: someLongFunction someFunction When I am in the insert mode in the middle of the second word some|Function and I press Ctrl-n, I get someLongFunctionFunction Is there a way of configuring Vim so that I…
s3rvac
  • 549
  • 3
  • 10
8
votes
1 answer

File name completion relative to currently edited file

If I open a file that isn't in the current directly, when I used Vim to autocomplete a filename, Vim provides files relative to the location where I launched Vim, not the currently edited file. Example $ find . nice-file.xml xml/ …
Scribblemacher
  • 319
  • 3
  • 11
8
votes
2 answers

How to Autocomplete CSS class names that include a minus character?

I'm having the following CSS class structure .mAIcon .mAIcon-reject .mAIcon-edit .mAIcon-accept .event and so on. Inside my HTML files I want to autocomplete these class names. But when I type and I want to autocomplete…
Raphael Ahrens
  • 502
  • 3
  • 13
8
votes
1 answer

Filename Completion with Spaces

I have a lot of files that have spaces in their names, and this is giving me problems. If I try to do command line completion for the find command, and one of these files come up, Vim will find it, but it won't load because the spaces aren't…
A Gold Man
  • 221
  • 1
  • 6
6
votes
2 answers

Line completion disregarding line prefix

In Vim, C-x C-l performs line completion. However, it expects the prefix of the currently typed line to match the prefix of another line. For example, consider that | below denotes the cursor position: ; A sentence I would like to auto…
s3rvac
  • 549
  • 3
  • 10
1
2 3 4 5 6 7