Exit Vim Mac



It looks like you're inside the vi editor. Typing:wq and pressing enter should do it, i.e. Save the commit message and exit.: enters the command mode, w is for 'write' (save) and q is for 'quit'. You may need to hit escape before:wq to exit the insert mode (vi is a mode based editor). If you want to exit without saving hit escape,:q! Git opens your default editor so you can edit. Apr 01, 2021 WayBack Exit Vim 2 Win shows the use of vim.js for a challenge. Source code at WayBack GitHub – idoco/exit-vim-2-win: Exiting vim eventually –jeroen.

I’m just about to install a crontab entry, and boom - I end up in the weird default editor. The one I never quite understood.

ESC? Nothing happens.

CTRL + C? No.

ESC ESC ESC? Nope. I’m stuck.

Not again. With my head down in shame, I’m resorting to opening another session just to killall vim to get on with my day.

Sound familiar? I don’t know about you, but I’ve been there. Until I decided to spend 10 minutes learning the very basics of Vim.

This post is your survival guide to the editor Vim. It’s not advanced, but enough to get you started and hopefully spark your interest in learning more.

Vim is shipped by default with many operating systems (including most Linux distributions and Mac OS X), so I suggest you take a proactive approach to learning it. Just launch a terminal and type ‘vim’ to get started.

With some learning, Vim can be more powerful than many graphical IDEs. And it certainly doesn’t eat hundreds of megs of memory just to view an empty file (looking at you, Eclipse).

The Basics

Some commands in this guide start with a colon: pressing it will display the command prompt where the subsequent command is written.

Vim

Commands without a colon are more like hotkeys - they can be used in the Vim default mode (which is the mode Vim starts in).

Commands written in CAPITAL LETTERS are specific keys: for example, ESC means the escape key on your keyboard.

All commands in Vim are case-sensitive.

Exiting Vim

To quit, discarding any changes you might have made:

Memorize: quit dammit!

To quit, saving any changes you’ve made:

Memorize: write to disk and quit

Navigating the editor

To move around the currently open file, use your arrow keys.

To move to line 285:

To search for the word import:

Mac

Editing text

To start inserting text on the current cursor location:

Memorize: insert

To start inserting at the end of the current line:

Exit Vim Mac Terminal

Memorize: Append

To exit insert mode, and return to the default mode:

Selecting text

To start selecting, enter the visual mode:

Memorize: visual

Select text by moving with your arrow keys.

To exit visual mode:

Cut, copy and paste

To copy the current selection into the buffer (think of it as a clipboard):

Memorize: yank

To cut the current selection:

Memorize: delete

To copy the current line into the buffer:

Memorize: yank yank

To copy 3 lines including the current line into the buffer:

To cut the current line and place it into the buffer:

Memorize: delete delete

To cut 5 lines including the current line:

To paste the buffer before the current line:

Note: Uppercase P

To paste the buffer after the current line:

Undo and redo

To undo the last change:

Memorize: uh-oh :)

To redo the last change you just undid:

To see the number of changes:

To undo the last two changes:

The Vim multi-level undo tree is very powerful. Read more about it here.

Opening files

To open the file index.html instead of the current one:

Saving files

To save the file you’re currently editing:

Mac

Memorize: write to disk

To save the file with a different name, here changes.txt (ie. Save As):

Searching and replacing

To search and replace all occurences of a string in the file:

To search and replace, but prompt before replacing:

Memorize: confirm

Syntax highlighting and Indentation

Turn on syntax highlighting:

Enable automatic indentation:

Increase indentation on multiple lines by selecting them in visual mode, and pressing:

Working with multiple files

Vim Exit Macro Recording

Tabs

To open server.py in a new tab:

Memorize: tab edit

To move to the next tab on the right:

Memorize: tab next

To move to the previous tab on the left:

Memorize: tab previous

To close a tab, move to it and use :q or :wq as you would normally.

Split view

To open templates/base.html in a vertical split screen:

Memorize: vertical split

To open shared.js in a horizontal split screen:

Memorize: the ‘default’ horizontal split

To move between split screens:

To close a split screen, move to it and use :q or :wq as you would normally.

Configuring Vim: the .vimrc

Many of the commands you use to change how Vim looks and behaves can be made default by placing them in the .vimrc. This is the Vim configuration file, and it lives in your home directory.

For example, placing this in ~/.vimrc will enable syntax highlighting and autoindentation by default:

Get some ideas for creating your dream .vimrc here.

More resources for life with Vim

Did I spark your interest? Great!

Here are some resources for you to continue learning:

  • Dalibor Nasevic’s 12 intermediate/advanced Vim tips
  • The official Vim wiki’s Best Vim Tips
  • Zzapper’s huge list of Vim tips

Releaseworks Academy has a free online training course on Docker & Jenkins best practices: https://www.releaseworksacademy.com/courses/best-practices-docker-jenkins

8th April 2010

I have had an annoying problem with git and vi. I like to use vim to edit my commit messages, but I’ve been hit with this annoying message every time I write the message and quit vim.

Exit Insert Mode Vim Mac

After a little bit of digging I found that this message is shown by git when the editor exits with a non-zero exit code. You can use $? to see the exit code of last script or application.

I’m still not sure why vim is exiting with non-zero exit code, but it is definitely related to my .vimrc - moving it to .vimrc.bak seemed to fix the problem. I’m using the excellent pathogen plugin to manage my vimfiles, so I plan to go through that and my installed plugins to find the cause of the problem.

There is a fix though, I’m not sure what’s causing this, but I found a post on the vim-mac mailing list which shows this:

Running vim with /usr/bin/vim seems to make it exit cleanly. So to fix the problem with git commit you just need to run this:

Exit Vim On Mac

I’d still like to get to the root of the problem, but this gets me my git commit messages back!