Vim Tips Wiki
(Change to TipImported template + severe manual clean)
(da link)
 
(6 intermediate revisions by 3 users not shown)
Line 2: Line 2:
 
{{TipImported
 
{{TipImported
 
|id=766
 
|id=766
|previous=765
+
|previous=763
 
|next=767
 
|next=767
|created=July 26, 2004
+
|created=2004
 
|complexity=intermediate
 
|complexity=intermediate
 
|author=Levin Du
 
|author=Levin Du
 
|version=6.0
 
|version=6.0
 
|rating=9/6
 
|rating=9/6
  +
|category1=Completion
  +
|category2=
 
}}
 
}}
 
I often come across lines like these:
 
I often come across lines like these:
   
 
<pre>
 
<pre>
p_ST-&gt;localconnectionOption-&gt;typeofService = 0;
+
p_ST->localconnectionOption->typeofService = 0;
p_ST-&gt;localconnectionOption-&gt;gain = 0;
+
p_ST->localconnectionOption->gain = 0;
p_ST-&gt;localconnectionOption-&gt;r_reservation = 0
+
p_ST->localconnectionOption->r_reservation = 0
p_ST-&gt;localconnectionOption-&gt;r_re
+
p_ST->localconnectionOption->r_re
 
</pre>
 
</pre>
   
Though Vim has completion mode, it's a wasting time of repeately typing 'p_ST-&gt;local&lt;C-N&gt;-&gt;...'. So I write this mapping:
+
Though Vim has completion mode, it's a wasting time of repeately typing 'p_ST->local<C-N>->...'. So I write this mapping:
   
 
<pre>
 
<pre>
:inoremap &lt;c-f&gt; &lt;ESC&gt;:let g:saved_col=virtcol(".")&lt;CR&gt;ddkYp:exe "normal ".(g:saved_col+1)."\|"&lt;CR&gt;C
+
:inoremap <c-f> <Esc>:let g:saved_col=virtcol(".")<CR>ddkYp:exe "normal ".(g:saved_col+1)."\|"<CR>C
 
</pre>
 
</pre>
   
Line 28: Line 30:
   
 
<pre>
 
<pre>
p_ST-&gt;localconnectionOption-&gt;typeofService = 0;
+
p_ST->localconnectionOption->typeofService = 0;
 
|
 
|
 
</pre>
 
</pre>
   
then I use &lt;Tab&gt; and &lt;Space&gt; to move the cursor to the right place:
+
then I use <Tab> and <Space> to move the cursor to the right place:
   
 
<pre>
 
<pre>
p_ST-&gt;localconnectionOption-&gt;typeofService = 0;
+
p_ST->localconnectionOption->typeofService = 0;
 
|
 
|
 
</pre>
 
</pre>
   
and press &lt;Ctrl&gt;-f, can you see the magic? It turns out to:
+
and press <Ctrl>-f, can you see the magic? It turns out to:
   
 
<pre>
 
<pre>
p_ST-&gt;localconnectionOption-&gt;typeofService = 0;
+
p_ST->localconnectionOption->typeofService = 0;
p_ST-&gt;localconnectionOption-&gt;|
+
p_ST->localconnectionOption->|
 
</pre>
 
</pre>
   
Line 50: Line 52:
   
 
<pre>
 
<pre>
ino &lt;silent&gt; &lt;c-f&gt; &lt;c-o&gt;:exe "norm! kly0jPD"&lt;cr&gt;
+
ino <silent> <c-f> <c-o>:exe "norm! kly0jPD"<CR>
 
</pre>
 
</pre>
   
 
----
 
----
I want to recommend &lt;C-X&gt;&lt;C-L&gt; - line completion. Not exactly the same as this, but useful in similar situations. After a line completion, you can use &lt;C-P&gt; and &lt;C-N&gt; as usual for previous and next match.
+
I want to recommend <C-X><C-L> - line completion. Not exactly the same as this, but useful in similar situations. After a line completion, you can use <C-P> and <C-N> as usual for previous and next match.
   
 
See {{help|ins-completion}}.
 
