Re: How do I stop a mapping from looking like a mapping?
On 7/13/06, Peter Hodge [EMAIL PROTECTED] wrote: However, if I type anything beginning with 'for', the letters disappear until I type something that is not part of the mapping. I understand this is the standard behaviour, but is there any way to change it so I can see what I am typing? Although there is no stardard option for imap to do this (make incompete mapping visible; yes I'd find it seful, too), I found a weird trick that does what you want. Does the following do what you want: - :imap h c-r=PrecedingChars(6) !=# 'foreac' ? 'h' : ExpandForeach() cr function! ExpandForeach() expansion of the foreach mapping nb: 'foreac' is already there. So we don't need to repeat it return h() {\n}\Left endfunction function! PrecedingChars(n) return n chars preceding cursor in rhs of :imap mapping return getline('.')[col('.')-1-a:n : col('.')-2] endfunction --- Explanation: this remaps 'h' character to check 6 preceding chars. If 6 preceding chars are 'foreac', then it is expanded into your you foreach-template. Otherwise, literas 'h' is inserted. Since this is 1-char-length mapping, there's no delay and no invisibilities. If you wonder where is expansion (rhs) of your template, it's inside function ExpandForeach(). The function PrecedingChars() is generic and doesn't change when you change rhs of your template. 2. If you find this too complex, and you don't want to press space or tab after 'foreach' (supposedly because it makes 8 chars instead of 7?) , then can I suggest either this simple weirdity: :iab foreac foreach ... (In which case, you get to type 'foreac' then space, which makes total 7 characters not 8.), or this mapping :imap ctrl-Zf foreach which is economy of 5 chars on the lhs side. (You type ctrl-z then f) Yakov
Re: How do I stop a mapping from looking like a mapping?
I'm even to lazy to type foreach. Thus I've defined mappings like this: inoremap buffer m-fm-e foreachspace... Makes total of 2 keys+ meta key. ;) with this mapping opens the ftp plugin file with _mw appended map m-s-fm-s-tm-s-p :exec 'e ~/.vim/ftplugin/'.filetype.'_mw.vim'cr and inswerts the inoremap beginning .. imap buffer m-im-m inoremapspacebufferspace you can add additional mappings very quickly Marc
Re: How do I stop a mapping from looking like a mapping?
On 7/13/06, Yakov Lerner [EMAIL PROTECTED] wrote: :imap ctrl-Zf foreach Correction. I wanted to write: :imap c-Zf foreach Yakov
Re: How do I stop a mapping from looking like a mapping?
On Thu, 13 Jul 2006 at 9:21am, Yakov Lerner wrote: On 7/13/06, Peter Hodge [EMAIL PROTECTED] wrote: However, if I type anything beginning with 'for', the letters disappear until I type something that is not part of the mapping. I understand this is the standard behaviour, but is there any way to change it so I can see what I am typing? Although there is no stardard option for imap to do this (make incompete mapping visible; yes I'd find it seful, too), I found a weird trick that does what you want. Does the following do what you want: - :imap h c-r=PrecedingChars(6) !=# 'foreac' ? 'h' : ExpandForeach() cr function! ExpandForeach() expansion of the foreach mapping nb: 'foreac' is already there. So we don't need to repeat it return h() {\n}\Left endfunction function! PrecedingChars(n) return n chars preceding cursor in rhs of :imap mapping return getline('.')[col('.')-1-a:n : col('.')-2] endfunction --- Very clever alternative to iab. You can take advantage of the new expr maps to simplify and generalize this as below (note, I changed the mapping to not remap): :inoremap expr h CheckExpand('foreac', 'h', h() {\n}\Left) expansion of the foreach mapping function! CheckExpand(precChars, curChar, expansion) if PrecedingChars(strlen(a:precChars)) ==# a:precChars nb: precChar is already there. So we don't need to repeat it return a:expansion else return a:curChar endif endfunction function! PrecedingChars(n) return n chars preceding cursor in rhs of :imap mapping return getline('.')[col('.')-1-a:n : col('.')-2] endfunction This method also allows you to do very detailed conditional checks to decide if the expansion should be made or not (to check if you are inside a comment using the current syntax group, e.g.). -- HTH, Hari Explanation: this remaps 'h' character to check 6 preceding chars. If 6 preceding chars are 'foreac', then it is expanded into your you foreach-template. Otherwise, literas 'h' is inserted. Since this is 1-char-length mapping, there's no delay and no invisibilities. If you wonder where is expansion (rhs) of your template, it's inside function ExpandForeach(). The function PrecedingChars() is generic and doesn't change when you change rhs of your template. 2. If you find this too complex, and you don't want to press space or tab after 'foreach' (supposedly because it makes 8 chars instead of 7?) , then can I suggest either this simple weirdity: :iab foreac foreach ... (In which case, you get to type 'foreac' then space, which makes total 7 characters not 8.), or this mapping :imap ctrl-Zf foreach which is economy of 5 chars on the lhs side. (You type ctrl-z then f) Yakov __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
Re: How do I stop a mapping from looking like a mapping?
On 7/13/06, Hari Krishna Dara [EMAIL PROTECTED] wrote: On Thu, 13 Jul 2006 at 9:21am, Yakov Lerner wrote: On 7/13/06, Peter Hodge [EMAIL PROTECTED] wrote: However, if I type anything beginning with 'for', the letters disappear until I type something that is not part of the mapping. I understand this is the standard behaviour, but is there any way to change it so I can see what I am typing? Although there is no stardard option for imap to do this (make incompete mapping visible; yes I'd find it seful, too), I found a weird trick that does what you want. Does the following do what you want: - :imap h c-r=PrecedingChars(6) !=# 'foreac' ? 'h' : ExpandForeach() cr function! ExpandForeach() expansion of the foreach mapping nb: 'foreac' is already there. So we don't need to repeat it return h() {\n}\Left endfunction function! PrecedingChars(n) return n chars preceding cursor in rhs of :imap mapping return getline('.')[col('.')-1-a:n : col('.')-2] endfunction --- Very clever alternative to iab. You can take advantage of the new expr maps to simplify and generalize this as below (note, I changed the mapping to not remap): :inoremap expr h CheckExpand('foreac', 'h', h() {\n}\Left) expansion of the foreach mapping function! CheckExpand(precChars, curChar, expansion) if PrecedingChars(strlen(a:precChars)) ==# a:precChars nb: precChar is already there. So we don't need to repeat it return a:expansion else return a:curChar endif endfunction function! PrecedingChars(n) return n chars preceding cursor in rhs of :imap mapping return getline('.')[col('.')-1-a:n : col('.')-2] endfunction Nice generalization, yes. Yakov
Re: How do I stop a mapping from looking like a mapping?
Hi Hari, Yakov, Thank you very much for your help! Yakov, thank you for an effective solution, Hari thank you for providing such a flexible way to use it! kind regards, Peter On Yahoo!7 Dating: It's free to join and check out our great singles! http://www.yahoo7.com.au/personals
How do I stop a mapping from looking like a mapping?
Hello all, I want to make a mapping like this: :inoremap foreach foreach() {CR}ESCk$3hi The end result being that when I type: foreach I should get foreach() { } However, if I type anything beginning with 'for', the letters disappear until I type something that is not part of the mapping. I understand this is the standard behaviour, but is there any way to change it so I can see what I am typing? regards, Peter === Fluent in more than 100 programming languages; Astoundingly fast; Works without complaint when given hardware from the medieval era; VIM makes up for all my shortcomings. Do you Yahoo!? Check out gigs in your area on the comprehensive Yahoo! Music Gig Guide http://au.music.yahoo.com/gig-guide
Re: How do I stop a mapping from looking like a mapping?
I want to make a mapping like this: :inoremap foreach foreach() {CR}ESCk$3hi The end result being that when I type: foreach I should get foreach() { } Sounds more like you're reaching for an abbreviation rather than a mapping. :iab foreach foreach() {^M}^[O where ^M is control+V followed by the enter key, and the ^[ is control+V followed by the esc key (and that's an oh, not a zero. If you don't want a fresh blank line, on which to start, you can change the O to an I (that's capital oh to capital eye in the event fonts are ambiguous on your end of things) With this mapping, you can type foreach followed by space or tab and it will automatically insert the code as you describe. It shouldn't have the same hidden/pause behavior that is rightfully annoying you. :) For more info, you can read about abbreviations (why is that such a long word...you can learn more about abrvs...) in the help under :help :ab (the short paragraph above this landing spot might also be helpful to include in your reading) HTH, -tim
Re: How do I stop a mapping from looking like a mapping?
--- Tim Chase [EMAIL PROTECTED] wrote: I want to make a mapping like this: :inoremap foreach foreach() {CR}ESCk$3hi The end result being that when I type: foreach I should get foreach() { } Sounds more like you're reaching for an abbreviation rather than a mapping. I don't want to have to press space or tab after 'foreach'. regards, Peter Send instant messages to your online friends http://au.messenger.yahoo.com