Thread: [Vim-latex-devel] Advice on a mapping
Brought to you by:
srinathava,
tmaas
From: Julien C. <jul...@gm...> - 2009-01-09 13:03:31
|
Dear all, Based on Mike and Ted's examples, I'm trying my first "slightly intricate" (for me) mapping: I want a mapping to replace selected existing "(expression)" and "[expression]" in math mode by "\left(expression\right)" and "`\left[expression\right]", respecitvely. So far, I've come to the follownig visualmode macro, which, once I've selected an inner block with, say, vib, adds the \left and \right. I feel it is unelegant (not robust, not multiline, ugly <C-O>, etc etc), but I can't figure a nicer way with my limited vim knowledge... vmap jus "zdi\right<C-O>2b\left<C-O>p<Esc> Any feedback appreciated ! (no emergency, though) Thanks :) Julien |
From: Julien C. <jul...@gm...> - 2009-01-09 13:05:46
|
Correction : vmap jus "zdi\right<C-O>2b\left<C-O>"zp<Esc> (forgot to call register z before pasting) Julien On Fri, Jan 9, 2009 at 2:00 PM, Julien Cornebise <jul...@gm...> wrote: > Dear all, > > Based on Mike and Ted's examples, I'm trying my first "slightly > intricate" (for me) mapping: I want a mapping to replace selected > existing "(expression)" and "[expression]" in math mode by > "\left(expression\right)" and "`\left[expression\right]", > respecitvely. > > So far, I've come to the follownig visualmode macro, which, once I've > selected an inner block with, say, vib, adds the \left and \right. I > feel it is unelegant (not robust, not multiline, ugly <C-O>, etc etc), > but I can't figure a nicer way with my limited vim knowledge... > > vmap jus "zdi\right<C-O>2b\left<C-O>p<Esc> > > Any feedback appreciated ! (no emergency, though) > Thanks :) > > Julien > |
From: Julien C. <jul...@gm...> - 2009-01-09 13:14:26
|
Most sorry for polluting the list. I guess I should try my macro deeper before sending. The final (?) version is : vmap jus "zdi\right<C-O>b<C-O>2h\left<C-O>"zp<Esc> (my move commands to reach the left parenthesis were bogus) Sorry again ! If anybody has a good ref to recommand on using Vim macros sanely, I'd be glad :) Julien On Fri, Jan 9, 2009 at 2:03 PM, Julien Cornebise <jul...@gm...> wrote: > Correction : > vmap jus "zdi\right<C-O>2b\left<C-O>"zp<Esc> > > (forgot to call register z before pasting) > > Julien > > On Fri, Jan 9, 2009 at 2:00 PM, Julien Cornebise > <jul...@gm...> wrote: >> Dear all, >> >> Based on Mike and Ted's examples, I'm trying my first "slightly >> intricate" (for me) mapping: I want a mapping to replace selected >> existing "(expression)" and "[expression]" in math mode by >> "\left(expression\right)" and "`\left[expression\right]", >> respecitvely. >> >> So far, I've come to the follownig visualmode macro, which, once I've >> selected an inner block with, say, vib, adds the \left and \right. I >> feel it is unelegant (not robust, not multiline, ugly <C-O>, etc etc), >> but I can't figure a nicer way with my limited vim knowledge... >> >> vmap jus "zdi\right<C-O>2b\left<C-O>p<Esc> >> >> Any feedback appreciated ! (no emergency, though) >> Thanks :) >> >> Julien >> > |
From: Ted P. <te...@te...> - 2009-01-09 14:47:08
|
> Based on Mike and Ted's examples, I'm trying my first "slightly > intricate" (for me) mapping: I want a mapping to replace selected > existing "(expression)" and "[expression]" in math mode by > "\left(expression\right)" and "`\left[expression\right]", > respecitvely. First, don't knock yourself out. First, checkout :help latex-suite Then, while editing a TeX file, type: (( You should find that suddenly a \left( \right)<++> appears and your cursor is in between the two of them. Type something and then hit Cntrl+J. Now your cursor has jumped to the <++> had has removed it. Similarly, try typing: [[ again, Cntrl+J to jump to the <++> placeholder. These are IMAP mappings. You can build more of them yourself, but the latex-suite includes lots of them. Within the mapping, things surrounded by <+ and +> serve as placeholders. So you can build templates with fields in them like <+name+>, <+date+>, etc., and then when you hit CNTRL+J, Vim will take you to the next field that needs to be filled in. --Ted -- Ted Pavlic <te...@te...> Please visit my ALS association page: http://web.alsa.org/goto/tedpavlic My family appreciates your support in the fight to defeat ALS. |
From: Julien C. <jul...@gm...> - 2009-01-09 16:05:12
|
> These are IMAP mappings. Thanks Ted, but I'm fully aware of the IMAP mappings :-) Sorry, I might not have been clear on the context : the latex file already exists, and is filled with unmatched parenthesis (my typographical choices -or lack of, thereof- were not always happy), some of them rightfully, other ... not. Hence I'm going through the formulae and changing the existing parentheses when needed. But where you're right is that I could maybe I can shorten my macro with these, leading to vmap jus ib"zdvab"_di((<Esc>"_2x"zP<C-j><Esc> directly applied in visual (i.e. used as vjus). Feels slightly cleaner. Only slightly. Anyway, that will do for what I have to do, I don't wan't to still more time. Thanks ! Julien |
From: Ted P. <te...@te...> - 2009-01-09 16:40:34
|
Ok. Well, if it were me, I would highlight the section with the offending (expressions) (perhaps by pressing "v" and then moving to the end of the section) and then issue :s/(\([^)]\+\))/\\left(\1\\right)/g (vim would automatically insert a '<,'> between the : and the s). You could even make a quick mapping that did that for you. That might be overkill (e.g., if you didn't want to fix *all* such expressions), but it would work for a single selected expression too. Additionally, if you weren't already aware, you can use % to jump from the top of a LaTeX block (e.g., \begin{equation}) to the bottom (\end{equation}) and back. That makes selecting large blocks quick. --Ted On 1/9/09 11:02 AM, Julien Cornebise wrote: >> These are IMAP mappings. > > Thanks Ted, but I'm fully aware of the IMAP mappings :-) > Sorry, I might not have been clear on the context : the latex file > already exists, and is filled with unmatched parenthesis (my > typographical choices -or lack of, thereof- were not always happy), > some of them rightfully, other ... not. > Hence I'm going through the formulae and changing the existing > parentheses when needed. > > But where you're right is that I could maybe I can shorten my macro > with these, leading to > > vmap jus ib"zdvab"_di((<Esc>"_2x"zP<C-j><Esc> > > directly applied in visual (i.e. used as vjus). Feels slightly > cleaner. Only slightly. > > Anyway, that will do for what I have to do, I don't wan't to still more time. > Thanks ! > > Julien > -- Ted Pavlic <te...@te...> Please visit my ALS association page: http://web.alsa.org/goto/tedpavlic My family appreciates your support in the fight to defeat ALS. |
From: Julien C. <jul...@gm...> - 2009-01-09 16:45:24
|
> :s/(\([^)]\+\))/\\left(\1\\right)/g > That might be overkill (e.g., if you didn't want to fix *all* such > expressions), but it would work for a single selected expression too. Thanks. Still, that would indeed fix *all* the expressions, even within the selection, not only the matched pair : No way to move from : ( a + ( b + c ) ) to \left( a + ( b + c ) \right) Anyway, I'm nit-picking here :-) Thanks > Additionally, if you weren't already aware, you can use % to jump from the > top of a LaTeX block (e.g., \begin{equation}) to the bottom (\end{equation}) > and back. That makes selecting large blocks quick. Thank you ! I didn't know that ! Julien > > --Ted > > On 1/9/09 11:02 AM, Julien Cornebise wrote: >>> >>> These are IMAP mappings. >> >> Thanks Ted, but I'm fully aware of the IMAP mappings :-) >> Sorry, I might not have been clear on the context : the latex file >> already exists, and is filled with unmatched parenthesis (my >> typographical choices -or lack of, thereof- were not always happy), >> some of them rightfully, other ... not. >> Hence I'm going through the formulae and changing the existing >> parentheses when needed. >> >> But where you're right is that I could maybe I can shorten my macro >> with these, leading to >> >> vmap jus ib"zdvab"_di((<Esc>"_2x"zP<C-j><Esc> >> >> directly applied in visual (i.e. used as vjus). Feels slightly >> cleaner. Only slightly. >> >> Anyway, that will do for what I have to do, I don't wan't to still more >> time. >> Thanks ! >> >> Julien >> > > -- > Ted Pavlic <te...@te...> > > Please visit my ALS association page: > http://web.alsa.org/goto/tedpavlic > My family appreciates your support in the fight to defeat ALS. > |
From: Ted P. <te...@te...> - 2009-01-09 16:45:10
|
> :s/(\([^)]\+\))/\\left(\1\\right)/g I suppose that wouldn't work if the (expression) had a line break in the middle of it... e.g., (expre ssion) Oh, well... Hopefully it was a useful example. --Ted -- Ted Pavlic <te...@te...> Please visit my ALS association page: http://web.alsa.org/goto/tedpavlic My family appreciates your support in the fight to defeat ALS. |
From: Julien C. <jul...@gm...> - 2009-01-09 16:50:19
|
>> :s/(\([^)]\+\))/\\left(\1\\right)/g > > I suppose that wouldn't work if the (expression) had a line break in the > middle of it... e.g., Yes indeed, that would fail. But, to be honest, it comes as a complete surprise to me that vib is multiline !! (I only checked as you mentionned the pb) Julien PS: Sorry Ted for the double post |