Delete word before and after the cursor in nano editor
Solution 1
Save this file to ~/.nanorc
and ctrl+] cuts the word to the left, and ctrl+| cuts right
bind ^] cutwordleft main
bind ^\\ cutwordright main
This works for me in nano version 2.5
Solution 2
There's no direct way to do this in nano
, but there are some key combinations that can accomplish what you want.
One useful tip to start is to open nano
using the -W
option, to make word boundaries work in a more sensible manner.
-W, --wordbounds
Detect word boundaries more accurately by treating punctuation characters as parts of words.
Delete the word before the current position of the cursor
- Switch on marking - Ctrl+6
- Move forward one word - Ctrl+Space
- Cut (delete) the selection - Ctrl+K
Delete the word after the current position of the cursor
Switch on marking - Ctrl+6
Move backward one word - Alt+Space
Cut (delete) the selection - Ctrl+K
Delete from the current cursor position to the beginning of the line
Switch on marking - Ctrl+6
Move to beginning of current line - Ctrl+A
Cut (delete) the selection - Ctrl+K
These command will work as described in a normal terminal, though the Alt key is swallowed by some editors (if I've connected through Windows cmd by ssh). You can use Esc to replace Alt.
Related videos on Youtube
Hendrik
Updated on September 18, 2022Comments
-
Hendrik over 1 year
How can I delete the word before and the word after the current position of the cursor in nano editor? (For the sake of clarity: I mean two distinct editions under this description, like the Ctrl-Backspace and Ctrl-Delete in Windows).
And how can I delete the text between the beginning of the current line and the position of the cursor?
-
KingKaitoKid over 5 yearslater version of nano allow users to bind the
cutwordleft
andcutwordright
functions to keyboard shortcuts using~/.nanorc
-
KingKaitoKid over 4 yearsthe most recent version of nano broke because now ctrl-\ is used to search and replace. thanks nano.