On Mon, 14 May 2012, Dotan Cohen wrote:

On Sun, May 13, 2012 at 9:37 PM, Tim Chase wrote:
On 05/13/12 10:58, Dotan Cohen wrote:
I have a few of these wonderful helpers:
inoremap foreach<Return> foreach (<Space><Space>)<Return>{<Return><R
 eturn>}<Esc>3kA<Left><Left>

I know that there is a snippets plugin, but I like this roll-my-own solution for a number of reasons (one of which is to learn Vim). However, one problem that I have is that the text f-o-r-e-a-c-h is not shown until I get to the end of the map. Is there any way to configure VIM to show the text normally, until it decides that there will be a replacement? This is driving me crazy.

You might try it with an abbreviation instead:

:iab foreach foreach(<space>)<cr>{<cr><cr>}<up><up><up><end><left><left>

which allows you to see it as you type it (also expands on <space> which I prefer over <enter>).
[...]

Thanks, Tim. I did not know about iab, thank you. There are a few caveats:

[...]

2) The iab abbreviations add a space after the mapping, which is precludes many combinations such as if I want to leave the cursor between two parentheses.

See the Eatchar function in the help for map.txt:
:help map.txt | /Eatchar

I use the following variant of Eatchar (since '\s' is the common case):

fun! Eatchar(...)
    let c = nr2char(getchar(0))
    return c =~ (a:0 ? a:1 : '\s') ? '' : c
endf

Then, in the example Tim provided above, the iab becomes:

:iab foreach 
foreach(<space>)<cr>{<cr><cr>}<up><up><up><end><left><left><C-R>=Eatchar()<CR>


3) The iab abbreviations will not work in the general case for remapping handy things which do not end in a space, such as these:
inoremap ii <Esc>
inoremap kk <Esc>A
"Go back to between the last {} [] <> () "" '' or ><
inoremap hh 
<c-o>?\%<c-r>=line('.')<Return>l\({}\\|\[]\\|<>\\|><\\|()\\|""\\|''\\|
  ><lt>\)?s+1<Return>
inoremap ;; <Esc>A;<Return>
"For adding another method argument while inside quotes
inoremap ,, <Right>,<Space>
"For adding => while inside quotes (PHP associative arrays)
inoremap ,,j <Right><Space>=><Space>

In all these cases the user is stuck watching a cursor that does not move according to his typing.

I know the reasons behind not showing the text (the text might never be entered into the buffer). However, the feedback of seeing the text, even if it is not intended for being added to the buffer, is very important.

Trying these mappings, I see the first letter of the mapping appear under the cursor (though the cursor doesn't move until the next key is typed). Is it really that disconcerting? (Typing a normal word at normal speed, it doesn't seem that noticeable to me.)


In any case, by far _most_ of the leading characters are used outside the mappings, so it is the common case that is being made annoying for the sake of the uncommon case. If need be, I would prefer that the text be added to the buffer and then removed if it matches a map.

I could be wrong, but I don't think mapping things that start with letters in insert mode is the common case. (Though, that might be because of the issue we're discussing.) My personal preference is to not map anything in insert mode at all, except via abbreviations. And a lot of people seem to prefer <F#> keys.


Is there any way to accomplish this?

Not as far as I know.

--
Best,
Ben

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to