'vim select function in python
I am new to vim and recently I learned that it is possible to select a function in c with vip
, and I was wondering if there is a way to do it with functions in python
keep in mind that function can contain different indentation levels for example
def func():
pass
if 1 > 2:
pass
and that I can't use any plugins
Solution 1:[1]
vip
is v
, followed by ip
:
v
enters visual mode,ip
is a text object that expands the selection to cover the current "paragraph".
It could be used to visually select a function in any language with functions, maybe, if that function satisfies Vim's definition of "paragraph". But that is a big "if", so vip
is as far from being a "select function" silver bullet as it can be.
See :help v
and :help ip
.
Now, the way text objects like ip
work is that they essentially locate a known landmark in one direction (a blank line in the case of ip
) and then look for a matching one in the other direction.
Given that (simplified) description, it would be relatively easy to imagine a custom pseudo-text object for a Ruby function:
def say_hello(name)
var = "Hello, " + name
return var
end
because its boundaries are clearly defined.
But Python functions:
def func():
pass
if 1 > 2:
pass
don't have well defined boundaries and there is not a single built-in text object that is able to cover such a case.
You will need third-party help for that:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | romainl |