Keyboard-only use of block/column mode in different text editors (Geany, Visual Studio, UltraEdit, Notepad++, Visual Studio Code, Vim, and Emacs)
Although it is often somewhat hidden, most text editors, except for the most basic ones, have a column mode (also known as block mode or visual mode) – to work on rectangular selections of text (including a width of zero).
Even more hidden is if it is possible to avoid using the mouse. In particular, Alt + mouse movement in Visual Studio will make a block selection, but this increases the risk of RSI. It is also impractical as the mouse must be used very precisely in both directions.
It turns out all the text editors considered here have a way to exclusively use the keyboard for column mode operations.
In Geany, Shift + Alt + arrow keys will make a block selection and thus effectively enter into column mode.
On Windows and Linux. It was tested with version 1.36 (Windows) and version 1.36 (Linux).
On Lubuntu (and Xubuntu?), the keyboard shortcuts do not work, because they conflict with four default keyboard shortcuts in the window manager (LXDE? Openbox?), Shift + Alt + arrow up, Shift + Alt + arrow down, Shift + Alt + arrow left, and Shift + Alt + arrow right. Disable them by editing file ~/.config/openbox/lubuntu-rc.xml near “S-A-Up”, “S-A-Down”, “S-A-Left”, and “S-A-Right”. For example, change “S-A-Up” to “S-A-Up99”, “S-A-Down” to “S-A-Down99”, “S-A-Left” to “S-A-Left99”, and “S-A-Right” to “S-A-Right99”, respectively. And add an XML comment as to why and document the original values (so they can more easily be reverted). Edit and update (without a restart required):
vi ~/.config/openbox/lubuntu-rc.xml openbox --reconfigure
In Visual Studio, Shift + Alt + arrow keys will make a block selection.
On Windows only. It was tested with Visual Studio 2012 (yes, I know).
In UltraEdit, it is a mode that must be entered first: Alt + C (for menu Column → Column Mode). Then normal selection works (Shift + arrow keys, etc.) – in this case, block selection.
On Windows and Linux. It was tested with version 16.2 (listed as “16.20”).
Special features in UltraEdit
The same text (e.g., a single word) from the clipboard can be inserted (in an empty column selection), in addition to being typed (so it is not necessary to retype the text). Thus after the paste the same text is now in all rows of the selection.
This is, e.g., not possible in Geany. The workaround is to prepare the text beforehand, producing the number of lines matching the number of rows in the selection and copy-paste those lines.
In Notepad++, Shift + Alt + arrow keys will make a block selection.
Note that it is blinking a lot when going over empty lines.
On Windows only. It was tested with version 7.9.1.
Visual Studio Code
In Visual Studio Code, it is much more tricky (not intuitive, inflexible and does not work as described in the documentation). The beginning is also not the same on Windows and Linux.
Use three modifier keys, Ctrl + Shift + Alt + arrow key down (or arrow key up). This puts it into column mode (with a column empty selection of two lines).
For Linux (this is very similar to Geany, Visual Studio, and Notepad++):
Press Shift + Alt + arrow key down (or arrow key up). This puts it into column mode (with a column empty selection of two lines).
The rest is common for Windows and Linux:
- Extend the selection to the desired number of rows (down or up). They must be selected before the columns.
- Lift the Ctrl key (as word selection would be the result in the next step – and the selection would be uneven (not a pure block)). Optionally also lift the Shift key.
- Extend the selection in the horizontal direction (to select the number of columns) by pressing the Shift key and the left or right arrow key.
- After operations using the block selection, the block selection mode can be exited by pressing the Esc key. Alternatively, the empty column selection (the number of columns stay the same) can be moved by the arrow keys (even up and down).
- Note that the Ctrl key works as an alternative to the Alt key.
Note that there is less freedom in how the block selection takes place. First the number of rows must be selected and then the number of columns.
Also, it does not work as expected if some of the lines are short (selection in the horizontal direction is beyond the short line) – the selection will extend onto the next line, making it useless. In particular, it does not work over empty lines – a very severe limitation.
On Windows and Linux. It was tested with version 1.43.1 (Windows) and 1.52.1 (Linux).
In conclusion, block mode in Visual Studio Code is both cumbersome to use and underdeveloped (it does not work for as many use cases as all the other editors presented here). Despite all the hype, Visual Studio Code has not matured.
Sublime Text is similar to the broken Visual Studio Code (e.g., with an initial column empty selection of two lines) and is unintuitive to use.
To start, press Shift + Alt + arrow key down (or arrow key up).
This was tested on Linux, with the default editor in ArcoLinux (an Arch Linux derivative).
In Vim, it is a mode that must be entered first: Alt + V. In Vim speak, it is called “visual mode”. Then using the arrow keys (and other movement) will make a block selection.
On Windows, Linux, and Raspberry Pi. It was tested with version 8.1 (Linux, 2018) and version 7.3 (Raspberry Pi, 2010).
Note that this also works for a first-generation Raspberry Pi over an SSH connection (but the name of the executable is ‘vi’, not ‘vim’ – though it is actually Vim that runs).
In Emacs, Ctrl + X, Space to start. Move the cursor to the end of the block/column selection (for example, by the arrow keys). The selection is invisible!
Related blog post (for example, with version requirements and instructions for casual use of Emacs): Building Emacs from source on Ubuntu 20.04 in 2020
Leave a Reply