In vimL, how to get a string from cursor to end of
expand('<cWORD>', but don't known how to keep only right part of cursor.
pre abc-xyz.xxx:123 post,
with cursor at
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.Sign up to join this community
One option is to take the current line, then the substring starting at the current position, split it into multiple words and take the first one. Or, in Vimscript:
let word = split(getline('.')[col('.')-1:])
One alternative is to use a normal mode command such as
yW and then access the contents of the default register (or, better, use a named register.) You can save and restore the contents of the register, so that accessing their contents after the call to the function will still return the original value.
function! GetWord() let save_reg = getreg('x') let save_type = getregtype('x') normal! "xyW let word = @x call setreg('x', save_reg, save_type) return word endfunction