" " File: words_tools.vim " Author: Luc Hermitte " " Last Update: 12nd nov 2001 " Purpose: Define functions better than expand("") " "=========================================================================== " " Return the current word, uses spaces to delimitate function! GetNearestWord() let c = col ('.')-1 let l = line('.') let ll = getline(l) let ll1 = strpart(ll,0,c) let ll1 = matchstr(ll1,'\S*$') let ll2 = strpart(ll,c,strlen(ll)-c+1) let ll2 = strpart(ll2,0,match(ll2,'$\|\s')) ""echo ll1.ll2 return ll1.ll2 endfunction " Return the word before the cursor, uses spaces to delimitate " Rem : is the word under or after the cursor function! GetCurrentWord() let c = col ('.')-1 let l = line('.') let ll = getline(l) let ll1 = strpart(ll,0,c) let ll1 = matchstr(ll1,'\S*$') if strlen(ll1) == 0 return ll1 else let ll2 = strpart(ll,c,strlen(ll)-c+1) let ll2 = strpart(ll2,0,match(ll2,'$\|\s')) return ll1.ll2 endif endfunction " Extract the word before the cursor, " use keyword definitions, skip latter spaces (see "bla word_accepted ") function! GetPreviousWord() let lig = getline(line('.')) let lig = strpart(lig,0,col('.')-1) return matchstr(lig, '\<\k*\>\s*$') endfunction