From a6b229305d24344af7e2c271116a492dcfbc301a Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Mon, 8 Feb 2016 14:34:37 +0100 Subject: [PATCH] Commands: :normal and :execute --- CHANGELOG.md | 1 + README.md | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a2eb39..b3032aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ All notable changes to this project will be documented in this file. - Basics: [Completion?](README.md#completion) - Basics: [Undo tree?](README.md#undo-tree) - 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: [Reload a file on saving](README.md#reload-a-file-on-saving) - Tips: [Smarter cursorline](README.md#smarter-cursorline) diff --git a/README.md b/README.md index 9560297..8680876 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,7 @@ Twitter](https://twitter.com/_mhinz_). Thanks! #### [Commands](#commands-1) +- [:normal and :execute](#normal-and-execute) - The scripting dream team. - [:redir](#redir) - Redirect messages. #### [Debugging](#debugging-1) @@ -1878,6 +1879,32 @@ set complete-=t " disable searching tags 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 Many commands print messages and `:redir` allows to redirect that output. You