Vim, change the definition of a paragraph separator

I write python code, and I'm faced with the annoying problem with the keys {

and }

: the definition of vim for paragraphs - it "blocks, separated by a blank line." However, when I code in a python class I like to keep the indentation between methods, so there is an easy way to make the paragraphs move like this:

class A:
  def f(): #cursor here, when I type {, go between f and g
    return 1

  #the previous line is indented
  def g():
    return 2

      

Of course, you can always reassign }

as a function that does

let a = @/
normal /\S\n\s*$/
normal j
let @/ = a

      

and {

to a similar one, but is there an easier way?

+3


source to share


2 answers


The solution posted by @romainl is fine, but you can also take a look at Kana textobj-user . This is the basis for defining text objects . Among other things, there is a plugin that uses this to define text objects for Python, which in turn have keys to navigate through functions and classes. People have written many other similar plugins .



+3


source


By default python ftplugin already overrides [m

and ]m

to go to previous and next ^\s*\(def\|class\)

.



+2


source







All Articles