On 04/16/2011 08:16 PM, Tony Mechelynck wrote:
On 17/04/11 01:50, AK wrote:
Hi, I needed to make a mapping that would insert a bullet if '*' is
typed at the beginning of line and insert literal '*' if typed somewhere
else. I came up with something that works for me, but I
was wondering if there's a shorter / better way to do this.. Here's
what I have:
inoremap * x<bs><c-o>:Bul<CR>
command! Bul call Potl("bullet") | normal 3l
Where Potl("bullet") is a python vim function that checks current
line and where the cursor is, and either inserts '*' or '•' character.
I'm not including it because the question is whether there's a way
to do this with a single mapping, without a command, or with a mapping
and a one-line command, without a function?
Thanks! -Rainyday
(untested)
:inoremap <expr> * col('.') < 2 ? "\u25CF" : "*"
see
:help map-expression
:help expr1
:help col()
For the first _nonblank_ you can of course use a more complex condition
before the question mark. Also use a different bullet if ● doesn't suit
you.
Thanks so much - yes, there can be leading space.. here's what I ended
up doing:
au FileType potl inoremap <expr> <buffer> * Bullet(0)
au FileType potl inoremap <expr> <buffer> = Bullet(1)
au FileType potl inoremap <expr> <buffer> @ Bullet(2)
fun! Bullet(btype)
" btype: 0, ● (U+25CF) 1, ‣ (U+2023) 2, ◦ (U+25E6)
let l = getline('.')
let l = strpart(l, 0, col('.'))
let l = substitute(l, '\s\+', '', '')
if (a:btype==0) | let b = "\u25CF " | let c = "*" | endif
if (a:btype==1) | let b = "\u2023 " | let c = "=" | endif
if (a:btype==2) | let b = "\u25E6 " | let c = "@" | endif
return (l=='') ? b : c
endfu
Is there any way to further improve this? -Rainyday
--
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