Vim Gui Mac



Run a 100 FPS GPU-rendered Vim With macOS Hot Keys, Shared Copy & Paste, Remote Collaboration, Session Save/Resume, Crash Recovery, and More

By following the hot keys setup in this article, we can make terminal Vim/Neovim feel just like any native app, or working in an editor like VS Code. You’ll be able to use Vim in iTerm2, Kitty, or Alacritty—or your terminal of choice—while still keeping your standard hot keys for copy, paste, switching tabs (this guide will focus on binding command key, but you can substitute with control key.) By running your Vim in a terminal, you get features like collaborative editing for free (through Teleconsole).

Pair it with my recommended Vim config for a fully loaded yet blazing fast IDE experience:

If you are using vim in MAC OSX, unfortunately it comes with older verion, and not complied with clipboard options. Luckily, homebrew can easily solve this problem. Install vim: brew install vim. Install gui verion of vim: brew install macvim. Restart the terminal to take effect. Append the following line to /.vimrc set clipboard=unnamed.

  • The original vim (checkout from vim official Subversion repository) only provides a Classic/Carbon based GUI for Mac OS X users, it lacks some important features and does not give us the best GUI experiences.
  • マルチウインドウが使えるMac OS XアプリケーションのVim(gVim)です。GUIを担当するMacVimと、Vim本体から構成されています。Vim本体はコンソールアプリケーションとしても使用できます。 香り屋版.
  • Vim - the text editor - for macOS. Contribute to macvim-dev/macvim development by creating an account on GitHub.
  • Since version 8.1.224 I am unable to build Vim.app due to the following error: guimac.c: In function 'myDataBrowserChangeAttributes': guimac.c:6615: warning.
  • Lightning-fast 100 FPS GPU-rendered Vim (via Kitty) that’s still easy on your processor and battery
  • Full mouse support: switch tabs by clicking, click on menu items, select text, etc.
  • Full standard OS hot keys: CMD+C/V to copy and paste, CMD+T for new tab, CMD+W to close tab, CMD+{ or } to switch tabs, etc. (whoever told you that you can’t map the command (⌘ CMD) key in regular VIM was wrong!)
  • Code hints, auto complete, syntax and code linting, type and method signatures—all as you type
  • Super fast project-wide file search and even text/symbol search
  • Save and resume sessions, even on crashes
  • Live synced editor for remote collaboration (via Teleconsole)
  • And much more!


Running Vim in the terminal opens you up to the terminal ecosystem, including tools like TMUX or Teleconsole, which lets you share your terminal session with a remote user for real-time live collaboration. It’s also one less app to open.

You can either bring Vim to VS Code or bring VS Code to Vim. I’ve found Vim emulation in VS Code to be too slow and unresponsive. But most importantly, I lose out on the Vim plugin ecosystem. Getting most of the VS Code features in Vim is actually quite easy. It’s a well covered topic. You can install a fully configured Vim setup like Spacevim (or even Spacemacs), or install the individual plugins yourself using a plugin manager like vim-plug (easier) or dein.vim (harder) and configure your vimrc file to suit your exact needs. If you want something lighter and easier to customize, you can try using my vim config that’s already configured with the features mentioned above. Clone it and make it your own (that’s what did from the last guy).

The rest of the guide will mainly be about making Vim/Neovim feel like a native dedicated app by running it in a blazing fast terminal emulator called Kitty with configured hot keys.

  • Setting up Vim or Neovim to run inside TMUX (optional) running in Kitty, a wicked-fast GPU powered terminal.
  • Making hot keys work in Kitty just like in the rest of your OS. CMD+C or V, CMD+W, CMD+{ or } tab switching, etc.
  • Making those same hot keys work in iTerm2 and other terminals like Alacritty
  • Fully resumable sessions—even on computer reboots or system crashes!

Introducing GeoVim: Running (Neo)Vim in Kitty

Install Kitty, a Hyper-Fast GPU Powered Terminal

