Wednesday, April 8, 2020

Re: vmap inline conditional ques

Am 08.04.2020 um 01:19 schrieb M Kelly:
> Hi,
>
> Is there a way to do an inline conditional such as for demonstration:
>
> vnoremap <silent> <expr> <M-Left> <C-\><C-n>':let [line_start, col_start] = getpos("v")[1:2] <bar> :let [line_end, col_end] = getpos(".")[1:2] <bar> (line_end > line_start) ? "ge" : "b"<CR>'
>
> I can do something in a function but that has several exe 'normal ...' statements and thus does not draw smoothly.
> It seems I cannot get past the :let part.
>
> thx for any help and everything vim,
> stay safe everyone during this mess,
> -m

The RHS is not a valid expression.

" what I would use using below functions
vnoremap <expr> <M-Right> VisAtEnd(0) ? 'e' : 'w'
vnoremap <expr> <M-Left> VisAtStart(0) ? 'b' : 'ge'


" VisAtStart({strict})
"
" return true if the cursor is in the upper left corner of the Visual
" area, otherwise false. If Visual mode is off: returns true always.
" For {strict}, see VisAtEnd().
"

" VisAtEnd({strict})
"
" return true if the cursor is in the lower right corner of the Visual
" area, otherwise false. If Visual mode is off: returns true always.
"
" {strict} (boolean)
" true more exact check when in Visual block mode (4 corners)
" false always do the charwise/linewise check (2 corners)
"
" When {strict} is true, then in Visual block mode both VisAtStart() and
" VisAtEnd() can be false. See :h v_O .
"


func! VisAtStart(strict) "{{{
if mode() ==? 'v' || !a:strict
return line("v") > line(".") || line("v") == line(".") && col("v") >= col(".")
else
" assume Visual block mode
return line("v") >= line(".") && col("v") >= col(".")
endif
endfunc "}}}

func! VisAtEnd(strict) "{{{
if mode() ==? 'v' || !a:strict
return line("v") < line(".") || line("v") == line(".") && col("v") <= col(".")
else
" assume Visual block mode
return line("v") <= line(".") && col("v") <= col(".")
endif
endfunc "}}}


--
Andy

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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/5E8E199F.1080804%40yahoo.de.

No comments: