Skip to content

Instantly share code, notes, and snippets.

@raoulmillais
Created April 9, 2020 13:31
Show Gist options
  • Save raoulmillais/196f48f020b97a22fff690adc60c280a to your computer and use it in GitHub Desktop.
Save raoulmillais/196f48f020b97a22fff690adc60c280a to your computer and use it in GitHub Desktop.
Vim / tmux / zsh show and tell
theme class backgroundColor
default
invert
black

The Vim, Tmux, Zsh Triumvirate

Raoul Millais


Philosophy

  • This is not a flamewar :) It is a pitch for the virtues of using these tools
  • An attempt to showcase how you can make your vim experience like the best IDE you (I!) ever used.
  • Coding at "the speed of thought" - Feedback with vim (if it is configured well) should always be instantaneous or so quick as to seem instantaneous.
  • Form your own opinions about how your development experience works
  • This takes time. Quite a lot of time but your investment is paid off manifold if you are prepared to do it.

Unix + Vim as an IDE

  • Unix is the ultimate development environment, vim and tmux and zsh embrace and extend that idea
  • IDEs have lots of opinions, often very good ones, but you must learn them and you might not like all of them. There is always a limit to the configurability. There is virtually no limit to configurability of vim, but it will reward you for configuration that is sympathetic with the vim philosophy of doing things.
  • Almost all IDEs will get in the way of you typing at some point. Vim will never do that unless you configure it to do so.

fzf


Some vim basic config

Strategy

  • Avoid remapping any of the defaults - I have some exceptions below
  • Try to create a neat mnemonic structure to under your leader key for mappings.
  • 2 philosophoes, chording for really common shortcuts or all under leader key. Chording makes you prone to RSI so I favour leader mappings

Nicer keymaps

  • jk to so you don't move off the home row
  • , , for moving round splits to avoid chording and one less keypress Use both line number and relative numbering. You will see what line you are on as well as how far other lines are relative to the current line.
set number
set relativenumber

Package management

  • Lots of options, I started using pathogen but you have to manage cloning all the plugins yourself and pulling when you want to update which is a bit tiresome. I now use vundle which is much nicer. I just do :PluginUpdate or :PluginInstall
  • Vim 8 now has it's own rudimentary "package management!" (not quite true, but close) - I haven't tried it.

IDE-like features (and Demos)

ALE

Asynchronous linting engine. Does linting and style checking for uncompiled files.

  • shellcheck
  • hadolint
  • standard (for JavaScript)
  • etc etc

Very fast. Shows errors in the error pane so you can navigate through them


Autocompletion

Multiple options here: I used to use YouCompleteMe which was very powerful but it was a bit of a kitchen sink and sometimes a bit laggy. I've since switched to deoplete which is much faster and doesnt have a manual compile step after installing and gives me 90% of the functionality


NERDTree

Useful as a project browser but I don't use it much. I prefer to rely on fzf. It's almost always fewer keypreses to open the file I'm interested in.

Pro-tip map :NERDTreeToggle to a hotkey to pop it open and closed

noremap <f2> :NERDTreeToggle<cr>

Git

  • Fugitive
  • Git commits
  • Git config

Make Vim and Tmux play well together

  • make pane / split navigation work seamlessly by binding navigation to crtl-{h,j,k,l} in both vim and tmux:

Vim

  • Make vim control tmux pane navigation
Plugin 'christoomey/vim-tmux-navigator'
  • Remap ctrl-{h,j,k,l} for less chording
cnoremap <C-j> <t_kd>
cnoremap <C-k> <t_ku>
cnoremap <C-a> <Home>
cnoremap <C-e> <End>

Tmux

  • Move seamlessly between tmux panes and vim - to not clober the bindings of ctrl-j and ctrl-k for fzf panes we check that the focussed is vim first
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
    | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
bind-key -n C-h if-shell "$is_vim" "send-keys C-h"  "select-pane -L"
bind-key -n C-j if-shell "$is_vim" "send-keys C-j"  "select-pane -D"
bind-key -n C-k if-shell "$is_vim" "send-keys C-k"  "select-pane -U"
bind-key -n C-l if-shell "$is_vim" "send-keys C-l"  "select-pane -R"
bind-key -n C-\ if-shell "$is_vim" "send-keys C-\\" "select-pane -l"

Zsh


Zsh vi mode

# Vi mode line editing
bindkey -v
bindkey jk vi-cmd-mode
  • Display "mode" on right hand side of prompt
function zle-line-init zle-keymap-select {
  VIM_PROMPT="%{$fg_bold[yellow]%} [% NORMAL]%  %{$reset_color%}"
  RPS1="${${KEYMAP/vicmd/$VIM_PROMPT}/(main|viins)/} $EPS1"
  zle reset-prompt
}

Oh-my-zsh

  • Don't use oh-my-zsh it is very slow
  • It includes a bloated dynamic plugin loading framework that is often activated on every keypres
  • You probably don't use 90% of it
  • You can walk through the source code and pull out the bits you actually need and use and you will end up with a much faster (instantaneous setup)
  • You will learn a lot about zsh

Resources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment