Wednesday, December 30, 2009

How to check whether a char is Chinese or not?

To search Chinese within Vim, I can do
/[^\x00-\xff]<CR>

To search non-Chinese within Vim, I can do
/[\x00-\xff]<CR>

Both worked well within Vim buffer, however,
I found it did not work inside a Vim script.

For example:

This function did not work:
---------------------------------------
function! <SID>vimim_ctrl_x_ctrl_u_bs()
---------------------------------------
let char_before = getline(".")[col(".")-2]
if char_before =~ "[\x00-\xff]"
let s:smart_backspace = 1
endif
endfunction

Instead, I have to use an inaccurate alternative:
---------------------------------------
function! <SID>vimim_ctrl_x_ctrl_u_bs()
---------------------------------------
let char_before = getline(".")[col(".")-2]
if char_before =~ '\w'
let s:smart_backspace = 1
endif
endfunction

--
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php

No comments: