开发者

what's the fastest way to select a function of Python via VIM?

I开发者_如何学运维s it possible without any plugins? Or what's the best plugin for edit python file?


try vis to visualy select and o to jump edges


The way I do it is not specific to functions. It will just select a continuous block of Python code:

v]] if what you want to select is below the cursor
v[[ if it is above the cursor.

Just remove one bracket if the cursor is on the first line of the code block you want to select.


With this plugin https://github.com/bps/vim-textobj-python you can select, delete, change, etc:

af: a function
if: inner function
ac: a class
ic: inner class


I normally use vip or any of the above depending on the need, do not forget that you can always select up (i.e., down =)) to the next occurrence using v/match (followed by Enter to confirm, and possibly n for next). For python, you could look for the next def or for the return (ret is normally enough).

This isn't the fastest at the beginning, but it is very general, use it in any language and also outside coding (md, latex, etc.).


I assume you mean visually selecting the whole function quickly. One way is to use Indent text object. You can use vai to select the whole function, provided your cursor is inside the function and only 1 indentation level lower.

If you really want select function regardless of indentation level, I suggest you read this and write your own text object. I imagine it would be quite easy since Python has def keyword for defining function.


you have to use omnicompletion for vim7 but it's only working with vim-nox, vim-gtk, vim-gnome o vim-athen

also read throu this page for configuring vim with python (autoindend, syntax highlight and autocompletion)


I try to avoid visual, hence for actions like yank, I tend to go to the beginning of the paragraph [[, yank till the end y]] and come back ^o. All in one, it is [[y]]^o (With ^ standing for control).

For visual you might use [[v]] or some variations like [[v][, [[v]m, or [[v]M.


If your function is long or has many blank lines, using v}}...}}d is pretty slow.

The quickest way I've found (without plug-ins) is zc2dd. The command zc closes the fold under the cursor, so if you are at the function declaration or any line at the outermost indent level, the whole function will fold. Then 2dd (or 3dd if you have two blank lines before/after your function) will remove the whole thing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