(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= |
+ | |previous=763 |
|next=767 |
|next=767 |
||
− | |created= |
+ | |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- |
+ | p_ST->localconnectionOption->typeofService = 0; |
− | p_ST- |
+ | p_ST->localconnectionOption->gain = 0; |
− | p_ST- |
+ | p_ST->localconnectionOption->r_reservation = 0 |
− | p_ST- |
+ | p_ST->localconnectionOption->r_re |
</pre> |
</pre> |
||
− | Though Vim has completion mode, it's a wasting time of repeately typing 'p_ST- |
+ | 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 |
+ | :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- |
+ | p_ST->localconnectionOption->typeofService = 0; |
| |
| |
||
</pre> |
</pre> |
||
− | then I use |
+ | then I use <Tab> and <Space> to move the cursor to the right place: |
<pre> |
<pre> |
||
− | p_ST- |
+ | p_ST->localconnectionOption->typeofService = 0; |
| |
| |
||
</pre> |
</pre> |
||
− | and press |
+ | and press <Ctrl>-f, can you see the magic? It turns out to: |
<pre> |
<pre> |
||
− | p_ST- |
+ | p_ST->localconnectionOption->typeofService = 0; |
− | p_ST- |
+ | p_ST->localconnectionOption->| |
</pre> |
</pre> |
||
Line 50: | Line 52: | ||
<pre> |
<pre> |
||
− | ino |
+ | ino <silent> <c-f> <c-o>:exe "norm! kly0jPD"<CR> |
</pre> |
</pre> |
||
---- |
---- |
||
− | I want to recommend |
+ | 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 |
+ | 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- |
+ | p_ST->localconnectionOption->typeofService = 0; |
type: |
type: |
||
− | p_ |
+ | p_<C-N> |
you get: |
you get: |
||
p_ST |
p_ST |
||
type: |
type: |
||
− | + | <C-X><C-N> |
|
you get: |
you get: |
||
− | p_ST- |
+ | p_ST->localconnectionOption |
type: |
type: |
||
− | + | <C-X><C-N> |
|
you get: |
you get: |
||
− | p_ST- |
+ | 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
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.