vim understanding the various modes and using the yanking more efficiently.

2010-04-06 783 words 4 mins read

\"MacVim
Image via Wikipedia

We will look at the vim modes today. Sometime back , I was looking at copying a function body. So I was basically looking to copy the lines till matching &#8221;}&#8221;. I found a plugin called <a href="http://www.vim.org/scripts/script.php?script_id=1234" target="_blank">yankring which would allow me to yank the text in various combinations. So I can copy a function by going to the begining of the function and then &#8221;y}&#8221;. That is very simple to understand right? Wrong!!!

The help mentions that you need to press &#8221;}&#8221; in the operator pending mode. I have been a vim user for quite sometime but did not bother to look at the documentation so thoroughly to understand all the modes, so here is a description of all the modes of vim.

<a class=\"zem_slink freebase/en/vim\" title=\"Vim (text editor)\" rel=\"homepage\" href=\"http://www.vim.org/\">Vim</a> has six <a class=\"zem_slink freebase/en/basic\" title=\"BASIC\" rel=\"wikipedia\" href=\"http://en.wikipedia.org/wiki/BASIC\">BASIC</a> modes:

			
<a href=\"http://vimdoc.sourceforge.net/htmldoc/intro.html#Normal\">Normal</a> mode		In <a href=\"http://vimdoc.sourceforge.net/htmldoc/intro.html#Normal\">Normal</a> mode you can enter all the <a class=\"zem_slink freebase/en/normal_mode\" title=\"Normal mode\" rel=\"wikipedia\" href=\"http://en.wikipedia.org/wiki/Normal_mode\">normal</a> <a class=\"zem_slink freebase/en/editing\" title=\"Editing\" rel=\"wikipedia\" href=\"http://en.wikipedia.org/wiki/Editing\">editor</a>
			commands.  If you start the editor you are in this
			mode (unless you have set the <a href=\"http://vimdoc.sourceforge.net/htmldoc/options.html#%27insertmode%27\">\'insertmode\'</a> option,
			see below).  This is also known <a href=\"http://vimdoc.sourceforge.net/htmldoc/motion.html#as\">as</a> command mode.

<a href=\"http://vimdoc.sourceforge.net/htmldoc/visual.html#Visual\">Visual</a> mode		This is like <a href=\"http://vimdoc.sourceforge.net/htmldoc/intro.html#Normal\">Normal</a> mode, but the <a href=\"http://vimdoc.sourceforge.net/htmldoc/intro.html#movement\">movement</a> commands
			extend a highlighted area.  When a non-movement
			command is used, <a href=\"http://vimdoc.sourceforge.net/htmldoc/motion.html#it\">it</a> is executed for the highlighted
			area.  See |<a href=\"http://vimdoc.sourceforge.net/htmldoc/visual.html#Visual-mode\">Visual-mode</a>|.
			If the <a href=\"http://vimdoc.sourceforge.net/htmldoc/options.html#%27showmode%27\">\'showmode\'</a> option is on \"<a href=\"http://vimdoc.sourceforge.net/htmldoc/starting.html#--\">--</a> VISUAL --\" is shown
			at the bottom of the <a href=\"http://vimdoc.sourceforge.net/htmldoc/windows.html#window\">window</a>.

<a href=\"http://vimdoc.sourceforge.net/htmldoc/visual.html#Select\">Select</a> mode		This looks most like the <a href=\"http://vimdoc.sourceforge.net/htmldoc/os_win32.html#MS-Windows\">MS-Windows</a> selection mode.
			Typing a printable character deletes the selection
			and starts <a href=\"http://vimdoc.sourceforge.net/htmldoc/insert.html#Insert\">Insert</a> mode.  See |<a href=\"http://vimdoc.sourceforge.net/htmldoc/visual.html#Select-mode\">Select-mode</a>|.
			If the <a href=\"http://vimdoc.sourceforge.net/htmldoc/options.html#%27showmode%27\">\'showmode\'</a> option is on \"<a href=\"http://vimdoc.sourceforge.net/htmldoc/starting.html#--\">--</a> SELECT --\" is shown
			at the bottom of the <a href=\"http://vimdoc.sourceforge.net/htmldoc/windows.html#window\">window</a>.

<a href=\"http://vimdoc.sourceforge.net/htmldoc/insert.html#Insert\">Insert</a> mode		In <a href=\"http://vimdoc.sourceforge.net/htmldoc/insert.html#Insert\">Insert</a> mode the text you type is inserted into the
			buffer.  See |<a href=\"http://vimdoc.sourceforge.net/htmldoc/insert.html#Insert-mode\">Insert-mode</a>|.
			If the <a href=\"http://vimdoc.sourceforge.net/htmldoc/options.html#%27showmode%27\">\'showmode\'</a> option is on \"<a href=\"http://vimdoc.sourceforge.net/htmldoc/starting.html#--\">--</a> INSERT --\" is shown
			at the bottom of the <a href=\"http://vimdoc.sourceforge.net/htmldoc/windows.html#window\">window</a>.

<a href=\"http://vimdoc.sourceforge.net/htmldoc/cmdline.html#Command-line\">Command-line</a> mode	In <a href=\"http://vimdoc.sourceforge.net/htmldoc/cmdline.html#Command-line\">Command-line</a> mode (also called <a href=\"http://vimdoc.sourceforge.net/htmldoc/cmdline.html#Cmdline\">Cmdline</a> mode) you
<a href=\"http://vimdoc.sourceforge.net/htmldoc/cmdline.html#Cmdline\">Cmdline</a> mode		can enter one line of text at the bottom of the
			<a href=\"http://vimdoc.sourceforge.net/htmldoc/windows.html#window\">window</a>.  This is for the <a href=\"http://vimdoc.sourceforge.net/htmldoc/intro.html#Ex\">Ex</a> commands, \"<a href=\"http://vimdoc.sourceforge.net/htmldoc/cmdline.html#:\">:</a>\", the <a href=\"http://vimdoc.sourceforge.net/htmldoc/pattern.html#pattern\">pattern</a>
			search commands, \"<a href=\"http://vimdoc.sourceforge.net/htmldoc/pattern.html#?\">?</a>\" and \"<a href=\"http://vimdoc.sourceforge.net/htmldoc/pattern.html#/\">/</a>\", and the <a href=\"http://vimdoc.sourceforge.net/htmldoc/change.html#filter\">filter</a> command,
			\"<a href=\"http://vimdoc.sourceforge.net/htmldoc/change.html#%21\">!</a>\".  |<a href=\"http://vimdoc.sourceforge.net/htmldoc/cmdline.html#Cmdline-mode\">Cmdline-mode</a>|

<a href=\"http://vimdoc.sourceforge.net/htmldoc/intro.html#Ex\">Ex</a> mode			Like <a href=\"http://vimdoc.sourceforge.net/htmldoc/cmdline.html#Command-line\">Command-line</a> mode, but after entering a command
			you remain in <a href=\"http://vimdoc.sourceforge.net/htmldoc/intro.html#Ex\">Ex</a> mode.  Very limited editing of the
			command line.  |<a href=\"http://vimdoc.sourceforge.net/htmldoc/intro.html#Ex-mode\">Ex-mode</a>|

There are six ADDITIONAL modes.  These are variants of the BASIC modes:

				
<a href=\"http://vimdoc.sourceforge.net/htmldoc/intro.html#Operator-pending\">Operator-pending</a> mode	This is like <a href=\"http://vimdoc.sourceforge.net/htmldoc/intro.html#Normal\">Normal</a> mode, but after an <a href=\"http://vimdoc.sourceforge.net/htmldoc/motion.html#operator\">operator</a>
			command has started, and Vim is waiting for a <a href=\"http://vimdoc.sourceforge.net/htmldoc/intro.html#%7Bmotion%7D\">{motion}</a>
			to specify the text that the <a href=\"http://vimdoc.sourceforge.net/htmldoc/motion.html#operator\">operator</a> will work on.

<a href=\"http://vimdoc.sourceforge.net/htmldoc/insert.html#Replace\">Replace</a> mode		<a href=\"http://vimdoc.sourceforge.net/htmldoc/insert.html#Replace\">Replace</a> mode is a special <a href=\"http://vimdoc.sourceforge.net/htmldoc/change.html#case\">case</a> of <a href=\"http://vimdoc.sourceforge.net/htmldoc/insert.html#Insert\">Insert</a> mode.  You
			can <a href=\"http://vimdoc.sourceforge.net/htmldoc/diff.html#do\">do</a> the same things <a href=\"http://vimdoc.sourceforge.net/htmldoc/motion.html#as\">as</a> in <a href=\"http://vimdoc.sourceforge.net/htmldoc/insert.html#Insert\">Insert</a> mode, but for
			each character you enter, one character of the existing
			text is deleted.  See |<a href=\"http://vimdoc.sourceforge.net/htmldoc/insert.html#Replace-mode\">Replace-mode</a>|.
			If the <a href=\"http://vimdoc.sourceforge.net/htmldoc/options.html#%27showmode%27\">\'showmode\'</a> option is on \"<a href=\"http://vimdoc.sourceforge.net/htmldoc/starting.html#--\">--</a> REPLACE --\" is
			shown at the bottom of the <a href=\"http://vimdoc.sourceforge.net/htmldoc/windows.html#window\">window</a>.