Kitty can be launched with the special key profile we’ll be using so it doesn’t interfere with your regular terminal activities. If you plan to just use iTerm2, you can skip this section and just grab the GeoVim key profile config for your terminal. I’m calling my Neovim inside Kitty setup “GeoVim.” Kitty is a super-fast terminal emulator that uses your GPU to render at 100 FPS (configurable based on your needs). Kitty is fast. The speed I’m talking about is not how fast it prints text on the screen, but how responsive the feedback is on screen. On a standard 60hz inch Macbook screen typing is noticeably more responsive than iTerm2. The effect is even more noticeable if you try to scroll up and down really fast. Humans do not need to consciously perceive fast refresh rates in order to benefit from them. You can maximize the responsiveness by using it with a 144hz monitor. The developer has claimed that his goals are still to keep the terminal energy and resource efficient though, something I will be thoroughly benchmarking in the future.

Install Kitty with Homebrew, which includes macOS GUI integration out of the box.

Clone Repo or Grab GeoVim Files

Linux Users: Linux support is untested, but should work.
Make sure to install ruby and tmux (if you want tmux enabled).

Either clone my Neovim repo into ~/.config/nvim, or just grab the folder below and place it somewhere. I recommend placing it in ~/.config/geovim if you don’t plan on using my Vim config.

GeoVim files: https://github.com/chrischen/vim-config/tree/master/geovim

Add this to your .zshrc or .bashrc, and modify GEOVIM_PATH accordingly.

The gvim command now lets you open somefile.txt and have Kitty -> TMUX -> Vim open up automatically with the file you specified.

You can also switch out Kitty for Alacritty. Open launch_geovim.sh to change the options:

Install NeoVim

I highly recommend Neovim instead of regular Vim 8, as I’ve found some UI blocking behavior happens when typing with live code completion and syntax checking. It’s mostly a drop-in replacement so if you want to use Vim you still can. It may just be better plugins, but in Neovim I’ve never encountered any freezing while typing. Neovim does have a bug when scrolling, but only if you scroll really really fast.

Getting Command and Control Hot Keys to Work

Vim

Getting Vim to receive and use special keys like Command and Control key will require getting the terminal to send custom key sequences and Vim to receive and map those sequences.

Configuring Kitty to Send macOS Custom Hot Keys

The GeoVim launcher script will use the bundled Kitty config file. These are preconfigured for standard macOS shortcuts, so you’ll need to edit the file if you want to change the key bindings. The config file is located at geovim/conf/kitty.conf. These keybindings will only be used in your GeoVim instance, so if you plan on using Kitty as your terminal, they won’t interfere with standard hot keys for your terminal shell.

Linux users: replace with your preferred hotkey instead of Command. Cmd should map to the Windows key though. If you plan to use the Kitty as your primary terminal, it also has a handy Ctrl+C smart mode that operates as both interrupt and copy. You’ll want to put those key bindings in ~/.config/kitty/kitty.conf instead.

Configuring Alacritty to Send macOS Custom Hot Keys

Alacritty is also a GPU-powered terminal emulator. It’s barebones, and does not have features like tabs, windows, or any UI apart from the terminal window itself. TMUX is required to make it practical. It’s an alternative to Kitty, but I’ve found Kitty to feel more responsive and be better adapted to our setup (for example, shift+select with mouse doesn’t work in Alacritty).

The GeoVim launcher will also take care of loading hot key configs for Alacritty. But if you use Linux you may want to remap the Command key to Ctrl or something else. Just open geovim/conf/alacritty.yml and edit the key_bindings: section.

