Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The above way is "kind of" working, but it's so unreadable that almost nobody could say what it actually does. <strong>The solution above is not good.</strong></p> <p><strong>Short Answer - Use this:</strong></p> <pre><code>function! Auto_complete_string() if pumvisible() return "\&lt;C-n&gt;" else return "\&lt;C-x&gt;\&lt;C-o&gt;\&lt;C-r&gt;=Auto_complete_opened()\&lt;CR&gt;" end endfunction function! Auto_complete_opened() if pumvisible() return "\&lt;Down&gt;" end return "" endfunction inoremap &lt;expr&gt; &lt;Nul&gt; Auto_complete_string() inoremap &lt;expr&gt; &lt;C-Space&gt; Auto_complete_string() </code></pre> <p>This answer also respects that there are two possible values (depending on terminal/gvim usage) for Ctrl+Space: <code>&lt;C-Space&gt;</code> and <code>&lt;Nul&gt;</code>. </p> <p>I use a similar approach as the first one in <a href="http://github.com/davidhalter/jedi-vim" rel="nofollow">jedi-vim</a>, but more customizable. </p> <hr> <p><strong>Long Answer - What the above does:</strong></p> <p>The whole escaping of the above answer is so confusing, that I've split the above answer into a readable format: </p> <pre><code>function! Auto_complete_string() if pumvisible() return "\&lt;C-n&gt;" else return "\&lt;C-x&gt;\&lt;C-o&gt;\&lt;C-r&gt;=Auto_complete_opened()\&lt;CR&gt;" end endfunction function! Auto_complete_opened() if pumvisible() return "\&lt;c-n&gt;\&lt;c-p&gt;\&lt;c-n&gt;" else return "\&lt;bs&gt;\&lt;C-n&gt;" end endfunction inoremap &lt;expr&gt; &lt;Nul&gt; Auto_complete_string() </code></pre> <p>This clearly shows what it is doing. There's some weird stuff happening in <code>Auto_complete_opened</code>. It's not just doing completion, it's doing two additional things after trying to complete:</p> <ul> <li>When trying to use the omnicompletion, it somehow does a <code>&lt;C-n&gt;&lt;C-p&gt;&lt;C-n&gt;</code>, which could IMHO just be abbreviated to <code>&lt;C-n&gt;</code>.</li> <li>In case completion is unsuccessful, it uses a backspace and does a completion again, not <code>&lt;C-o&gt;&lt;C-x&gt;</code> but <code>&lt;C-n&gt;</code>, which just doesn't make a lot of sense.</li> </ul> <p>I'm not saying that this is not what some user might want, but it's probably not what most users want! My short answer takes that in credit and gives you a simple way to edit it. You can now just easily change things if you want to (for example <code>&lt;Down&gt;</code> to <code>&lt;C-n&gt;</code>, if you want the first entry to be written from the beginning on).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload