Commands: :normal and :execute

This commit is contained in:
Marco Hinz 2016-02-08 14:34:37 +01:00
parent 33932b5195
commit a6b229305d
2 changed files with 28 additions and 0 deletions

View File

@ -23,6 +23,7 @@ All notable changes to this project will be documented in this file.
- Basics: [Completion?](README.md#completion) - Basics: [Completion?](README.md#completion)
- Basics: [Undo tree?](README.md#undo-tree) - Basics: [Undo tree?](README.md#undo-tree)
- Commands: [:redir](README.md#redir) - Commands: [:redir](README.md#redir)
- Commands: [:normal and :execute](README.md#normal-and-execute)
- Tips: [Saner command-line history](README.md#saner-command-line-history) - Tips: [Saner command-line history](README.md#saner-command-line-history)
- Tips: [Reload a file on saving](README.md#reload-a-file-on-saving) - Tips: [Reload a file on saving](README.md#reload-a-file-on-saving)
- Tips: [Smarter cursorline](README.md#smarter-cursorline) - Tips: [Smarter cursorline](README.md#smarter-cursorline)

View File

@ -76,6 +76,7 @@ Twitter](https://twitter.com/_mhinz_). Thanks!
#### [Commands](#commands-1) #### [Commands](#commands-1)
- [:normal and :execute](#normal-and-execute) - The scripting dream team.
- [:redir](#redir) - Redirect messages. - [:redir](#redir) - Redirect messages.
#### [Debugging](#debugging-1) #### [Debugging](#debugging-1)
@ -1878,6 +1879,32 @@ set complete-=t " disable searching tags
Useful commands that are good to know. Useful commands that are good to know.
#### :normal and :execute
These commands are commonly used in Vim scripts.
With `:normal` you can do normal mode mappings from the command-line. E.g.
`:normal! 4j` will make the cursor go down 4 lines (without using any custom
mapping for "j" due to the "!").
Mind that `:normal` also takes a count, so `:%norm! Iabc` would prepend "abc" to
every line.
With `:execute` you can mix commands with expressions. Assume you edit a C
source file and want to switch to its header file:
```vim
:execute 'edit' fnamemodify(expand('%'), ':r') . '.h'
```
Both commands are often used together. Assume you want to make the cursor go
down "n" lines:
```vim
:let n = 4
:execute 'normal!' n . 'j'
```
#### :redir #### :redir
Many commands print messages and `:redir` allows to redirect that output. You Many commands print messages and `:redir` allows to redirect that output. You