Loading ...
Sorry, an error occurred while loading the content.

Re: Moving cursor to start of current word

Expand Messages
  • Andy Wokula
    ... Update: Doesn t work correctly with Visual mode. a:vmode argument and the following three lines should be removed. ... -- Andy
    Message 1 of 12 , Aug 27, 2008
    • 0 Attachment
      Andy Wokula schrieb:
      > Robert Webb schrieb:
      >>>> :silent! normal! heb
      >>> Won't work if the word is a single character.
      >> Also won't work at the start of this text: "== blah".
      >> The idea is to put the cursor at the start of the word that
      >> expand("<cword>") would return.
      >>
      >> This works quite well:
      >>
      >> func! Sow()
      >> if (getline(".")[col(".") - 1] =~ '\k')
      >> normal wb
      >> else
      >> call search('\<', 'sW')
      >> endif
      >> endfunc
      >>
      >> Except that it may search onto the next line if there are no more words,
      >> and won't find a non-word sequence at the end of the line if no words exist.
      >
      > This will find a non-word sequence at the end of the line if no words exist
      > (improvement of my first function):
      >
      > func! Sow(vmode)

      Update: Doesn't work correctly with Visual mode.
      a:vmode argument and the following three lines should be removed.

      > if a:vmode
      > normal! gv
      > endif
      > let xw = expand("<cword>")
      > if xw != ""
      > if xw =~ '\k'
      > call search('\k\>','cW')
      > else
      > call search('\S\S\@!','cW')
      > endif
      > if strlen(xw) > 1
      > normal! b
      > endif
      > endif
      > endfunc

      --
      Andy


      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_dev" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    Your message has been successfully submitted and would be delivered to recipients shortly.