I want to bind "tab" to autocompletion in python mode.
But when I am on a line, where there are only are whitespaces in front of
the cursor, autocompletion does not make sense.
Can I somehow detect this situation and insert an "tab" in that case?
Thanks!
Nathan
--
View this message in context: http://www.nabble.com/check-if-only-whitespaces-before-cursor-in-current-line-tp24390733p24390733.html
Sent from the Vim - General mailing list archive at Nabble.com.
let x=line(".")
But how do I check if there are only whitespaces before cursor?
Thanks!
Nathan
TheLonelyStar wrote:
>
> Hi.
>
> I want to bind "tab" to autocompletion in python mode.
> But when I am on a line, where there are only are whitespaces in front of
> the cursor, autocompletion does not make sense.
> Can I somehow detect this situation and insert an "tab" in that case?
>
> Thanks!
> Nathan
>
--
View this message in context: http://www.nabble.com/check-if-only-whitespaces-before-cursor-in-current-line-tp24390733p24410328.html
something like this maybe?
let x=getline('.')
let y='\%>' . col('.') . 'v\s\+$'
let ws=match(x, y)
regards,
Christian
Christian Brabandt-3 wrote:
>
>
> something like this maybe?
> let x=getline('.')
> let y='\%>' . col('.') . 'v\s\+$'
> let ws=match(x, y)
>
>
Hi,
Sorry, if this is getting a stupid question. I searched the documentation,
but I can not find another definition for "match" than higlighting in the
current buffer.
I mean, I need something like this:
if "only_whitespaces_before_cursor" then
do_something
else
do_something_else
endif
Thanks!
Nathan
--
View this message in context: http://www.nabble.com/check-if-only-whitespaces-before-cursor-in-current-line-tp24390733p24412419.html
:help match()
Regards,
Dennis Benzinger
It just does not work, if I do
let x=getline('.')
let y='\%>' . col('.') . 'v\s\+$'
let ws=match(x, y)
echo ws
The result is always "-1", now matter of whitespaces before cursor or not.
So, the '\%>' . col('.') . 'v' matches everything after cursor and \s\+
should match the whitespaces.
I think I understand ... but it does not work :(
--
View this message in context: http://www.nabble.com/check-if-only-whitespaces-before-cursor-in-current-line-tp24390733p24414449.html
On Do, 09 Jul 2009, TheLonelyStar wrote:
> It just does not work, if I do
>
> let x=getline('.')
> let y='\%>' . col('.') . 'v\s\+$'
> let ws=match(x, y)
> echo ws
>
Let's take this line (| denotes the place where the cursor is, _
stands for Spaces):
Here is some whitespace|_________
If I do
:echo ws=match(x,y) it returns 24.
regards,
Christian
--
:wq!
Here is my complete function from .vimrc:
map <tab> :call TestComplete()<cr>
function TestComplete()
let x=getline('.')
let y='\%>' . col('.') . 'v\s\+$'
let ws=match(x, y)
echo ws
endfunction
it echos -1 no matter what I do. And I also do not get it to work typing for
Example:
:echo ws=match(x,y)
--
View this message in context: http://www.nabble.com/check-if-only-whitespaces-before-cursor-in-current-line-tp24390733p24414975.html
On Do, 09 Jul 2009, TheLonelyStar wrote:
> In my case it returns -1 ....
>
>
> it echos -1 no matter what I do.
Please provide an exact example. Where is the cursor and what does the
line look like?
> And I also do not get it to work typing for
> Example:
> :echo ws=match(x,y)
:echo match(x,y)
regards,
Christian
--
:wq!
>
> Please provide an exact example. Where is the cursor and what does the
> line look like?
>
>
Examples (| marsk the cursor):
let| x=getline('.')
|let ws=match(x, y)
| jde
All these return -1
--
View this message in context: http://www.nabble.com/check-if-only-whitespaces-before-cursor-in-current-line-tp24390733p24416087.html
On Do, 09 Jul 2009, TheLonelyStar wrote:
> > Please provide an exact example. Where is the cursor and what does
> > the line look like?
> >
> >
> Examples (| marsk the cursor):
> let| x=getline('.')
> |let ws=match(x, y)
> | jde
>
> All these return -1
Sure, because there is just not any amount of space followed by the
line end.
I guess I misread your question. If you want to check, that there is
no space between line start and the cursor use something like this:
echo match(getline('.'), '^\s\{' . col('.') . '}')
regards,
Christian
--
:wq!