It often happens that people start typing a command in terminal and then in the middle they remember that they should have another command before the current one. In this case people usually do a Ctrl+c and start writing the new command. There is a better way to undo and redo command typing in terminal.
I will try to explain undo and redo command typing with an example. Many times I start typing command for committing code changes to git repository and then I think I should first look at the diff or status before committing. Here is the flow of commands:
- git commit -a -m “Some random … (Before I press return I remember I want to first try git status)
- I then press Ctrl+u to undo command typing which clears the line.
- Then I can easily do git status
- And then when I want to get back to the original command which I was typing I press Ctrl+y to redo command typing. This will bring back the un-done command in step 2.
This is a really handy tip. I use it quite often since when I have discovered.
Summary: Ctrl+u for undoing a command typing. This clears the currently typed command line from the terminal. Ctrl+y for redoing a command typing. This will bring back the un-done command.
Vim 7.3 introduced a very nice feature – relative line numbers. In vim we normally use count(n) with any operator(o) to repeat the operation o, n number of times. For example – if one wants to delete next 7 lines including the current line one could issue command ’7dd’. ‘dd’ deletes the current line and ’7dd’ would delete next 7 lines including the current line. But I was rarely able to use this feature till Vim 7.2. It’s difficult to count the number of lines on screen and its time taking. So I would better use the operator ’0′, ‘n’ number of times or use some other alternative. Now in Vim 7.3 there is a very nice feature relative line numbers – The line on which you are present is numbered as 0 and numbers increase downwards and upwards. Here’s a screenshot to illustrate -
Vim 7.3 – Relative Line Numbers
In the screenshot above you can notice that line number 0 is the one on which the cursor is located. Line number increases upwards and downwards. Now it is easy to count number of lines both upwards and downwards. So now I can easily find how many lines I have to delete or copy from the present line. I have started using count with operators.
To switch on this feature enter the command “:set rnu” and to switch off this feature enter the command “:set nornu”.