Tuesday, April 17, 2012

Re: Solved: set paste in : mode only

суббота, 14 апреля 2012 г., 20:34:13 UTC+4 пользователь howardb21 написал:
> For any interested, I did arrange for paste to be set, only in : cmdline mode,
> without using the getcmdtype() function and an alternate abbreviation command.
> Thus, abbreviations expand in insert, and search modes, but not in command
> line mode. Easy - but a little clunky:
>
> au InsertEnter * set nopaste
> noremap Z9 /
> map / :set nopaste<CR>Z9
> noremap Z8 ?
> map ? :set nopaste<CR>Z8
> noremap Z7 :
> map : :set paste<CR>Z7
>
> The useful trick is redefining a command, by noremapping another command to
> it, and then adding whatever you want to the real command. Noremap prevents
> an infinite regress when the redefined command is executed.

First, why don't you use just

noremap : :set nopaste<CR>:
? Using "map" without "nore" for no reason is never a good idea.

Second, have you tested this in visual mode? It won't work, as well as `2:` in normal mode. Take a different approach:

function s:SetNoPaste()
set nopaste
return ''
endfunction
noremap <expr> : s:SetNoPaste().':'
noremap <expr> / s:SetNoPaste().'/'
noremap <expr> ? s:SetNoPaste().'?'

--
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

No comments: