Chat Zalo Chat Messenger Phone Number Đăng nhập
Vim and Tmux on your Mac

Vim and Tmux on your Mac

Setting up your computer for Vim and Tmux often comes with some issues. Here’s how to manage plugins for Vim and use Tmux to increase your productivity, as well as solve some common problems.

We will install

: Vundle –

  1. Plugin management for Vim
  2. Solarized
  3. color scheme Tmux

  4. – Terminal Multiplexer

We will also discover some problems that Mac and Tmux have when displaying 256 color themes

.

Install Vundle You can install

Vundle by cloning it: $ git Clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle Configure Vundle

Once installed, you can configure it

.

And follow the installation instructions by editing your ~/.vimrc

file: disable the unsupported file type ” Required set rtp+=~/.vim/bundle/vundle/ call vundle#rc() Bundle ‘gmarik/

vundle

‘ ” Required filetype plugin indent on ” Required

Once this is configured, you can open a new instance of vim and run

:BundleInstall: $vim # Any file will do: BundleInstall

You will receive a confirmation message “Done” at the bottom of the screen if all goes well

.

Add

solarized color theme

Next, we’ll add the solarized color theme. Vundle makes this really easy. Just add the Github repository name in ~/.vimrc:

Bundle ‘gmarik/vundle’ ” We saw this before Bundle ‘altercation/vim-colors-solarized’ ” New line!! ” Some settings to enable the theme: set number ” Show line number syntax enable ” Use syntax highlighting set background=dark colorscheme solarized

Now that we’ve added the solarized theme, we need Vundle to install it.

$ vim :BundleInstall

Now open your Terminal (iTerm2 or Terminal application). If you’re on a Mac, you might see something… ugly. It had a terrible background and the colors were completely muted. It didn’t have 256 colors enabled.

Here’s what I saw: Annex A

To fix that, I finally came across this question from StackOverflow, which had the answer waiting

.

Change your ~.vimrc setting above to the following

: ” Some settings to enable the theme: set number syntax enable set background=dark let g:solarized_termcolors = 256 ” New line!! solarized colorscheme

Once you start a new Vim instance, you should see your new vim

!

Annex B

On tmux! Let’s

up our game and put Tmux in the mix. We can use Tmux to open multiple “panels” within our shell.

First, install it. On your Mac, you can use Homebrew

: $ brew install tmux

Ubuntu or Debian users can use

apt-get: $ sudo apt-get install tmux

Great. Now, colors are also an issue when running Vim within Tmux. Let’s fix that. Create or edit the

~/.tmux.conf file: $vim ~/.tmux.conf > set -g default-terminal “screen-256color”

Now we are ready to use Tmux. Start a new Tmux session

: $ tmux

Then split the screen vertically so that we have 2 panels with this keyboard shortcut

: Ctrl-b %

You can switch between panels with this shortcut:

Ctrl-b or

You can then open separate files in each! (Or do… anything really).

tmux

More Tmux Tmux

has Windows

, and within Windows it has Panels. Each window consists of a set of 1-n panels.

Tmux also has Sessions. A collection of windows/panels live within a session. It can be separated from a session, leaving it running in the background. Later, you can plug it back in and continue working. This is how people match the program.

Split the screen into 2 panels:

Ctrl-b %

Split the current panel horizontally into 2

panels: Ctrl-b ” Switch between

panels

: Ctrl-b or Create

New Window

: Ctrl-b c Switch between Windows: Ctrl-b n # next Ctrl-b p # previous Detach from session: Ctrl-b d

Reconnect to

a session: tmux attach -t [session name]

Create a

session: tmux new -s [session name] Switch between sessions: tmux switch -t [session name] Switch between sessions within tmux : Ctrl-b ( # previous session Ctrl-b ) # next session Ctrl-b L # ‘last’ session (previously used) Ctrl-b s # choose a session from a list Session list:

tmux
list-sessions

List of

all commands:

Ctrl-b ?

Hyphen!

You can run this bash script on your Debian or Ubuntu server to run the above Vim + Tmux configurations. This could conflict with anything you currently have in your ~/.vimrc or ~/.tmux.conf files (if they already exist). Backup them first.

Further reading:

  • Use this to get the right colors on Mac Terminal
  • Vim as your new IDE
  • tmux crash

  • course My (someones)
  • tmux setup

  • Cheap tmux ebook
  • Tmux cheetsheet

Contact US