{"id":326,"date":"2020-05-05T06:02:00","date_gmt":"2020-05-05T06:02:00","guid":{"rendered":"https:\/\/www.instapainting.com\/blog\/?p=326"},"modified":"2020-07-17T23:17:29","modified_gmt":"2020-07-17T23:17:29","slug":"terminal-vim-with-command-control-hot-key","status":"publish","type":"post","link":"https:\/\/www.instapainting.com\/blog\/terminal-vim-with-command-control-hot-key\/","title":{"rendered":"GeoVim: Terminal Vim With GUI Hot Keys (Cmd\/Ctrl), VS Code Feature Parity, and Collaborative Editing"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Run a 100 FPS GPU-rendered Vim With macOS Hot Keys, Shared Copy &amp; Paste, Remote Collaboration, Session Save\/Resume, Crash Recovery, and More<\/h2>\n\n\n\n<figure class=\"wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"Turn Vim Into A Full GUI VS Code IDE Experience With Command Key Shortcuts And Remote Collaboration\" width=\"525\" height=\"295\" src=\"https:\/\/www.youtube.com\/embed\/GHwDEg3APho?list=PL9XS2sV-WKf_cl2VeG4Fn4dIs4yX6Hf2d\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><figcaption>What a fully loaded, hot-key enabled, but still lightning fast Vim setup looks like<\/figcaption><\/figure>\n\n\n\n<p>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&#8217;ll be able to use Vim in iTerm2, Kitty, or Alacritty\u2014or your terminal of choice\u2014while 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).<\/p>\n\n\n\n<p>Pair it with my recommended Vim config for a fully loaded yet blazing fast IDE experience:<\/p>\n\n\n\n<ul><li>Lightning-fast 100 FPS GPU-rendered Vim (via <a href=\"https:\/\/sw.kovidgoyal.net\/kitty\/\">Kitty<\/a>) that&#8217;s still easy on your processor and battery<\/li><li>Full mouse support: switch tabs by clicking, click on menu items, select text, etc.<\/li><li>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. <em>(whoever told you that you can&#8217;t map the command (\u2318 CMD) key in regular VIM was wrong!)<\/em><\/li><li>Code hints, auto complete, syntax and code linting, type and method signatures\u2014all as you type<\/li><li>Super fast project-wide file search and even text\/symbol search<\/li><li>Save and resume sessions, even on crashes<\/li><li>Live synced editor for remote collaboration (via Teleconsole)<\/li><li>And much more!<\/li><\/ul>\n\n\n\n<!--more-->\n\n\n\n<p>Running Vim in the terminal opens you up to the terminal ecosystem, including tools like TMUX or <a href=\"http:\/\/teleconsole.com\">Teleconsole<\/a>, which lets you share your terminal session with a remote user for <strong>real-time live collaboration<\/strong>. It&#8217;s also one less app to open. <\/p>\n\n\n\n<p>You can either bring Vim to VS Code or bring VS Code to Vim. I&#8217;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&#8217;s a well covered topic. You can install a fully configured Vim setup like <a href=\"https:\/\/spacevim.org\">Spacevim<\/a> (or even <a href=\"http:\/\/spacemacs.org\">Spacemacs<\/a>), or install the individual plugins yourself using a plugin manager like <a href=\"https:\/\/github.com\/junegunn\/vim-plug\">vim-plug<\/a> (easier) or <a href=\"https:\/\/github.com\/Shougo\/dein.vim\">dein.vim<\/a> (harder) and configure your vimrc file to suit your exact needs. If you want something lighter and easier to customize, <strong>you can try using <a href=\"https:\/\/github.com\/chrischen\/vim-config\">my vim config<\/a> that&#8217;s already configured with the features mentioned above.<\/strong> Clone it and make it your own (that&#8217;s what did from the last guy).<\/p>\n\n\n\n<p>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 <a href=\"https:\/\/sw.kovidgoyal.net\/kitty\/\">Kitty<\/a> with configured hot keys.<\/p>\n\n\n\n<ul><li>Setting up Vim or Neovim to run inside TMUX (optional) running in Kitty, a wicked-fast GPU powered terminal.<\/li><li>Making hot keys work in Kitty just like in the rest of your OS. <code>CMD+C<\/code> or <code>V<\/code>, <code>CMD+W<\/code>, <code>CMD+{<\/code>  or <code>}<\/code> tab switching, etc.<\/li><li>Making those same hot keys work in iTerm2 and other terminals like Alacritty<\/li><li>Fully resumable sessions\u2014even on computer reboots or system crashes!<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Introducing GeoVim: Running (Neo)Vim in Kitty<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Install Kitty, a Hyper-Fast GPU Powered Terminal<\/h3>\n\n\n\n<p><strong>Kitty can be launched with the special key profile we&#8217;ll be using so it doesn&#8217;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.<\/strong> I&#8217;m calling my Neovim inside Kitty setup &#8220;GeoVim.&#8221; Kitty is a super-fast terminal emulator that uses your GPU to render at 100 FPS (configurable based on your needs). Kitty is <em>fast<\/em>. The speed I&#8217;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. <a href=\"https:\/\/pavelfatin.com\/typing-with-pleasure\/\">Humans do not need to consciously perceive fast refresh rates in order to benefit from them<\/a>. 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.<\/p>\n\n\n\n<p>Install Kitty with Homebrew, which includes macOS GUI integration out of the box.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># macOS: use homebrew\nbrew cask install kitty\n\n# Ubuntu 18.10+: aptitude\nsudo apt install kitty<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Clone Repo or Grab GeoVim Files<\/h3>\n\n\n\n<p class=\"has-text-color has-background has-text-align-center has-very-dark-gray-color has-luminous-vivid-amber-background-color\"><strong>Linux Users<\/strong>: Linux support is untested, but should work.<br>Make sure to install ruby and tmux (if you want tmux enabled).<\/p>\n\n\n\n<p>Either clone <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/chrischen\/vim-config\" target=\"_blank\">my Neovim repo<\/a> into <code>~\/.config\/nvim<\/code>, or just grab the folder below and place it somewhere. I recommend placing it in <code>~\/.config\/geovim<\/code> if you don&#8217;t plan on using my Vim config.<\/p>\n\n\n\n<p>GeoVim files: <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/chrischen\/vim-config\/tree\/master\/geovim\" target=\"_blank\">https:\/\/github.com\/chrischen\/vim-config\/tree\/master\/geovim<\/a><\/p>\n\n\n\n<p>Add this to your <code>.zshrc<\/code> or <code>.bashrc<\/code>, and modify <code>GEOVIM_PATH<\/code> accordingly.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># Set this path to where you saved the above folder\nexport GEOVIM_PATH=\"$HOME\/.config\/nvim\/geovim\"\n# Or this if you use my Vim config\n# GEOVIM_PATH=\"$HOME\/.config\/nvim\/geovim\"\nexport GEOVIM_EDITOR=\"nvim\" # Set to \"vim\" to use Vim\nexport GEOVIM_TMUX=1 # Set to 0 to disable TMUX\n\n# The default command to invoke geovim is 'gvim'\n# alias mvim=gvim\nsource \"$GEOVIM_PATH\/geovim.sh\"<\/pre>\n\n\n\n<p>The <code>gvim<\/code> command now lets you open<code> somefile.txt<\/code> and have Kitty -&gt; TMUX -&gt; Vim open up automatically with the file you specified.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># When we're done you'll be able to run this from your shell and it will launch your editor with the file + resume your session\ngvim someFile.ts<\/pre>\n\n\n\n<p>You can also switch out Kitty for Alacritty. Open <code>launch_geovim.sh<\/code> to change the options:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># launch_geovim.sh\n\nsession=\"geovim\"\n# terminal_app=\"alacritty\" # Use alacritty - don't forget to install it\nterminal_app=\"kitty\" # Use kitty\n...<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Install NeoVim<\/h3>\n\n\n\n<p>I highly recommend <a href=\"https:\/\/neovim.io\">Neovim<\/a> instead of regular Vim 8, as I&#8217;ve found some UI blocking behavior happens when typing with live code completion and syntax checking. It&#8217;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&#8217;ve never encountered any freezing while typing. Neovim does have a bug when scrolling, but only if you scroll really really fast.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># macOS: homebrew\nbrew install neovim\n\n# Ubuntu: aptitude\nsudo add-apt-repository ppa:neovim-ppa\/unstable\nsudo apt-get update\nsudo apt-get install neovim<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Getting Command and Control Hot Keys to Work<\/h2>\n\n\n\n<p>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.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Configuring Kitty<\/strong> to Send macOS Custom Hot Keys<\/h3>\n\n\n\n<p>The GeoVim launcher script will use the bundled Kitty config file. These are preconfigured for standard macOS shortcuts, so you&#8217;ll need to edit the file if you want to change the key bindings. The config file is located at <code><a href=\"https:\/\/github.com\/chrischen\/vim-config\/blob\/master\/geovim\/conf\/kitty.conf\" target=\"_blank\" rel=\"noreferrer noopener\">geovim\/conf\/kitty.conf<\/a><\/code>. These keybindings will only be used in your GeoVim instance, so if you plan on using Kitty as your terminal, they won&#8217;t interfere with standard hot keys for your terminal shell.<\/p>\n\n\n\n<p><strong>Linux users: <\/strong>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 <a href=\"https:\/\/sw.kovidgoyal.net\/kitty\/conf.html#shortcut-kitty.Copy%20to%20clipboard\">handy Ctrl+C smart mode that operates as both interrupt <em>and<\/em> copy<\/a>. You&#8217;ll want to put those key bindings in <code>~\/.config\/kitty\/kitty.conf<\/code> instead.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Configuring Alacritty<\/strong> to Send macOS Custom Hot Keys<\/h3>\n\n\n\n<p>Alacritty is also a GPU-powered terminal emulator. It&#8217;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&#8217;s an alternative to Kitty, but I&#8217;ve found Kitty to feel more responsive and be better adapted to our setup (for example, shift+select with mouse doesn&#8217;t work in Alacritty).<\/p>\n\n\n\n<p>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 <code><a href=\"https:\/\/github.com\/chrischen\/vim-config\/blob\/master\/geovim\/conf\/alacritty.yml\" target=\"_blank\" rel=\"noreferrer noopener\">geovim\/conf\/alacritty.yml<\/a><\/code> and edit the <code>key_bindings:<\/code> section.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>key_bindings: \n  # Sends &lt;M-'> to comment\/uncomment lines\n  - { key: Apostrophe,        mods: Command, chars: \"\\x1b'\" }\n  # Sends &lt;M-]> and &lt;M-&#91;> for indenting lines\n  - { key: LBracket,        mods: Command, chars: \"\\x1b&#91;\" }\n  - { key: RBracket,        mods: Command, chars: \"\\x1b]\" }\n  # Mapped to Ctrl+S which saves in Vim\n  - { key: S,        mods: Command, chars: \"\\x13\" }\n  # Sends &lt;C-S-Insert> for Select All\n  - { key: A,        mods: Command, chars: \"\\x1b&#91;2;6~\" }\n...<\/code><\/pre>\n\n\n\n<p>If you want to bind other custom keys, try using <code>xxd -psd<\/code> in your terminal to get the hex codes. You can also use <a href=\"https:\/\/apps.apple.com\/us\/app\/key-codes\/id414568915?mt=12\">Key Codes.app<\/a>, type <code>Ctrl+V<\/code> in your terminal followed by the key combo, or run <code>cat<\/code> and then type your key combo. Certain key combos won&#8217;t work this way,  such as <code>Ctrl+C<\/code>, but if I type <code>Ctrl+V<\/code> followed by <code>Ctrl+Shift+(up arrow key)<\/code> I&#8217;d get <code>^[[1;6A<\/code> which is the escape sequence to use. <code>^[<\/code> is the ESC (hex 0x1b) key (which is the same as pressing <code>Ctrl+[<\/code>), followed by a string of <code>[1;6A<\/code>. This is sent by the terminal as sequential key presses.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Configuring iTerm2<\/strong> to Send macOS Custom Hot Keys<\/h3>\n\n\n\n<p>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&#8217;t interfere with your normal shell usage. If you aren&#8217;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 <code>Advanced -&gt; Automatic Profile Switching<\/code> after loading the profile. Because the profile can be automatically activated, you won&#8217;t need to use the GeoVim launcher for Vim in iTerm2.<\/p>\n\n\n\n<p><strong>Note:<\/strong> my default config overrides new tab\/switch tab hot keys to work in the Vim window. If you don&#8217;t want that, make sure to delete or re-map the <code>Cmd+T<\/code> and <code>Cmd+Shift+[<\/code> or <code>]<\/code> hot keys.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Load The iTerm2 Profile<\/h4>\n\n\n\n<p>Grab the iTerm2 profile from <code><a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/chrischen\/vim-config\/blob\/master\/geovim\/conf\/iTerm2.json\" target=\"_blank\">geovim\/conf\/iTerm2.json<\/a><\/code>. In the menu bar click on <code>iTerm2 -&gt; Preferences<\/code> and then click on the <code>Profiles<\/code> tab. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.instapainting.com\/blog\/wp-content\/uploads\/2020\/05\/image.png\" alt=\"\" class=\"wp-image-341\" width=\"273\" height=\"231\" srcset=\"https:\/\/www.instapainting.com\/blog\/wp-content\/uploads\/2020\/05\/image.png 528w, https:\/\/www.instapainting.com\/blog\/wp-content\/uploads\/2020\/05\/image-300x253.png 300w\" sizes=\"(max-width: 273px) 100vw, 273px\" \/><figcaption>Load the profile from <code>geovim\/conf\/iTerm2.json<\/code><\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Receiving The Hot Keys In Vim<\/h3>\n\n\n\n<p>The next step is to take these key combos sent from your terminal and trigger the right actions in Vim. The Command <strong>\u2318<\/strong> <code>&lt;D-...&gt;<\/code> (&#8220;super&#8221; key) Vim key binding only works in MacVim. We still won&#8217;t be able to use it, but we&#8217;re getting around that by taking advantage of <em>escape sequences<\/em>.<\/p>\n\n\n\n<p>In recent versions of terminal Vim you may notice that CMD+V may actually work\u2014at least slightly. This is because your terminal is sending a <a href=\"https:\/\/cirw.in\/blog\/bracketed-paste\">bracketed paste<\/a>. 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.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\\e[200~Some text in your clipboard ending in a newline\\n\\e[201~\n# Here \\e is also known as Esc, ^[, Ctrl+[, or 0x1b<\/pre>\n\n\n\n<p>However as of the time of this writing, there are still<a href=\"https:\/\/github.com\/neovim\/neovim\/issues\/12184\"> quirks to this behavior in Neovim<\/a> which means we&#8217;ll have to re-implement this functionality to get it working perfectly. Plus, CMD+C copying still won&#8217;t work if you have mouse support enabled in Vim because text selection triggers a visual selection in <em>Vim<\/em>, preventing your <em>terminal<\/em> from highlighting it  (you can still yank with <code>y<\/code> though).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Configuring Vim<\/h3>\n\n\n\n<p class=\"has-text-color has-background has-text-align-center has-very-dark-gray-color has-luminous-vivid-amber-background-color\"><em>This section is not necessary if you use <a href=\"https:\/\/github.com\/chrischen\/vim-config\">my Neovim configuration<\/a>.<\/em><\/p>\n\n\n\n<p>Add the following to your <code>~\/.vimrc<\/code> or <code>~\/.config\/nvim\/init.vim<\/code> (neovim) config file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\" GeoVim {{{\n\" ----------\n\" Remap Paste Key Mappings\n\" ----------\n\" Insert mode paste\ninoremap &lt;C-Insert> &lt;C-r>*\n\" Command mode paste\ncnoremap &lt;C-Insert> &lt;C-r>*\n\" Normal mode paste\nnnoremap &lt;C-Insert> P\n\" Visual mode paste (without yanking replaced text)\nvnoremap &lt;C-Insert> \"_dP\n\" Remap Copy Key Mappings\n\" ----------\n\" Remap copy to work in neovim\nvmap &lt;M-&#91;>2;5+ y\n\" Remap copy to work in vim8\nvmap \u001b&#91;2;5+ y\n\" Select all\nnoremap &lt;C-S-Insert> &lt;Esc>ggVG\n\" Remap Indent\n\" ----------\nvmap &lt;M-]> >gv|\nvmap &lt;M-&#91;> &lt;gv\nnmap &lt;M-]> &lt;Esc>v>&lt;Esc>\nnmap &lt;M-&#91;> &lt;Esc>v&lt;&lt;Esc>\nimap &lt;M-]> &lt;C-t>\nimap &lt;M-&#91;> &lt;C-d>\n\" Remap Comment (Requires caw.vim plugin)\n\" ----------\nvmap &lt;M-'> gcc\nnmap &lt;M-'> gcc\nimap &lt;M-'> &lt;Esc>gcci\n\" Remap quit all to Alt+q (requires Alt to send escape)\n\" ----------\nnoremap &lt;M-q> &lt;Esc>:qa&lt;Enter>\nnoremap &lt;M-&#91;>qa! &lt;Esc>:qa!&lt;Enter>\nnoremap ^&#91;&#91;qa! &lt;Esc>:qa!&lt;Enter>\n\" Remap save\n\" ----------\ninoremap &lt;C-s> &lt;Esc>:w&lt;Enter>i\nvnoremap &lt;C-s> &lt;Esc>:w&lt;Enter>v\nnnoremap &lt;C-s> &lt;Esc>:w&lt;Enter>\n\" Make Shift+Click work to extend visual selection\n\" ----------\nnnoremap &lt;silent> v :let b:v_mode='v'&lt;CR>mVv\nnnoremap &lt;silent> V :let b:v_mode='V'&lt;CR>mVV\nvnoremap &lt;expr> &lt;S-LeftMouse> '&lt;Esc>&lt;LeftMouse>mN`V'.b:v_mode.'`N'\n\" }}}<\/code><\/pre>\n\n\n\n<p>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 <code>.vimrc<\/code> to sync your clipboard with your OS clipboard. The <code>+<\/code> 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. <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">if has('mac') &amp;&amp; has('vim_starting')\n  let g:clipboard = {\n  \\   'name': 'macOS-clipboard',\n  \\   'copy': {\n  \\      '+': 'pbcopy',\n  \\      '*': 'pbcopy',\n  \\    },\n  \\   'paste': {\n  \\      '+': 'pbpaste',\n  \\      '*': 'pbpaste',\n  \\   },\n  \\   'cache_enabled': 0,\n  \\ }\nendif\n\nif has('clipboard') &amp;&amp; has('vim_starting')\n  set clipboard&amp; clipboard^=unnamed,unnamedplus\nendif<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Add Your Own Custom Key Bindings<\/h4>\n\n\n\n<p>There are keybindings that work in GUI apps but not in terminal Vim, such as Ctrl+Enter. Most terminals won&#8217;t be able to distinguish between Enter and Ctrl+Enter. I&#8217;ve pre-added bindings for these modifiers if you want to use them.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># In your vimrc...\n# To bind &lt;C-Enter&gt;\nmap C&lt;Enter&gt; ...\n# To bind &lt;S-Enter&gt;\nmap S&lt;Enter&gt; ...\n# &lt;C-S-Enter&gt;\nmap C-S&lt;Enter&gt; ...<\/pre>\n\n\n\n<p>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&#8217;t seem to distinguish the added modifiers, you&#8217;ll need to define custom key sequences and receive them in Vim like above.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"816\" height=\"248\" src=\"https:\/\/www.instapainting.com\/blog\/wp-content\/uploads\/2020\/05\/image-4.png\" alt=\"\" class=\"wp-image-355\" srcset=\"https:\/\/www.instapainting.com\/blog\/wp-content\/uploads\/2020\/05\/image-4.png 816w, https:\/\/www.instapainting.com\/blog\/wp-content\/uploads\/2020\/05\/image-4-300x91.png 300w, https:\/\/www.instapainting.com\/blog\/wp-content\/uploads\/2020\/05\/image-4-768x233.png 768w\" sizes=\"(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><figcaption>You can do this too in insert mode<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Install Obsession Vim Plugin For Tab State Save\/Reload<\/h3>\n\n\n\n<p class=\"has-text-color has-background has-text-align-center has-very-dark-gray-color has-luminous-vivid-amber-background-color\"><em>This section is not necessary if you use <a href=\"https:\/\/github.com\/chrischen\/vim-config\">my Neovim configuration<\/a>.<\/em><\/p>\n\n\n\n<p>Install <a href=\"https:\/\/github.com\/tpope\/vim-obsession\">https:\/\/github.com\/tpope\/vim-obsession<\/a> using your preferred vim plugin manager. I recommend <a href=\"https:\/\/github.com\/junegunn\/vim-plug\">Vim-Plug<\/a> (easier to use) or <a href=\"https:\/\/github.com\/Shougo\/dein.vim\">Dein<\/a> (harder to use). No further configuration is necessary as the GeoVim launcher will take care of starting sessions.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Auto Saving and Resuming Sessions<\/h2>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<p>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&#8217;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 <code>launch_geovim.sh<\/code>. 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.<\/p>\n\n\n\n<p>Install <a href=\"https:\/\/github.com\/tmux-plugins\/tpm\">TMUX plugin manager<\/a> if you haven&#8217;t already. If you are using Prezto, you&#8217;ll need to initialize plugins in <code>.tmux.conf<\/code> exactly as shown below, instead of what it tells you in the default instructions.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Configure TMUX<\/h3>\n\n\n\n<p>Add this to the end of your <code>tmux.conf<\/code> or <code>tmux.conf.user<\/code> file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Meta + W (Meta is the same as Alt\/Option when configured to send ^&#91; + escape\n# sequence. This will send \":qa\" to all Vim windows\nbind M-W run-shell \"tmux list-panes -s -F '##{session_name}:##{window_index}.##bind M-w run-shell \"tmux list-panes -s -F '##{session_name}:##{window_index}.##{pane_index}' | xargs -I PANE tmux send-keys -t PANE M-q C-d\"\n# Kills TMUX and all windows without saving\nbind C-q confirm-before \"kill-session -t geovim\"\n\n# This ensures that any new TMUX windows spawned via Prefix+c runs your shell\n# instead of another instance of Vim\nbind c new-window -e GEOVIM=0\n\n# tmux-resurrect config options - do not turn these on as it interferes with our manual resurrection\n# set -g @resurrect-strategy-vim 'session'\n# for neovim\n# set -g @resurrect-strategy-nvim 'session'\n\n# Do not turn this on as we restore TMUX sessions manually\n# set -g @continuum-restore 'on'\n\n# List of plugins\n# tpm - Plugin manager (required)\n# tmux-sensible - sensible defaults (optional)\n# tmux-resurrect - allows saving\/restoring TMUX windows (required)\n# tmux-continuum - autosaves via resurrect (required)\nset -g @tpm_plugins '           \\\n   tmux-plugins\/tpm             \\\n   tmux-plugins\/tmux-sensible   \\\n   tmux-plugins\/tmux-resurrect  \\\n   tmux-plugins\/tmux-continuum  \\\n'\n\n# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)\nrun '~\/.tmux\/plugins\/tpm\/tpm'<\/code><\/pre>\n<\/div><\/div>\n\n\n\n<p>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\u2014even when you restart your computer or recover from a crash. You can manually save\/restore your TMUX windows with the following key combos:<\/p>\n\n\n\n<p>Save: <strong>Ctrl-A<\/strong> followed by <strong>Ctrl-S<\/strong><br>Restore: <strong>Ctrl-A<\/strong> followed by <strong>Ctrl-R<\/strong><\/p>\n\n\n\n<p>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. <em>Vim session tracking also needs to be turned on manually if you open a specific file to edit as in<\/em> <code>gvim someFile.ts<\/code><em> as opposed to just launching<\/em> <code>gvim<\/code> <em>with no arguments. This is to prevent it from littering random directories with Vim session files.<\/em><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># Type this command in Vim to manually turn on Obsess (for session tracking)\n:Obsess<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Performance<\/h2>\n\n\n\n<p>I haven&#8217;t fully evaluated the energy impact of this setup yet. In a future post I will be reporting back on detailed energy consumption stats.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Collaborative Editing<\/h2>\n\n\n\n<p>Because Vim is now running inside the terminal, we can take advantage of utilities made for the terminal such as <a href=\"https:\/\/www.teleconsole.com\">Teleconsole<\/a>, 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! <strong>Important: turn off TMUX or just run Vim by itself for this.<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># Turn off TMUX! \n# Launch teleconsole (install it first)\n$ teleconsole\n$ ... you'll be given a link to share ...\n$ nvim<\/pre>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>Run a 100 FPS GPU-rendered Vim With macOS Hot Keys, Shared Copy &amp; 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&#8217;ll be able to use &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.instapainting.com\/blog\/terminal-vim-with-command-control-hot-key\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;GeoVim: Terminal Vim With GUI Hot Keys (Cmd\/Ctrl), VS Code Feature Parity, and Collaborative Editing&#8221;<\/span><\/a><\/p>\n<p><!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[24,22,23],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>GeoVim: Terminal Vim With GUI Hot Keys (Cmd\/Ctrl), VS Code Feature Parity, and Collaborative Editing - Instapainting Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.instapainting.com\/blog\/terminal-vim-with-command-control-hot-key\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"GeoVim: Terminal Vim With GUI Hot Keys (Cmd\/Ctrl), VS Code Feature Parity, and Collaborative Editing - Instapainting Blog\" \/>\n<meta property=\"og:description\" content=\"Run a 100 FPS GPU-rendered Vim With macOS Hot Keys, Shared Copy &amp; 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&#8217;ll be able to use &hellip; Continue reading &quot;GeoVim: Terminal Vim With GUI Hot Keys (Cmd\/Ctrl), VS Code Feature Parity, and Collaborative Editing&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.instapainting.com\/blog\/terminal-vim-with-command-control-hot-key\/\" \/>\n<meta property=\"og:site_name\" content=\"Instapainting Blog\" \/>\n<meta property=\"article:published_time\" content=\"2020-05-05T06:02:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-07-17T23:17:29+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.instapainting.com\/blog\/wp-content\/uploads\/2020\/05\/image.png\" \/>\n<meta name=\"author\" content=\"chris\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"chris\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"16 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.instapainting.com\/blog\/terminal-vim-with-command-control-hot-key\/\",\"url\":\"https:\/\/www.instapainting.com\/blog\/terminal-vim-with-command-control-hot-key\/\",\"name\":\"GeoVim: Terminal Vim With GUI Hot Keys (Cmd\/Ctrl), VS Code Feature Parity, and Collaborative Editing - Instapainting Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.instapainting.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.instapainting.com\/blog\/terminal-vim-with-command-control-hot-key\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.instapainting.com\/blog\/terminal-vim-with-command-control-hot-key\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.instapainting.com\/blog\/wp-content\/uploads\/2020\/05\/image.png\",\"datePublished\":\"2020-05-05T06:02:00+00:00\",\"dateModified\":\"2020-07-17T23:17:29+00:00\",\"author\":{\"@id\":\"https:\/\/www.instapainting.com\/blog\/#\/schema\/person\/f0008166544f365e1de42677b6ec07a2\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.instapainting.com\/blog\/terminal-vim-with-command-control-hot-key\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.instapainting.com\/blog\/terminal-vim-with-command-control-hot-key\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.instapainting.com\/blog\/terminal-vim-with-command-control-hot-key\/#primaryimage\",\"url\":\"https:\/\/www.instapainting.com\/blog\/wp-content\/uploads\/2020\/05\/image.png\",\"contentUrl\":\"https:\/\/www.instapainting.com\/blog\/wp-content\/uploads\/2020\/05\/image.png\",\"width\":528,\"height\":446},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.instapainting.com\/blog\/terminal-vim-with-command-control-hot-key\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.instapainting.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"GeoVim: Terminal Vim With GUI Hot Keys (Cmd\/Ctrl), VS Code Feature Parity, and Collaborative Editing\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.instapainting.com\/blog\/#website\",\"url\":\"https:\/\/www.instapainting.com\/blog\/\",\"name\":\"Instapainting Blog\",\"description\":\"Leveraging Art &amp; Technology\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.instapainting.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.instapainting.com\/blog\/#\/schema\/person\/f0008166544f365e1de42677b6ec07a2\",\"name\":\"chris\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.instapainting.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/4836857b5056601222e6aca8804d8348?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/4836857b5056601222e6aca8804d8348?s=96&d=mm&r=g\",\"caption\":\"chris\"},\"url\":\"https:\/\/www.instapainting.com\/blog\/author\/chris\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"GeoVim: Terminal Vim With GUI Hot Keys (Cmd\/Ctrl), VS Code Feature Parity, and Collaborative Editing - Instapainting Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.instapainting.com\/blog\/terminal-vim-with-command-control-hot-key\/","og_locale":"en_US","og_type":"article","og_title":"GeoVim: Terminal Vim With GUI Hot Keys (Cmd\/Ctrl), VS Code Feature Parity, and Collaborative Editing - Instapainting Blog","og_description":"Run a 100 FPS GPU-rendered Vim With macOS Hot Keys, Shared Copy &amp; 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&#8217;ll be able to use &hellip; Continue reading \"GeoVim: Terminal Vim With GUI Hot Keys (Cmd\/Ctrl), VS Code Feature Parity, and Collaborative Editing\"","og_url":"https:\/\/www.instapainting.com\/blog\/terminal-vim-with-command-control-hot-key\/","og_site_name":"Instapainting Blog","article_published_time":"2020-05-05T06:02:00+00:00","article_modified_time":"2020-07-17T23:17:29+00:00","og_image":[{"url":"https:\/\/www.instapainting.com\/blog\/wp-content\/uploads\/2020\/05\/image.png"}],"author":"chris","twitter_card":"summary_large_image","twitter_misc":{"Written by":"chris","Est. reading time":"16 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.instapainting.com\/blog\/terminal-vim-with-command-control-hot-key\/","url":"https:\/\/www.instapainting.com\/blog\/terminal-vim-with-command-control-hot-key\/","name":"GeoVim: Terminal Vim With GUI Hot Keys (Cmd\/Ctrl), VS Code Feature Parity, and Collaborative Editing - Instapainting Blog","isPartOf":{"@id":"https:\/\/www.instapainting.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.instapainting.com\/blog\/terminal-vim-with-command-control-hot-key\/#primaryimage"},"image":{"@id":"https:\/\/www.instapainting.com\/blog\/terminal-vim-with-command-control-hot-key\/#primaryimage"},"thumbnailUrl":"https:\/\/www.instapainting.com\/blog\/wp-content\/uploads\/2020\/05\/image.png","datePublished":"2020-05-05T06:02:00+00:00","dateModified":"2020-07-17T23:17:29+00:00","author":{"@id":"https:\/\/www.instapainting.com\/blog\/#\/schema\/person\/f0008166544f365e1de42677b6ec07a2"},"breadcrumb":{"@id":"https:\/\/www.instapainting.com\/blog\/terminal-vim-with-command-control-hot-key\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.instapainting.com\/blog\/terminal-vim-with-command-control-hot-key\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.instapainting.com\/blog\/terminal-vim-with-command-control-hot-key\/#primaryimage","url":"https:\/\/www.instapainting.com\/blog\/wp-content\/uploads\/2020\/05\/image.png","contentUrl":"https:\/\/www.instapainting.com\/blog\/wp-content\/uploads\/2020\/05\/image.png","width":528,"height":446},{"@type":"BreadcrumbList","@id":"https:\/\/www.instapainting.com\/blog\/terminal-vim-with-command-control-hot-key\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.instapainting.com\/blog\/"},{"@type":"ListItem","position":2,"name":"GeoVim: Terminal Vim With GUI Hot Keys (Cmd\/Ctrl), VS Code Feature Parity, and Collaborative Editing"}]},{"@type":"WebSite","@id":"https:\/\/www.instapainting.com\/blog\/#website","url":"https:\/\/www.instapainting.com\/blog\/","name":"Instapainting Blog","description":"Leveraging Art &amp; Technology","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.instapainting.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.instapainting.com\/blog\/#\/schema\/person\/f0008166544f365e1de42677b6ec07a2","name":"chris","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.instapainting.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/4836857b5056601222e6aca8804d8348?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4836857b5056601222e6aca8804d8348?s=96&d=mm&r=g","caption":"chris"},"url":"https:\/\/www.instapainting.com\/blog\/author\/chris\/"}]}},"_links":{"self":[{"href":"https:\/\/www.instapainting.com\/blog\/wp-json\/wp\/v2\/posts\/326"}],"collection":[{"href":"https:\/\/www.instapainting.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.instapainting.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.instapainting.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.instapainting.com\/blog\/wp-json\/wp\/v2\/comments?post=326"}],"version-history":[{"count":38,"href":"https:\/\/www.instapainting.com\/blog\/wp-json\/wp\/v2\/posts\/326\/revisions"}],"predecessor-version":[{"id":399,"href":"https:\/\/www.instapainting.com\/blog\/wp-json\/wp\/v2\/posts\/326\/revisions\/399"}],"wp:attachment":[{"href":"https:\/\/www.instapainting.com\/blog\/wp-json\/wp\/v2\/media?parent=326"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.instapainting.com\/blog\/wp-json\/wp\/v2\/categories?post=326"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.instapainting.com\/blog\/wp-json\/wp\/v2\/tags?post=326"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}