Vim Commands Mac



Vim is a text editor that has been around for ages and is fairly popular among the coders and advanced users. In this article, we will be taking a look at some of the most popular and useful Vim commands.

  1. Vim Editor Commands Mac
  2. Vim Common Commands
  3. Vim Commands List

Vim features two distinct modes, a command mode and an insert mode. When you open Vim for the first time, you’re in the command mode. The command mode lets you navigate the screen, delete and copy text, among many others. The insert mode, on the other hand, as implied, lets users insert text into Vim’s console. Vim recognizes three file formats (unix, dos, mac) that determine what line ending characters (line terminators) are removed from each line when a file is read, or are added to each line when a file is written. A file format problem can display ^M characters, or can prevent scripts from running correctly. This tip explains how to avoid problems, and how to convert from one file format to. You can open up Terminal on your Mac (perhaps by opening Spotlight on your Mac with Command⌘-Space key combination and type “Terminal”. Traverse to a folder you want to work in (documents will do.

Defining itself as “the ubiquitous text editor”, Vim is not something that the average computer user is likely to run everyday. However, it has a very loyal user base and comes loaded with a good set of features. As such, it is worth the effort to take a moment and first familiarize ourselves with the Vim editor itself.

What is Vim?

In simple words, Vim is a text editor. It is the successor to the Vi editor, and has been around ever since the 1970s. In fact, for several decades, Vim was the default text editor of choice on most UNIX operating systems, including popular Linux distros and certain Apple devices.

Vim Editor Commands Mac

Of late, Vim has found itself falling out of favor. This is primarily due to the advent of newer text editors to the scene, such as gedit on Linux. Plus, modern code editors such as Atom can also fill in as a text editor when needed without causing too much of a strain on memory resources. Not a Vim user? Why not check out our list of awesome Brackets extensions?

Vim editor command

That said, Vim still continues to be a popular text editing option. It is highly configurable and easily adaptable. While Vim is probably not the most eyecandy editor out there, it makes up for its less enticing appearance by providing a wide range of features.

Consider, for example:

  • Memory-persistent, multi-level undo feature
  • Support for various file formats and extensions, including several programming languages
  • An extensive plugin repository to get the most out of the Vim text editor
  • Integration with custom tools, as well as standard text editing features such as Find and Replace.

All such features, put together, make Vim a robust and reliable text editor. This is especially why it has been around for several years now — Vim is a simple yet powerful tool that just gets the job done.

How to Work with Vim?

Now that we have established what all Vim can bring to the table, the obvious question arises — how do we get it?

For a start, the first step is to download and install Vim. The installation process is fairly straightforward. As far as the download goes, Vim is a totally free and open source software. Windows users can grab the latest version from the official website here. Mac users, on the other hand, can find the respective version from this repository.

Most Linux distros tend to bundle Vim as an alternative text editor nowadays. It might be a good idea to search for Vim in the distro’s repository itself, if your Linux machine does not have it installed already.

With that out of the way, Vim needs a fair amount of getting used to, before you can actually master its interface.

Vim has 12 different editing modes. Yes, you read that right — most editors tend to have just one mode (that is, “editing”). There are 6 basic modes, and the other six modes are just variations of the same.

The six basic Vim modes are as follows:

  • Normal Mode: The default mode that is used for editor commands.
  • Visual Mode: Similar to Normal Mode, but generally used to visually “select” and highlight chunks of text or code.
  • Select Mode: Operates in a similar fashion to Visual Mode.
  • Insert Mode: Used for editing; identical to the default workflow of modern text editors.
  • Command Line Mode: As the name suggests, this is the CLI mode.
  • Ex Mode: Similar to Command Line Mode, except that in Ex Mode, a single line of CLI input does not cause the command line to exit.

The Normal Mode is the default mode in which Vim starts. As such, it is also referred to as the Command Mode (not to be confused with the Command Line Mode though).

Introducing: Vim Commands

Now, as we discussed earlier in this post, Vim is not your everyday run of the mill text editor. Instead, it is more geared towards coders and power users. As such, it comes loaded with a wide array of custom keyboard commands that can make life easier for its users.

In fact, in order to truly get the max out of Vim, it is almost essential to have a certain degree of familiarity and experience with Vim commands. So let us now take a look at some of the most useful Vim commands that we can use with this awesome text editor.

However, before that, we need to ask the big question: how do we use the keyboard commands in Vim?

In order to type Vim commands, we need to be in the Command or Normal Mode. Vim starts in this mode itself by default, or we can just press the Esc key to reach Command Mode.

Once in the Command Mode, we can input any Vim command as per our needs. In order to type text, we will need to be in Insert Mode, which can be achieved by pressing the i key in the Command Mode.

And now, on to Vim commands!

Basic Vim Commands

First up, let us discuss the most basic Vim commands.

CommandInformation
:e myfileOpens “myfile” for editing
:wSave the file
:sav myfile.txtSaves the file as myfile.txt
😡Write changes to file and exit
:q!Quit without saving changes
:qQuit Vim

Find and Replace Vim Commands

Every text editor has the Find and Replace feature nowadays, and Vim is no exception. Here are the Vim commands for the same:

CommandInformation
/xyzSearch xyz from top to bottom
?xyzSearch xyz from bottom to top
*Search the text that is under cursor
/ctextSearch for text (case-insensitive)
/ra[av]iSearch for raai or ravi
/abc|xyzSearch for abc or xyz
/<dddd>Search for exactly 4 digits
/^n{3}Search for 3 empty lines
:bufdo /searchstr/Search in all open files globally
bufdo %s/findme/replaceme/gSearch findme in all the open buffers and replace it with replaceme
:%s/x/y/gReplace all occurrences of x by y in file
:%s/qwerty/ytrewq/giReplace qwerty by ytrewq, case-insensitive
:%s/x/y/gcReplace all occurrences after confirmation
:%s/^/Begin/gReplace the beginning of each line by Begin
:%s/$/End/gReplace the ending of each line by End
:%s/x/y/giReplace x by y, case-insensitive
:%s/ *$//gSearch and delete all white spaces
:g/myname/dSearch and delete all lines containing myname
:v/myname/dDelete all lines not containing myname
:s/John/Doe/Replace the first occurrence of John by Doe in current line
:s/John/Doe/gReplace John by Doe in current line
:%s/John/Doe/gReplace John by Doe in all files
:%s/^M//gSearch and delete DOS carriage returns (^M)
:%s/r/r/gReplace DOS carriage returns with regular return key
:%s#<[^>]+>##gSearch and delete HTML tags but keep text
:%s/^(.*)n1$/1/Search and delete duplicate lines
Ctrl+aIncrements number under the cursor
Ctrl+xDecrements number under cursor

Vim Commands for Cut, Copy and Paste

Just like Find and Replace, Cut, Copy and Paste too is a common feature. Vim commands to work with cut/copy and pasting of text can be found below:

CommandInformation
yCopy the selected text
pPaste the selected text
ddCut the current line
yyCopy the current line
y$Copy to EOL
DCut to EOL

Vim Commands to Change Case

These are Vim commands that can help us change the case of text, such as uppercase to lowercase, or vice versa.

CommandInformation
VuLowercase the entire line
VUUppercase the entire line
g~~Invert selected case
vEUSwitch selected word to uppercase
vE~Modify the current word case
ggguGSet all text to lowercase
gggUGSet all text to uppercase
:set ignorecaseIgnore case when searching text
:set smartcaseIgnore case in search, but not if an uppercase letter is used
:%s/<./u&/gSets the first letter of each word to uppercase
:%s/<./l&/gSets the first letter of each word to lowercase
:%s/.*/u&Sets the first letter of each line to uppercase
:%s/.*/l&Sets the first letter of each line to lowercase

Navigation within the File

Vim Commands given in the below table help us smoothly navigate within the opened file.

CommandInformation
k or Up ArrowMove the cursor position up one line
j or Down ArrowMove the cursor down one line
eMove the cursor to the end of the word
bMove the cursor to the beginning of the word
0Move the cursor to the beginning of the line
GMove the cursor to EOF
ggMove the cursor to the beginning of the file
LMove the cursor to the bottom of the screen
:80Move the cursor to line number 80
%Move the cursor to matching parenthesis
[[Move the cursor to function start
[{Move the cursor to block start

File R/W and File Explorer

What good is a text editor that cannot read/write files properly? Vim comes with its own File Explorer that can help us access the files on our disk in no time. Here are some handy file-related Vim commands.

CommandInformation
:1,10 w myfileSaves lines 1 to 10 in myfile
:1,10 w >> myfileAppends lines 1 to 10 to myfile
:r myfileInserts the content of myfile to current file
:23r myfileInserts the content of myfile under line 23
:e .Open the File Explorer
:SexSplit window and open File Explorer
:Sex!Same as :Sex but splits window vertically
:browse eGraphical File Explorer
:lsList buffers
:cd ..Move to parent or root directory
:argsList files
:args *.phpOpen file list with .php extension
:grep something *.phpReturns list of .php files containing something
gfOpen file name under cursor

Interface-Related Vim Commands (Tabs and Windows)

Need to split the window into two? Open a new tab or work with multiple tabs? Yes, Vim supports it all, and has custom Vim commands for such interface-related operations.

CommandInformation
:tabnewOpens a new tab
gtGo to next tab
:tabfirstGo to first tab
:tablastGo to last tab
:tabm n(position)Rearrange open tabs
:tabdo %s/foo/bar/gExecute same command in all tabs
:tab ballPuts all open files in different tabs
:new myfile.txtEdit myfile.txt in new window
:e filenameEdit filename in current window
:split myfileSplit the window and open myfile
ctrl-w + Up arrowPuts cursor in top window
ctrl-w ctrl-w (twice)Puts cursor in next window
ctrl-w_Maximize current window vertically
ctrl-w|Maximize current window horizontally
ctrl-w=Make all windows of the same size
100 ctrl-w+Add 100 lines to file in current window
:vsplit fileSplit windows vertically
:sview fileSplit windows vertically (read-only)
:hideClose current window
:­nlyClose all windows, except the current
:b 4Open tab #4 in current window

Text Alignment and Indentation

To indent or align text in Vim, following commands can be used:

CommandInformation
:set autoindentTurn on auto-indentation
:%!fmtAlign all the lines
!}fmtAlign all lines at the current position
2!!fmtAlign the next two lines
:set smartindentTurn on smart auto-indentation
:set shiftwidth=8Defines 8 spaces as indent size
ctrl-t, ctrl-dIndent and un-indent in Insert Mode
>>Indent the current line
<<Un-indent the current line
=%Indent the code between parenthesis
1GVG=Indent the entire file

Autocomplete Vim Commands

To autofill or autocomplete text, Vim has a few commands of its own.

CommandInformation
Ctrl+n Ctrl+pComplete the suggested word (Insert Mode)
Ctrl+x Ctrl+lComplete the suggested line
:set dictionary=enDefine en as active dictionary
Ctrl+x Ctrl+kComplete with the active dictionary

UNIX-Only Vim Commands

Vim comes with certain commands that can be used only on a UNIX environment. This implies the following commands can be used on Linux computers, or Mac, but sadly not on Windows.

CommandInformation
:!getExecute the get Unix command, then return to Vim
!!getExecute the get Unix command and insert output in current file
:shReturn to Unix shell
$exitExit the Unix shell and return to Vim

It is also worth noting, by the way, that Vim is not exclusive to desktop machines. Vim can be used on any web hosting server, and be accessed via SSH as well. This is why Vim has specialized Vim commands for UNIX machines as the vast majority of web hosting servers are running Linux/UNIX operating systems.

Miscellaneous Vim Commands

And now, let us look at some misc Vim commands as well:

CommandInformation
m {q-p}Marks the current position as {q-p}
‘ {q-p}Move to position {q-p} (used after marking)
Move to previously marked position
:ab mail hi@designbombs.comDefine mail as abbreviation of hi@designbombs.com

Conclusion

And that brings us to the end of this post about Vim commands. If you are a Vim power-user, which Vim commands do you use the most? More importantly, which Vim commands are the most useful for saving time and boosting productivity? Share your views in the comments below!

Vim is available for many different systems and there are several versions.This page will help you decide what to download.Most popular:
MS-Windows:Click this link to download the self-installing executable(using ftp).
Signed MS-Windows files are available on thevim-win32-installer site(gvim_8.2.0012_x86_signed.exe is recommended)
Unix:See the GitHub page, or Mercurial, if you prefer that.There is also anAppimagewhich is build daily and runs on many Linux systems.
Mac:See the MacVim project for a GUI version and Homebrew for a terminal version

Details and options for:

MirrorsAlternative sites to download Vim files from.
SourcesBuild Vim yourself and/or make changes.
GitHubObtain Vim sources with a git client (recommended).
MercurialObtain Vim sources with a Mercurial client(recommended if you don't like git).
PatchesInclude the latest improvements (requires sources and rebuilding).
RuntimeGet the latest syntax files, documentation, etc..
Script linksLinks to individual syntax, indent, color, compiler and ftplugin scripts.
TranslationsNon-English documentation packages.

Versions before 7.3 can also be obtained withSubversionandCVS.Vim 8.2 is the latest stable version. It is highly recommended, many bugs have been fixed since previous versions.If you have a problem with it (e.g.,when it's too big for your system), you could try version 6.4 or 5.8 instead.

To avoid having to update this page for every new version, there arelinks to the directories. From there select the files you want to download.In the file names ## stands for the version number. For example,vim##src.zipwith version 8.2 is vim82src.zip andvim-##-src.tar.gz for version 8.2is vim-8.2-src.tar.gz.Links are provided for quick access to the latest version.
Note that the links point to the latest version (currently 8.2) to avoidthat caching causes you to get an older version.

CommandsThe best way to install Vim on Unix is to use the sources. This requires acompiler and its support files. Compiling Vim isn't difficult at all.You can simply type 'make install' when you are happy with the defaultfeatures. Edit the Makefile in the 'src' directory to select specificfeatures.

You need to download at the sources and the runtime files.And apply all the latest patches.For Vim 6 up to 7.2 you can optionally get the 'lang' archive, which adds translated messages and menus. For 7.3 and later this is included with the runtime files.

Using git
This is the simplest and most efficient way to obtain the latest version, including all patches. This requires the 'git' command.
MacThe explanations are on the GitHub page.

Summary:

Using Mercurial
This is another simple and most efficient way to obtain the latest version, including all patches. This requires the 'hg' command.
The explanations are on this page:Mercurial

Summary:

version 7.x and 8.x
There is one big file to download that contains almost everything.It is found inthe unix directory(ftp):
The runtime and source files together:vim-##.tar.bz2vim-8.2.tar.bz2 (ftp)
The files ending in '.tar.gz' are tar archives that are compressed with gzip.Unpack them with tar -xzf filename.
The single big file ending in '.tar.bz2' is a tar archive compressed withbzip2. Uncompress and unpack it withbunzip2 -c filename | tar -xf -.
All archives should be unpacked in the same directory.

If you can't compile yourself or don't want to, look at the site of thesupplier of your Unix version for a packaged Vim executable. For Linuxdistributions and FreeBSD these are often available shortly after a new Vimversion has been released. But you can't change the features then.

  • Debian packages are available at:http://packages.debian.org/vim.
  • Sun Solaris Vim is included in the Companion Software:http://wwws.sun.com/software/solaris/freeware/.
    Vim for other Sun systems can be found athttp://sunfreeware.com/.
  • HPUX with GTK GUI for various HPUX versions:http://hpux.its.tudelft.nl/hppd/hpux/Editors/vim-6.2/ orhttp://hpux.connect.org.uk/hppd/hpux/Editors/vim-6.2/ (note that the remark about the GNU GPL is wrong)
For modern MS-Windows systems (starting with XP) you can simply use the executable installer:
gvim82.exe (ftp)
It includes GUI and console versions, for 32 bit and 64 bit systems.You can select what you want to install and includes an uninstaller.

If you want a signed version you can get a build from
vim-win32-installer
It supports many interfaces, such as Perl, Tcl, Lua, Python and Ruby.There are also 64bit versions which only run on 64 bit MS-Windows and use alot more memory, but is compatible with 64 bit plugins.
You can also get a nightly build from there with the most recent improvements,with a small risk that something is broken.

Since there are so many different versions of MS operating systems, there areseveral versions of Vim for them.
For Vim 5.x, Vim 6.x and Vim 7 look inthe pc directory (ftp).

Self-installing executable gvim##.exe gvim82.exe (ftp)
For Vim 6 and later. This includes a GUI versionof Vim - with many features and OLE support - and all the runtime files.It works well on MS-Windows 95/98/ME/NT/2000/XP/Vista/7.Use this if you have enough disk space and memory. It's the simplest way tostart using Vim on the PC. The installer allows you to skip the parts youdon't want.
For Vim 6.3 and later it also includes a console version, both for MS-Windows 95/98/ME and MS-Windows NT/2000/XP/Vista/7. The installer automatically selects the right one.
Runtime files vim##rt.zip vim82rt.zip (ftp)
For all the following binary versions you need this runtime archive, whichincludes the documentation, syntax files, etc. Always get this, unless youuse the self-installing executable.

There are three versions that run as an MS-Windows application. These providemenus, scrollbars and a toolbar.

GUI executable gvim##.zip gvim82.zip (ftp)
This is the 'normal' GUI version.
OLE GUI executable gvim##ole.zip gvim82ole.zip (ftp)
A GUI version with OLE support. This offers a few extra features,such as integration with Visual Developer Studio. But it uses quite a bitmore memory.
There are three versions that run on MS-DOS or in a console window inMS-Windows:
Win32 console executable vim##w32.zip vim82w32.zip (ftp)
The Win32 console version works well on MS-Windows NT/2000/XP/Vista/7. It supports long file names and is compiled with 'big' features. It does not runperfectly well on MS-Windows 95/98/ME, especially when resizing the consolewindow (this may crash MS-Windows...).
32 bit DOS executable vim##d32.zip vim73_46d32.zip (ftp)
The 32 bit DOS version works well on MS-Windows 95/98/ME. It requires a DPMImanager, which needs to be installed on MS-DOS. MS-Windows already has one.It supports long file names, but NOT on MS-Windows NT/2000/XP/Vista/7. It is compiled with 'big' features.
Not available for 7.4 and later.
16 bit DOS executable vim##d16.zip vim71d16.zip (ftp)
The 16 bit DOS version is the only one that runs on old MS-DOS systems. Onlyuse this if you are really desparate, because it excludes many useful features(such as syntax highlighting and long file names) and quickly runs out ofmemory.
The last version available is 7.1. Version 7.2 and later are too big to fit in the DOS memory model.
There are a few extra files:
iconv librarylibiconv
A library used for converting character sets.Put 'iconv.dll' in the same directory as gvim.exe to be able to edit files inmany encodings. You can find the dll file in the bin directory of the'libiconv-win32' archive.
newer intl librarylibintl
The included libintl.dll does not support encoding conversion.If you have installed the iconv library, as mentioned above, you can install agettext library that uses it.Get 'intl.dll' from the bin directory in the gettext-win32 archive and store itas 'libintl.dll' in the same directory as gvim.exe, overwriting the filethat may already be there.
PC sources vim##src.zip vim82src.zip (ftp)
The source files, packed for the PC. This only includes the files needed onthe PC, not for other systems. The files are in dos format CR-LF.
PC debug files gvim##.pdb gvim82.pdb (ftp) gvim##ole.pdb gvim82ole.pdb (ftp) vim##w32.pdb vim80w32.pdb (ftp)
When you notice a bug or a crash in Vim these files can be used to help tracing down the problem. In Vim 7 do ':help debug-win32' to see how.
PC translations vim##lang.zip vim72lang.zip (ftp)
Only for 7.2 and earlier, for 7.3 and later these are included in the 'rt' archive.Translated messages and menu files, packed for the PC. Use this to seenon-English menus. The messages are only translated when the libintl.dlllibrary is installed.
Windows 3.1 GUI executable gvim##w16.zip and gvim##m16.zip
These are GUI versions for 16 bit windows (Windows 3.1). The 'w16' has manyfeatures, 'm16' has few features (for when you're short on memory).
The files ending in '.zip' can be unpacked with any unzip program.Make sure you unpack them all in the same directory!

Alternate distributions

Yongwei's build
You may also try Yongwei's build,executables with slightly different interfaces supported.
Cream
For an unofficial version that used to include all the latest patches andoptionally a bitmore: Cream.The 'one-click installer' mentioned includes the Cream changes.For the 'real Vim' use the 'without Cream' version listed further down.
Unfortunately, it stopped updating since Vim 8.0.
Cygwin
For a Cygwin binary look at others.
Quite a long time ago, Vim development started on the Amiga. Although it's areally old system now, it might still work. However, this has not been tested recently.You may have to use an older version for which Amiga binaries are available.

For Vim 5.x and Vim 6 look inthe amiga directory (ftp).
Vim 7 files can be found atos4depot.net. This is for AmigaOS 4. Made by Peter Bengtsson.

Runtime files vim##rt.tgz vim64rt.tgz (ftp)
Documentation, syntax files, etc. You always need this.
Executable vim##bin.tgz vim64bin.tgz (ftp)
The executables for Vim and Xxd.For Vim 6 it includes 'big' features, for Vim 5.x itincludes the normal features.For Vim 6.2 it is not available (my Amiga had harddisk problems then, this miraculously healed later).
Big executable vim##big.tgz
Vim with 'big' features and Xxd. Only for Vim 5.x.
Sources vim##src.tgz vim64src.tgz (ftp)
The source files for the Amiga.Only needed when you want to compile Vim yourself.
The files are all tar archives, compressed with gzip. To unpack, firstuncompress them with gzip -d filename. Then unpack withtar xf filename. You need to unpack the archives in the samedirectory.The OS/2 version runs in a console window.

For Vim 5.x and Vim 6 look inthe os2 directory (ftp).Version 6.2 is not available.Versions 6.3 and 6.4 were compiled by David Sanders.
Version 7.0 was compiled by David Sanders.

Runtime files vim##rt.zip vim70rt.zip (ftp)
Documentation, syntax files, etc. You always need this.
Executables vim##os2.zip vim70os2.zip (ftp)
Vim, Xxd, Tee and EMX libraries.
The files ending in '.zip' can be unpacked with any unzip program.Make sure you both zip archives in the same directory!

If you want to compile the OS/2 version, you need the EMX compiler. Use theUnix source archive, runtime files and the extra archive. After unpacking theruntime archive, move all the files and directories in the 'runtime'directory one level up.

The terminal version of Vim is included as 'vi', you already have it. It'slagging behind a bit though and has limited features, thus you may want toadditionally install a recent version or one with more features.

MacVim

There most popular version is MacVim. This is being actively developed. Thisbehaves like a Mac application, using a GUI.

MacVim has more a Mac look and feel, is developed actively and most peopleprefer this version. Most of MacVim was made by Björn Winckler.

MacVim can be downloaded here: https://github.com/macvim-dev/macvim

New versions are made quite often.Subscribe to thevim-mac maillistto be informed about bugs and updates.

Homebrew

This is a terminal version installed with the 'brew' command.It is updated frequently.It can be downloaded here: formulae.brew.sh/formula/vim.

Older

Older binaries for Mac OS/X can be found on thisSourceForge project.Maintained by Nicholas Stallard.

Here is a multi-byte version of Vim 5.7 (for Japanese, possibly also forKorean and Chinese; not for Unicode):
http://www-imai.is.s.u-tokyo.ac.jp/~asai/macvim-e.html

Vim

Background

Vim Common Commands

Most of the work forthe Macintosh port (Classic and Carbon) was done by Dany St-Amant.

If you have OSX and a setup for compiling programs, you can use the source codeand compile yourself. See the Unix section above. The development tools can bedownloaded from Apple's developer web site.

Turn to the vim-mac maillist to meet otherVim-Mac users.

Vim Commands List

This is a list of links to sites where various versions of Vim can be obtained.These are supported by individuals, use at your own risk.
Android Search for 'Vim Touch' by Momodalo in the Play Store.
i/OS Run Vim on your iPhone or Ipad.
QNX (ftp) Provided by Yakov Zaytsev. Requires QNX 6.3.0/6.3.2 with service pack 2.
Agenda http://pi7.fernuni-hagen.de/hartrumpf/agenda/vim/vim.vr3
Cygwin (with GTK GUI) http://lassauge.free.fr/cygwin/
Open VMS http://www.polarhome.com/vim/
MorphOS http://www.akcaagac.com/index_vim.html

TOP