El 27/08/11 00:22, Tony Mechelynck escribió:
On 26/08/11 19:24, Gerardo Marset wrote:
I'm looking for a way of knowing wether or not all the characters up to
the cursor position in the current line are spaces.
How would I do that?
Thanks!
Spaces only, or spaces and tabs, or any whitespace including (or not)
no-break spaces and including (or not) CJK wide spaces (U+3000 IIRC)?
Real spaces only.
Including or excluding the cursor position?
Excluding.
For "true" spaces only, and not including the cursor position, what
about (untested)
if getline('.') =~ '^ \{' . col('.') - 1 . '}'
" we are on the first nonspace, or before it
else
" we aren't
endif
(it is important to use single quotes in the test-expression).
The other cases are left as an exercise to the reader, but beware of
the difference between col() and virtcol()
Also, the example above should intentionally follow the "true" path
whenever we are in column 1, since in that case the zero characters
before the cursor contain nothing that isn't a space.
Nice, but it seems to have a little mistake. I had to add brackets like
this:
if getline('.') =~ '^ \{' . (col('.') - 1) . '}'
Then, it worked.
Much better than my previous method, which involved a loop and variables
and whatnot. Thanks!
--
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