Vim has always been my favorite text editor on Mac and Linux. But since I spend quite some time on Windows lately I figured it’s time to see how things are now in with Vim in the Windows department.
Vim has always been my favorite text editor on Mac and Linux. But since I spend quite some time on Windows lately I figured it’s time to see how things are now with Vim in the Windows Department.
But first, why Vim? For me the most important reason is that I get to edit files quickly without leaving the terminal.
And that’s a big win. Besides, it’s easy on the eyes too!
Install Vim and ConEmu with Chocolatey
Choco, what else!
We need a decent terminal emulator for PowerShell so let’s install ConEmu as well.
choco install conemu -y
choco install vim -y
Now we can start vim with the vim command. But of course plain vim is ultimately boring, so let’s start configuring it.
Where are the config files
In ConEmu, open a Powershell shell and enter vim. This wil start Vim.
Vim looks for configuration in a ‘vimrc’ file.
Now we get to see the environment settings of Vim so we know where to put our config.
system vimrc file: "$VIM\vimrc"
user vimrc file: "$HOME\_vimrc"
2nd user vimrc file: "$HOME\vimfiles\vimrc"
3rd user vimrc file: "$VIM\_vimrc"
user exrc file: "$HOME\_exrc"
2nd user exrc file: "$VIM\_exrc"
defaults file: "$VIMRUNTIME\defaults.vim"
Let’s continue using the second entry and create the vimrc file:
Exit Vim by typing
And in your Powershell prompt enter:
Next let’s add some plugins and modifications to our vimrc file.
With Pathogen installing Vim plugins is a breeze.
At the PowerShell prompt type:
mkdir ~/vimfiles/bundle;mkdir ~/vimfiles/autoload
Invoke-WebRequest https://tpo.pe/pathogen.vim -OutFile ~\vimfiles\autoload\pathogen.vim
Then install some plugins by cloning them to the bundle folder you just created:
git clone https://github.com/scrooloose/nerdtree.git
git clone https://github.com/Valloric/MatchTagAlways.git
git clone https://github.com/vim-airline/vim-airline
git clone https://github.com/vim-airline/vim-airline-themes
git clone https://github.com/lukaszb/vim-web-indent.git
git clone https://github.com/altercation/vim-colors-solarized.git
Create your vimrc
Copy and paste this into your vimrc:
filetype plugin indent on
map <F7> mzgg=G`z<CR>
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
autocmd vimenter * if !argc() | NERDTree | endif
map <F5> :NERDTreeToggle<CR>
The first section is self explanatory I think. Then this config:
– loads Pathogen
– maps the function key F7 to a command sequence that aligns the code.
– configures the NERDTree to load if you start Vim without a filename.
– The last section is to set the color theme to Solarized and the configure the Airline status bar.