Re: Multiple commands from Fkey
Gary wrote in part: nmap silent F2 :call DoSub()CR function DoSub() %s/^/``/e %s/ / ``/ge %s/$/''/e %s/ /'' /ge endfunction For my other F keys I have used noremap instead of nmap, thus: inoremap F3 C-O:!pdftex book.texCr nnoremap F3 :!pdftex book.texCr inoremap F4 C-O:!texexec book.tex /dev/nullCr nnoremap F4 :!texexec book.tex /dev/nullCr inoremap F5 C-O:!acroread book.pdfCr nnoremap F5 :!acroread book.pdfCr nnoremap F2 1GgqG Which is the better usage? I have read but do not understand fully the help item suggested previousely. I will use the code in two different rc files: one for my own use on a Linux system using gvimrc, and one ( _vimrc) to be used by customers who are presumed to be using evim at leas to start. -- John Culleton Able Indexing and Typesetting Precision typesetting (tm) at reasonable cost. Satisfaction guaranteed. http://wexfordpress.com
Re: Multiple commands from Fkey
On 2007-05-14, John R. Culleton [EMAIL PROTECTED] wrote: Gary wrote in part: nmap silent F2 :call DoSub()CR function DoSub() %s/^/``/e %s/ / ``/ge %s/$/''/e %s/ /'' /ge endfunction For my other F keys I have used noremap instead of nmap, thus: inoremap F3 C-O:!pdftex book.texCr nnoremap F3 :!pdftex book.texCr inoremap F4 C-O:!texexec book.tex /dev/nullCr nnoremap F4 :!texexec book.tex /dev/nullCr inoremap F5 C-O:!acroread book.pdfCr nnoremap F5 :!acroread book.pdfCr nnoremap F2 1GgqG Which is the better usage? I have read but do not understand fully the help item suggested previousely. Without the nore part, when the use presses the mapped key, vim executes the rhs of the mapping including executing any mappings it finds on the rhs. For example, if you define the following mapping, nmap D dj to delete the current line and the line below, and some plugin has redefined 'j' with nmap j k then when you type 'D', your macro will delete the current line and the line _above_. Adding nore tells vim to ignore any mappings on the rhs and to execute any commands on the rhs with their default actions. Continuing the example above, changing the 'D' mapping to nnoremap D dj will ensure that (as long as D itself is not remapped) typing 'D' will delete the current line and the line below regardless of any mapping of 'd' or 'j'. Including nore is then the safer usage since it protects the rhs of the macro from being affected by any mappings of the functions on the rhs. I didn't use 'nnoremap' in the F2 mapping above because I thought there was no possibility of a remapping of anything on the rhs, so that the nore would be superfluous, but now I see that the macro would be affected if someone defined ':' as a macro (a really poor choice). Regards, Gary -- Gary Johnson | Agilent Technologies [EMAIL PROTECTED] | Mobile Broadband Division | Spokane, Washington, USA
Multiple commands from Fkey
I want a single F key assignment via user's gvimrc to activate several commands in order, e.g.: %s/^/``/ %s/ / ``/g %s/$/''/ %s/ /'' /g (The left hand part contains an inch sign and the right hand part contains either two back ticks or two apostrophes.) I may add more such commands to the same F key. Can I string them all together in a gvimrc command or would it be handier to have the F key call a script somehow? This will be for a naive user. (I am pretty naive myself :) -- John Culleton Able Indexing and Typesetting Precision typesetting (tm) at reasonable cost. Satisfaction guaranteed. http://wexfordpress.com
Re: Multiple commands from Fkey
On 2007-04-19, John R. Culleton [EMAIL PROTECTED] wrote: I want a single F key assignment via user's gvimrc to activate several commands in order, e.g.: %s/^/``/ %s/ / ``/g %s/$/''/ %s/ /'' /g (The left hand part contains an inch sign and the right hand part contains either two back ticks or two apostrophes.) I may add more such commands to the same F key. Can I string them all together in a gvimrc command or would it be handier to have the F key call a script somehow? This will be for a naive user. (I am pretty naive myself :) You can certainly string them together in a single mapping using bar as a separator and CR as a terminator, e.g., nmap F2 :%s/^/``/ bar %s/ / ``/g bar %s/$/''/ bar %s/ /'' /gCR However, that mapping will fail as soon as one of the substitutions fails, so a better mapping would include the 'e' flag at the end of each substitution, e.g., nmap F2 :%s/^/``/e bar %s/ / ``/ge bar %s/$/''/e bar %s/ /'' /geCR That mapping will leave the command visible in the command line after the user presses the function key, and if the command is long or the window is narrow, the user will also get the Press ENTER or type a command to continue prompt when the command is done. To avoid that, you can add silent to the mapping, e.g., nmap silent F2 :%s/^/``/e bar %s/ / ``/ge bar %s/$/''/e bar %s/ /'' /geCR Such a long mapping can be difficult to maintain. One way to make that easier is to put the commands in a function and have the mapping just call that function, e.g., nmap silent F2 :call DoSub()CR function DoSub() %s/^/``/e %s/ / ``/ge %s/$/''/e %s/ /'' /ge endfunction See also :help :bar :help map_bar :help :s_flags :help map-silent :help user-functions HTH, Gary -- Gary Johnson | Agilent Technologies [EMAIL PROTECTED] | Mobile Broadband Division | Spokane, Washington, USA