If you want to bind other custom keys, try using xxd -psd in your terminal to get the hex codes. You can also use Key Codes.app, type Ctrl+V in your terminal followed by the key combo, or run cat and then type your key combo. Certain key combos won’t work this way, such as Ctrl+C, but if I type Ctrl+V followed by Ctrl+Shift+(up arrow key) I’d get ^[[1;6A which is the escape sequence to use. ^[ is the ESC (hex 0x1b) key (which is the same as pressing Ctrl+[), followed by a string of [1;6A. This is sent by the terminal as sequential key presses.

Mvim

Configuring iTerm2 to Send macOS Custom Hot Keys

iTerm2 has a nifty automatic profile switching feature that allows it to activate our custom key bindings only if Vim or Neovim is open, so it won’t interfere with your normal shell usage. If you aren’t using TMUX with this setup, you may want to edit the profile in iTerm2 to not trigger when TMUX is run. You can edit this in Advanced -> Automatic Profile Switching after loading the profile. Because the profile can be automatically activated, you won’t need to use the GeoVim launcher for Vim in iTerm2.

Note: my default config overrides new tab/switch tab hot keys to work in the Vim window. If you don’t want that, make sure to delete or re-map the Cmd+T and Cmd+Shift+[ or ] hot keys.

Load The iTerm2 Profile

Grab the iTerm2 profile from geovim/conf/iTerm2.json. In the menu bar click on iTerm2 -> Preferences and then click on the Profiles tab.

Receiving The Hot Keys In Vim

The next step is to take these key combos sent from your terminal and trigger the right actions in Vim. The Command <D-...> (“super” key) Vim key binding only works in MacVim. We still won’t be able to use it, but we’re getting around that by taking advantage of escape sequences.

In recent versions of terminal Vim you may notice that CMD+V may actually work—at least slightly. This is because your terminal is sending a bracketed paste. Vim still knows nothing of the command key, but is just handling a special string sent from the terminal app. Terminals actually send a string with an escape sequence surrounding your clipboard contents (sort of like HTML tags) which is parsed by Vim, or your shell, to trigger a paste action. This allows apps running in your terminal, such as Zsh, to know that this content is pasted, and treat it in special ways such as not executing it automatically.

However as of the time of this writing, there are still quirks to this behavior in Neovim which means we’ll have to re-implement this functionality to get it working perfectly. Plus, CMD+C copying still won’t work if you have mouse support enabled in Vim because text selection triggers a visual selection in Vim, preventing your terminal from highlighting it (you can still yank with y though).

Configuring Vim

Add the following to your ~/.vimrc or ~/.config/nvim/init.vim (neovim) config file.

Now when you press CMD+V Vim will will paste correctly whether in insert, visual, select, or command mode. CMD+C will trigger a yank, and CMD+A will select all. The goal is to mimic the behavior in GUI Vim like MacVim. You may also want add this to your .vimrc to sync your clipboard with your OS clipboard. The + clipboard register is shared between macOS and Vim. Disable it if you do not want copy or paste to replace the contents of the OS clipboard.

Add Your Own Custom Key Bindings

There are keybindings that work in GUI apps but not in terminal Vim, such as Ctrl+Enter. Most terminals won’t be able to distinguish between Enter and Ctrl+Enter. I’ve pre-added bindings for these modifiers if you want to use them.

Pro Tip: To figure out if your terminal is actually sending certain key combos to Vim, go in insert mode and press Ctrl+V, followed by your key combo. If it doesn’t seem to distinguish the added modifiers, you’ll need to define custom key sequences and receive them in Vim like above.

Install Obsession Vim Plugin For Tab State Save/Reload

Install https://github.com/tpope/vim-obsession using your preferred vim plugin manager. I recommend Vim-Plug (easier to use) or Dein (harder to use). No further configuration is necessary as the GeoVim launcher will take care of starting sessions.

Auto Saving and Resuming Sessions

TMUX is used to primarily allows us to open multiple Vim sessions rooted in different project directories without having to launch multiple instances of the terminal. It’s also remotely scriptable, which allows the launcher to do smart file opens (for example it will open a file in an existing project into a new Vim tab if the project is open). TMUX is optional, and can be disabled in launch_geovim.sh. If disabled, Vim sessions will still function (restoring your Vim tabs), but new files will have to be launched in separate terminal windows unless you open them from within Vim.

Install TMUX plugin manager if you haven’t already. If you are using Prezto, you’ll need to initialize plugins in .tmux.conf exactly as shown below, instead of what it tells you in the default instructions.

Configure TMUX

Add this to the end of your tmux.conf or tmux.conf.user file.

The TMUX plugins will periodically save the state of your TMUX windows, while vim-obsession will save your Vim tabs on changes (new tab, close tab, etc). The GeoVim launcher will automagically resume all the open files and terminals from your last session—even when you restart your computer or recover from a crash. You can manually save/restore your TMUX windows with the following key combos:

Save: Ctrl-A followed by Ctrl-S
Restore: Ctrl-A followed by Ctrl-R

If you disable TMUX, you can still get Vim session save/restore by manually triggering it. You only have to do this once in any given project directory as it will detect and read the created Session.vim on subsequent opens. Vim session tracking also needs to be turned on manually if you open a specific file to edit as ingvim someFile.ts as opposed to just launchinggvimwith no arguments. This is to prevent it from littering random directories with Vim session files.

Performance

I haven’t fully evaluated the energy impact of this setup yet. In a future post I will be reporting back on detailed energy consumption stats.

Collaborative Editing

Because Vim is now running inside the terminal, we can take advantage of utilities made for the terminal such as Teleconsole, which allows a remote user share control of your terminal and collaborate live. Now we have a VS Code style IDE with real time collaborative editing for free! Important: turn off TMUX or just run Vim by itself for this.

Vim works in an ordinary terminal, while gVim has a Graphical User Interface (GUI). It can do the same things and a few more. The GUI offers menus, a toolbar, scrollbars and other items. This chapter is about these extra things that the GUI offers.

    Table of contents

09.1Parts of the GUI

You might have an icon on your desktop that starts gvim. Otherwise, one of these commands should do it:

If this doesn't work you don't have a version of Vim with GUI support. You will have to install one first.

Vim will open a window and display file.txt in it. What the window looks like depends on the version of Vim. It should resemble the following picture (for as far as this can be shown in ASCII!).

The largest space is occupied by the file text. This shows the file in the same way as in a terminal. With some different colors and another font perhaps.

#The window title

At the very top is the window title. This is drawn by your window system. Vim will set the title to show the name of the current file. First comes the name of the file. Then some special characters and the directory of the file in parens. These special characters can be present:

-The file cannot be modified (e.g., a help file)
+The file contains changes
=The file is read-only
=+The file is read-only, contains changes anyway

If nothing is shown you have an ordinary, unchanged file.

#The menubar

You know how menus work, right? Vim has the usual items, plus a few more. Browse them to get an idea of what you can use them for. A relevant submenu is Edit/Global Settings. You will find these entries:

Toggle Toolbarmake the toolbar appear/disappear
Toggle Bottom Scrollbarmake a scrollbar appear/disappear at the bottom
Toggle Left Scrollbarmake a scrollbar appear/disappear at the left
Toggle Right Scrollbarmake a scrollbar appear/disappear at the right

On most systems you can tear-off the menus. Select the top item of the menu, the one that looks like a dashed line. You will get a separate window with the items of the menu. It will hang around until you close the window.

#The toolbar

This contains icons for the most often used actions. Hopefully the icons are self-explanatory. There are tooltips to get an extra hint (move the mouse pointer to the icon without clicking and don't move it for a second).

The 'Edit/Global Settings/Toggle Toolbar' menu item can be used to make the toolbar disappear. If you never want a toolbar, use this command in your vimrc file:

This removes the 'T' flag from the guioptions option. Other parts of the GUI can also be enabled or disabled with this option. See the help for it.

#The scrollbars

By default there is one scrollbar on the right. It does the obvious thing. When you split the window, each window will get its own scrollbar.

You can make a horizontal scrollbar appear with the menu item Edit/GlobalSettings/Toggle Bottom Scrollbar. This is useful in diff mode, or when the wrap option has been reset (more about that later).

When there are vertically split windows, only the windows on the right side will have a scrollbar. However, when you move the cursor to a window on the left, it will be this one the that scrollbar controls. This takes a bit of time to get used to.

When you work with vertically split windows, consider adding a scrollbar on the left. This can be done with a menu item, or with the guioptions option:

This adds the 'l' flag to guioptions.

09.2Using the mouse

Standards are wonderful. In Microsoft Windows, you can use the mouse to select text in a standard manner. The X Window system also has a standard system for using the mouse. Unfortunately, these two standards are not the same.

Fortunately, you can customize Vim. You can make the behavior of the mouse work like an X Window system mouse or a Microsoft Windows mouse. The following command makes the mouse behave like an X Window mouse:

The following command makes the mouse work like a Microsoft Windows mouse:

The default behavior of the mouse on UNIX systems is xterm. The default behavior on a Microsoft Windows system is selected during the installation process. For details about what the two behaviors are, see :behave. Here follows a summary.

Vim Copy To Clipboard Mac

#Xterm mouse behavior

Left mouse clickposition the cursor
Left mouse dragselect text in Visual mode
Middle mouse clickpaste text from the clipboard
Right mouse clickextend the selected text until the mouse pointer

Vim Gui Mac Os

#MSWIN mouse behavior

Left mouse clickposition the cursor
Left mouse dragselect text in Select mode (see “Select mode”)
Left mouse click, with Shiftextend the selected text until the mouse pointer
Middle mouse clickpaste text from the clipboard
Right mouse clickdisplay a pop-up menu

The mouse can be further tuned. Check out these options if you want to change the way how the mouse works:

mousein which mode the mouse is used by Vim
mousemodelwhat effect a mouse click has
mousetimetime between clicks for a double-click
mousehidehide the mouse while typing
selectmodewhether the mouse starts Visual or Select mode

09.3The clipboard

In section “Using the clipboard” the basic use of the clipboard was explained. There is one essential thing to explain about X-windows: There are actually two places to exchange text between programs. MS-Windows doesn't have this.

In X-Windows there is the 'current selection'. This is the text that is currently highlighted. In Vim this is the Visual area (this assumes you are using the default option settings). You can paste this selection in another application without any further action.

For example, in this text select a few words with the mouse. Vim will switch to Visual mode and highlight the text. Now start another gvim, without a file name argument, so that it displays an empty window. Click the middle mouse button. The selected text will be inserted.

Gui Vim For Mac

The 'current selection' will only remain valid until some other text is selected. After doing the paste in the other gvim, now select some characters in that window. You will notice that the words that were previously selected in the other gvim window are displayed differently. This means that it no longer is the current selection.

You don't need to select text with the mouse, using the keyboard commands for Visual mode works just as well.

#The real clipboard

Now for the other place with which text can be exchanged. We call this the 'real clipboard', to avoid confusion. Often both the 'current selection' and the 'real clipboard' are called clipboard, you'll have to get used to that.

To put text on the real clipboard, select a few different words in one of the gvims you have running. Then use the Edit/Copy menu entry. Now the text has been copied to the real clipboard. You can't see this, unless you have some application that shows the clipboard contents (e.g., KDE's Klipper).

Now select the other gvim, position the cursor somewhere and use the Edit/Paste menu. You will see the text from the real clipboard is inserted.

#Using both

This use of both the 'current selection' and the 'real clipboard' might sound a bit confusing. But it is very useful. Let's show this with an example. Use one gvim with a text file and perform these actions:

  • Use the Edit/Copy menu to get these words onto the clipboard.

  • Use the Edit/Paste menu item. What will happen is that the single selected word is replaced with the two words from the clipboard.

  • Move the mouse pointer somewhere else and click the middle button. You will see that the word you just overwrote with the clipboard is inserted here.

If you use the 'current selection' and the 'real clipboard' with care, you can do a lot of useful editing with them.

#Using the keyboard

If you don't like using the mouse, you can access the current selection and the real clipboard with two registers. The '* register is for the current selection.

To make text become the current selection, use Visual mode. For example, to select a whole line just press V.

To insert the current selection before the cursor:

Notice the uppercase P. The lowercase p puts the text after the cursor.

Macvim Mvim

The '+ register is used for the real clipboard. For example, to copy the text from the cursor position until the end of the line to the clipboard:

Remember, y is yank, which is Vim's copy command.

To insert the contents of the real clipboard before the cursor:

It's the same as for the current selection, but uses the plus (+) register instead of the star (*) register.

09.4Select mode

And now something that is used more often on MS-Windows than on X-Windows. But both can do it. You already know about Visual mode. Select mode is like Visual mode, because it is also used to select text. But there is an obvious difference: When typing text, the selected text is deleted and the typed text replaces it.

To start working with Select mode, you must first enable it (for MS-Windows it is probably already enabled, but you can do this anyway):

Now use the mouse to select some text. It is highlighted like in Visual mode. Now press a letter. The selected text is deleted, and the single letter replaces it. You are in Insert mode now, thus you can continue typing.

Since typing normal text causes the selected text to be deleted, you can not use the normal movement commands hjkl, w, etc. Instead, use the shifted function keys. <S‑Left> (shifted cursor left key) moves the cursor left. The selected text is changed like in Visual mode. The other shifted cursor keys do what you expect. <S‑End> and <S‑Home> also work.

Gui Vim Osx

You can tune the way Select mode works with the selectmode option.