Setting up Portable gVim for Windows
This post documents how I set up my personal configuration of VIM for portable use.
# Background
Recently I fell in love with VIM. I use VIM for programming, blogging, documentation and almost everything on my personal computer. However when I switched to my company computer, I was so frustrated that I have to stuck with the MS Office Suite. So I decided to spend the weekend to put together a light weight, environment independent, but yet powerful VIM configuration to use on any computer.
The configuration should be able to:
- Work on Windows system.
- Not rely on any development tools/environment such git, npm, cmake, etc. (as my company computer won't be able to install all these tools without going through approval process).
- Easily shared by USB drive or a remote repository.
- Have minimal plugins pre-installed.
- Have common key mappings and useful presets.
- Have minimal / no additional setups on a new machine.
# Installation
I use the portable GVim downloaded from here (opens new window). The installation file is a binary and can be installed to any location very easily. And it seems the firewall of the company will let it go through without any issues.
# Folder Structure
I installed to my non-system D driver. The folder structure is as follows:
|-- VIM
|-- App
|-- Settings
# Plugins
I use a dozen of plugins. They can be categorized into the following:
- Theming and cosmetic:
- vim-github-colorscheme
- onedark.vim
- vim-airline
- vim-airline-themes
- Easier navigation
- SimpylFold
- nerdtree
- vim-sneak
- vim-surround
- auto-pairs
- tabular
- For documentation
- vimwiki
- vim-markdown
- For programming
- indentpython.vim
It is a bit annoying that I couldn't get the completion plugins to work such as YouCompleteMe or python-mode. Those plugins require a more open system where you can install the environment needed.
# Other customizations
Except for the customized key mappings that I like to use, I also have the following customizations.
cnoremap <A-v> <C-\>esubstitute(getline('.'), '^\s*\(' . escape(substitute(&commentstring, '%s.*$', '', ''), '*') . '\)*\s*:*' , '', '')<CR>
When you are in the command mode, you can press alt-v to paste the current line in the command.
autocmd FileType python nnoremap <buffer> <F5> :update<bar>!python %<CR>
I like to use F5. This command will directly run your python file in the terminal with one key stroke.
autocmd bufenter *.md noremap <silent> <f5> :! start msedge "%:p"<cr>
Again, use F5 to display the current markdown file in the browser, where I have an extension installed to render the markdown.
augroup clear_trailing
autocmd BufWritePre * if &ft != "vimwiki" | %s/\s\+$//e
autocmd BufWritePre * if &ft != "vimwiki" | %s/\n\+\%$//e
autocmd BufwritePre * noh
augroup END
This autocmd will remove all trailing spaces and blank lines. How ever I disabled it in the markdown files because sometimes I have to type extra spaces as a cartridge.
# Update - Aug 21
I finally made this version of VIM to work with a python auto completion engine: jedi-VIM. To make it work, I had to replace the original VIM application with a build with python compiled. And I had to also download the corresponding python dll in a "Windows embeddable package (64-bit)". This is zipped file and doesn't require admin rights to install.
Now I can finally have an IDE like experience with just VIM.