Virtual <a href=\"http://vimdoc.sourceforge.net/htmldoc/insert.html#Replace\">Replace</a> mode	Virtual <a href=\"http://vimdoc.sourceforge.net/htmldoc/insert.html#Replace\">Replace</a> mode is similar to <a href=\"http://vimdoc.sourceforge.net/htmldoc/insert.html#Replace\">Replace</a> mode, but
			instead of file characters you are <a href=\"http://vimdoc.sourceforge.net/htmldoc/change.html#replacing\">replacing</a> screen
			real estate.  See |<a href=\"http://vimdoc.sourceforge.net/htmldoc/insert.html#Virtual-Replace-mode\">Virtual-Replace-mode</a>|.
			If the <a href=\"http://vimdoc.sourceforge.net/htmldoc/options.html#%27showmode%27\">\'showmode\'</a> option is on \"<a href=\"http://vimdoc.sourceforge.net/htmldoc/starting.html#--\">--</a> VREPLACE --\" is
			shown at the bottom of the <a href=\"http://vimdoc.sourceforge.net/htmldoc/windows.html#window\">window</a>.

<a href=\"http://vimdoc.sourceforge.net/htmldoc/insert.html#Insert\">Insert</a> <a href=\"http://vimdoc.sourceforge.net/htmldoc/intro.html#Normal\">Normal</a> mode	Entered when <a href=\"http://vimdoc.sourceforge.net/htmldoc/motion.html#CTRL-O\">CTRL-O</a> given in <a href=\"http://vimdoc.sourceforge.net/htmldoc/insert.html#Insert\">Insert</a> mode.  This is
			like <a href=\"http://vimdoc.sourceforge.net/htmldoc/intro.html#Normal\">Normal</a> mode, but after executing one command Vim
			returns to <a href=\"http://vimdoc.sourceforge.net/htmldoc/insert.html#Insert\">Insert</a> mode.
			If the <a href=\"http://vimdoc.sourceforge.net/htmldoc/options.html#%27showmode%27\">\'showmode\'</a> option is on \"<a href=\"http://vimdoc.sourceforge.net/htmldoc/starting.html#--\">--</a> (insert) --\" is
			shown at the bottom of the <a href=\"http://vimdoc.sourceforge.net/htmldoc/windows.html#window\">window</a>.

<a href=\"http://vimdoc.sourceforge.net/htmldoc/insert.html#Insert\">Insert</a> <a href=\"http://vimdoc.sourceforge.net/htmldoc/visual.html#Visual\">Visual</a> mode	Entered when starting a <a href=\"http://vimdoc.sourceforge.net/htmldoc/visual.html#Visual\">Visual</a> selection from <a href=\"http://vimdoc.sourceforge.net/htmldoc/insert.html#Insert\">Insert</a>
			mode, e.g., by using <a href=\"http://vimdoc.sourceforge.net/htmldoc/motion.html#CTRL-O\">CTRL-O</a> and then \"<a href=\"http://vimdoc.sourceforge.net/htmldoc/visual.html#v\">v</a>\", \"<a href=\"http://vimdoc.sourceforge.net/htmldoc/visual.html#V\">V</a>\" or
			<a href=\"http://vimdoc.sourceforge.net/htmldoc/visual.html#CTRL-V\">CTRL-V</a>.  When the <a href=\"http://vimdoc.sourceforge.net/htmldoc/visual.html#Visual\">Visual</a> selection ends, Vim returns
			to <a href=\"http://vimdoc.sourceforge.net/htmldoc/insert.html#Insert\">Insert</a> mode.
			If the <a href=\"http://vimdoc.sourceforge.net/htmldoc/options.html#%27showmode%27\">\'showmode\'</a> option is on \"<a href=\"http://vimdoc.sourceforge.net/htmldoc/starting.html#--\">--</a> (insert) VISUAL --\"
			is shown at the bottom of the <a href=\"http://vimdoc.sourceforge.net/htmldoc/windows.html#window\">window</a>.

<a href=\"http://vimdoc.sourceforge.net/htmldoc/insert.html#Insert\">Insert</a> <a href=\"http://vimdoc.sourceforge.net/htmldoc/visual.html#Select\">Select</a> mode	Entered when starting <a href=\"http://vimdoc.sourceforge.net/htmldoc/visual.html#Select\">Select</a> mode from <a href=\"http://vimdoc.sourceforge.net/htmldoc/insert.html#Insert\">Insert</a> mode.
			E.g., by dragging the mouse or <a href=\"http://vimdoc.sourceforge.net/htmldoc/motion.html#%3CS-Right%3E\"><S-Right></a>.
			When the <a href=\"http://vimdoc.sourceforge.net/htmldoc/visual.html#Select\">Select</a> mode ends, Vim returns to <a href=\"http://vimdoc.sourceforge.net/htmldoc/insert.html#Insert\">Insert</a> mode.
			If the <a href=\"http://vimdoc.sourceforge.net/htmldoc/options.html#%27showmode%27\">\'showmode\'</a> option is on \"<a href=\"http://vimdoc.sourceforge.net/htmldoc/starting.html#--\">--</a> (insert) SELECT --\"
			is shown at the bottom of the <a href=\"http://vimdoc.sourceforge.net/htmldoc/windows.html#window\">window</a>.
\"Reblog

author

Authored By Amit Agarwal

Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now
This website uses cookies to ensure you get the best experience on our website. Learn more Got it