See {{help|ins-completion}}.
   
 
----
 
----
What about &lt;C-X&gt;&lt;C-N&gt;? I just discovered this recently as something between "whole-line completion" &lt;C-X&gt;&lt;C-L&gt; and "word completion" &lt;C-N&gt;. It works like &lt;C-N&gt; completion, but it's more like "complete more".
+
What about <C-X><C-N>? I just discovered this recently as something between "whole-line completion" <C-X><C-L> and "word completion" <C-N>. It works like <C-N> completion, but it's more like "complete more".
   
 
So from the previous example:
 
So from the previous example:
p_ST-&gt;localconnectionOption-&gt;typeofService = 0;
+
p_ST->localconnectionOption->typeofService = 0;
 
type:
 
type:
p_&lt;C-N&gt;
+
p_<C-N>
 
you get:
 
you get:
 
p_ST
 
p_ST
 
type:
 
type:
&lt;C-X&gt;&lt;C-N&gt;
+
<C-X><C-N>
 
you get:
 
you get:
p_ST-&gt;localconnectionOption
+
p_ST->localconnectionOption
 
type:
 
type:
&lt;C-X&gt;&lt;C-N&gt;
+
<C-X><C-N>
 
you get:
 
you get:
p_ST-&gt;localconnectionOption-&gt;typeofService
+
p_ST->localconnectionOption->typeofService
   
 
No spacing/tabbing and scripting necessary!
 
No spacing/tabbing and scripting necessary!
   
 
----
 
----
  +
  +
It is worth to mention CTRL-y (and CTRL-e) and the wordwise CTRL-y tip on this occasion - http://vim.wikia.com/wiki/Wordwise_Ctrl-Y_in_insert_mode.

Latest revision as of 11:02, 20 April 2012

Tip 766 Printable Monobook Previous Next

created 2004 · complexity intermediate · author Levin Du · version 6.0


I often come across lines like these:

p_ST->localconnectionOption->typeofService = 0;
p_ST->localconnectionOption->gain = 0;
p_ST->localconnectionOption->r_reservation = 0
p_ST->localconnectionOption->r_re

Though Vim has completion mode, it's a wasting time of repeately typing 'p_ST->local<C-N>->...'. So I write this mapping:

:inoremap <c-f> <Esc>:let g:saved_col=virtcol(".")<CR>ddkYp:exe "normal ".(g:saved_col+1)."\|"<CR>C

Take above lines for example. First, I type one line (with autoindent turn on, the cursor position is shown as "|" after finishing the line with Return):

p_ST->localconnectionOption->typeofService = 0;
|

then I use <Tab> and <Space> to move the cursor to the right place:

p_ST->localconnectionOption->typeofService = 0;
                                                   |

and press <Ctrl>-f, can you see the magic? It turns out to:

p_ST->localconnectionOption->typeofService = 0;
p_ST->localconnectionOption->|

Comments[]

Here's an alternative mapping.

ino <silent> <c-f> <c-o>:exe "norm! kly0jPD"<CR>

I want to recommend <C-X><C-L> - line completion. Not exactly the same as this, but useful in similar situations. After a line completion, you can use <C-P> and <C-N> as usual for previous and next match.

See :help ins-completion.


What about <C-X><C-N>? I just discovered this recently as something between "whole-line completion" <C-X><C-L> and "word completion" <C-N>. It works like <C-N> completion, but it's more like "complete more".

So from the previous example:

p_ST->localconnectionOption->typeofService = 0;

type:

p_<C-N>

you get:

p_ST

type:

<C-X><C-N>

you get:

p_ST->localconnectionOption

type:

<C-X><C-N>

you get:

p_ST->localconnectionOption->typeofService

No spacing/tabbing and scripting necessary!


It is worth to mention CTRL-y (and CTRL-e) and the wordwise CTRL-y tip on this occasion - http://vim.wikia.com/wiki/Wordwise_Ctrl-Y_in_insert_mode.