开发者

Keyboard navigation of cell grouping hierarchy?

开发者 https://www.devze.com 2023-04-08 03:44 出处:网络
I find cell grouping very useful in organizing my notebooks. I\'ve been navigating this hierarchy by clicking with the mouse in the brackets on the right hand side of the notebook, but that\'s kind of

I find cell grouping very useful in organizing my notebooks. I've been navigating this hierarchy by clicking with the mouse in the brackets on the right hand side of the notebook, but that's kind of tedious and requires some hand-eye coordination that degrades in the early morning hours. I'd really like to be able to navigate with the keyboard, but I've been unable to do this with any shortcuts that I could find. I usually use the Mac version of Mm.

The arrow keys (or Ctl-F,B,P,N a la emacs) will move the cursor between cells displayed, and Ctl-. will select enclosing groups, essentially moving up the group hierarchy as I wish to do. And Cmd-' will open/close a group. However, I've not found a way to otherwise move through the groupings - primarily, say, moving the selection forward and backward at the same level but perhaps also down a level. Have I missed a shortcut or is there a better way to navigate the hierarchy?

The specific problem I have in mind is the following:

Suppose I have a collection of cells, grouped in sections A, B and C with subsections in each A1, A2, B1, B2, with cells A1a, A1b, etc. If I'开发者_JAVA百科m in cell A1a I can use ctl-. to select successively higher groupings - from A1a to A1 to A, for example. Now I have the whole A section selected. What I would like to do is to move to section C. If I use the arrow keys, I will advance to the next displayed cell at any level after the selected A (alternating with insertion points between those cells). But what I would like to do is to advance at the same (Section) level - to section B, then to section C. And then perhaps to drop the selection down to the subsection level - C1 - and advance to C3.

Its not a big deal, but I arrange my longer notebooks hierarchically like this to reflect a logical organization in my mind, and it would be very convenient to navigate the notebook more like I am thinking about the problem.


It is not too clear to me exactly what you want, but this might help you.

If you select a cell bracket and use the arrow keys, you will select a nearby cell bracket.

If you instead select inside a cell and use the arrow keys you will move inside the cell first and then inside nearby cells.

If you want to move a selected cell somewhere else:

  1. select the cell bracket
  2. type ctrl/cmd -X to cut the cell and put it on the clipboard
  3. move with arrows or otherwise to another location on the nb (between cells)
  4. type ctrl/cmd -V to paste the cut cell into the new place

This way you can quickly alter the cell hierarchy and order


You can add at least part of the functionality you want through editing MenuSetup.tr or KeyEventTranslations.tr. These are important system files, so be careful. Start by copying the file you are going to edit from the $InstallationDirectory to $UserBaseDirectory in the same tree. This should look something like:

\AppData\Roaming\Mathematica\SystemFiles\FrontEnd\TextResources\Windows\MenuSetup.tr

Now, editing the file in the new location, you can add menu items and key commands. Under the Menu["&Cell", section, being careful to respect brackets and commas, I add:

MenuItem["Next Cell",
  FrontEndExecute@{FrontEnd`SelectionMove[FrontEnd`SelectedNotebook[], Next, CellGroup]},
  MenuKey[".", Modifiers->{"Control"}]            
]

This adds a new menu item under Cell, and a new keyboard command to move to the next CellGroup: Ctrl+.. This should allow you to move from one highlighted cell group, such as a section, to the next group at the same level. This is the easiest of the commands to implement. I may return to this to try to implement some of the other commands, or you may experiment yourself with the arguments of SelectionMove to see what can be done.

0

精彩评论

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

关注公众号