Fixing vi paragraph motion: change empty line definition to include blank lines with spaces and tabs

Reading Time: 1 minutes

Vim Paragraph Motions

(code from udacity “AI for robotics” class, lesson 8 particle filters)

I was feeling frustrated as the command I use all the time, moving forward or backward by a paragraph using { or }, was skipping a complete screen up and down. In the above screenshotted example, I was moving from the start of the class definition (up an entire screen) to the end,  instead of the behavior I expected of moving from function to function within the class.

Turns out that the vim’s paragraph definition only includes completely empty lines, and does not include lines that appear empty but have whitespace such as spaces or indents.


I installed vundle and installed the vim-paragraph-motion plugin. That is, in vim.rc, I added the following bundle line below the plugin vundle.vim line.

Plugin 'VundleVim/Vundle.vim'
Bundle 'dbakker/vim-paragraph-motion'

Then I closed and reopened vim, and ran :BundleInstall.

Reopened the file I was editing, and voila, paragraph motion commands behaved as I was expecting.

Credit to this post.

Debugging: show whitespace including spaces and tabs

I was confused debugging this for a while, as :set list doesn’t show spaces and tabs! So the end character was appearing as a magically “indented” end-of-line character. My search terms were all out of whack.

def some func():

vs, with help from this post, using :set listchars=eol:$,tab:>-,trail:~,extends:>,precedes:<

def some func():

Bonus! vim: go to definition of variable under cursor

Also, today I discovered the use of gd , which moves you to where the variable under your cursor is defined!

Then you can use Ctrl-O to move back to where you started (and Ctrl-I if you want to go forward in your jump list).

Credit to this post.

projects blog (*wave* Hi, I'm Nancy Ouyang, aka nouyang)