Jump to start or end of current block?


#1

Is there a keyboard equivalent to Vim’s fold movements [z (move to start of open fold) ]z (move to end of open fold)? I know I can open and close a fold, but instead want to move around inside it…


#2

These two commands might help:

findContainingFoldRange = (editor, row) ->
	for i in [0..row]
		fold_range = editor.languageMode.rowRangeForFoldAtBufferRow(row - i)
		return fold_range if fold_range and fold_range[1] >= row

	return null

atom.workspaceView.command 'navigate-fold:end', ->
	editor = atom.workspace.getActiveEditor()
	row = editor.getCursor().getBufferRow()
	fold_range = findContainingFoldRange(editor, row)

	if fold_range and fold_range[1] == row and row < editor.getBuffer().lines.length - 1
		fold_range = findContainingFoldRange(editor, row + 1)

	if fold_range
		editor.moveCursorDown fold_range[1] - row

atom.workspaceView.command 'navigate-fold:start', ->
	editor = atom.workspace.getActiveEditor()
	row = editor.getCursor().getBufferRow()
	fold_range = findContainingFoldRange(editor, row)

	if fold_range and fold_range[0] == row and row > 0
		fold_range = findContainingFoldRange(editor, row - 1)

	if fold_range
		editor.moveCursorUp row - fold_range[0]

This seems to match the Vim behaviour as far as I can tell.

Copy into your init.coffee and then add whatever key bindings you want for navigate-fold:start and navigate-fold:end in keymap.cson.