Beckett wrote:
Question to group:
Is there a good way to jump to the start of the current function
in a case like the following (or in other languages like
Python)?

I suppose that one could remap something like

  :noremap [[ ?^\(\S.*{<bslash><bar>{\)<cr>
  :noremap ]] /^\(\S.*{<bslash><bar>{\)<cr>
  :noremap [] ?^\(\S.*{<bslash><bar>{\)<cr>%

For indentation-based languages like Python, you'd have to do something like

  :noremap [[ ?^\s*\(def\|class\)<cr>
  :noremap ]] /^\s*\(def\|class\)<cr>
  :noremap [] /^<c-r>=&et?repeat(' ', &ts):'\t'<cr>\S/e-<cr>

Finding the end of a section is a bit tricky (especially since python 2.x allows for spaces or tabs), so my "[]" version tries to guess whether it should use spaces or tabs based on your &et setting and uses &ts as your number of spaces. It's tricker if you have code like

  class Foo:
    class Bar:
      def baz(self):
        pass

because the end of baz() is more than one indent-worth. You might have to instead search backwards like "[[" for a class/def preceded only by whitespace, capture the quantity of whitespace and tack on one indentation level followed by "\S" to the forward-search pattern.

-tim



--
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

Reply via email to