Tips: Saner command-line history

This commit is contained in:
Marco Hinz 2016-01-09 03:45:13 +01:00
parent 233f5b13db
commit 9901e63949
2 changed files with 21 additions and 0 deletions

View File

@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file.
### Added
- Basics: [Marks?](README.md#marks)
- Tips: [Saner command-line history](README.md#saner-command-line-history)
- Debugging: [Verbosity](README.md#verbosity)
- Debugging: [Debugging Vim scripts](README.md#debugging-vim-scripts)
- Miscellaneous: [Easter eggs](README.md#easter-eggs)

View File

@ -36,6 +36,7 @@ added every day. Things about to be added can be found here:
#### [Tips](#tips-1)
- [Saner behavior of n and N](#saner-behavior-of-n-and-n)
- [Saner command-line history](#saner-command-line-history)
- [Quickly move current line](#quickly-move-current-line)
- [Quickly add empty lines](#quickly-add-empty-lines)
- [Quickly edit your macros](#quickly-edit-your-macros)
@ -697,6 +698,25 @@ nnoremap <expr> n 'Nn'[v:searchforward]
nnoremap <expr> N 'nN'[v:searchforward]
```
#### Saner command-line history
If you're anything like me, you're used to going to next and previous items via
`<c-n>` and `<c-p>` respectively. By default, this also works in the
command-line and recalls older or more recent command-lines from history.
So far, so good. But `<up>` and `<down>` are even smarter! They recall the
command-line whose beginning matches the current command-line. E.g. `:echo <up>`
may change to `:echo "Vim rocks!"`.
Of course I don't want you to reach to the arrow keys, just map it instead:
```viml
cnoremap <c-n> <down>
cnoremap <c-p> <up>
```
I depend on this behaviour several times a day.
#### Quickly move current line
Sometimes I need a quick way to move the current line above or below: