Vim Installation / Ubuntu, macOS Environment
1. Installation and Configuration Environment
The installation and configuration environment is as follows.
- Ubuntu 14.04 / Ubuntu 16.04 (root user)
- macOS 10.14
- Vim 8
2. Configuration Plugin List
The list of VIM plugins used is as follows.
- vundle: Serves as a Vim Plugin Manager. By placing Vim plugins to install in .vimrc, you can easily install Vim plugins through vundle.
- nerdtree: Serves as a file explorer.
- tagbar: Shows a list of code tags.
- YouCompleteMe: Performs code autocomplete functionality.
- vim-gutentags: Automatically manages Ctag files.
- vim-airline: Improves readability of Vim’s status line.
- vim-clang-format: Performs code alignment using clang-format.
- vim-go: Configures the environment for golang.
3. Vim Basic Installation and Configuration
3.1. Package Installation
3.1.1. Ubuntu
$ add-apt-repository ppa:jonathonf/vim
$ apt-get update
$ apt-get install vim-gnome
$ apt-get install ctags
$ apt-get install cscope
$ apt-get install clang-formatInstall Vim, ctags, cscope, and ClangFormat.
3.1.2. macOS
$ brew update
$ brew install vim
$ brew install --HEAD universal-ctags/universal-ctags/universal-ctags
$ brew install cscope
$ brew install clang-formatInstall Vim, ctags, cscope, and ClangFormat.
3.2. Bash Shell Configuration
3.2.1. Ubuntu
| |
Add the content from [File 1] to the ~/.bashrc file to configure Vundle to install vim-go.
3.3. Vundle Plugin Installation
$ git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vimInstall Vundle using git.
3.4. .vimrc File Configuration
| |
Create the ~/.vimrc file as shown in [File 2] to store plugin installation and configuration information.
3.5. Vim Plugin Installation Using Vundle
: PluginInstallInstall Vim plugins stored in ~/.vimrc. Execute in Vim command mode.
3.6. YouCompleteMe Installation
3.6.1. Ubuntu
$ apt-get install build-essential cmake
$ apt-get install python-dev python3-dev
$ cd ~/.vim/bundle/YouCompleteMe
$ ./install.py --clang-completerCompile and install YouCompleteMe.
$ wget https://raw.githubusercontent.com/Valloric/ycmd/3ad0300e94edc13799e8bf7b831de8b57153c5aa/cpp/ycm/.ycm_extra_conf.py -O ~/.vim/.ycm_extra_conf.pyDownload .ycm_extra_conf.py and copy it to ~/.vim/.ycm_extra_conf.py to use as YouCompleteMe’s default configuration value.
3.6.2. macOS
$ brew install cmake
$ brew install python2
$ cd ~/.vim/bundle/YouCompleteMe
$ ./install.py --clang-completerCompile and install YouCompleteMe.
$ wget https://raw.githubusercontent.com/Valloric/ycmd/3ad0300e94edc13799e8bf7b831de8b57153c5aa/cpp/ycm/.ycm_extra_conf.py -O ~/.vim/.ycm_extra_conf.pyDownload .ycm_extra_conf.py and copy it to ~/.vim/.ycm_extra_conf.py to use as YouCompleteMe’s default configuration value.
4. Golang Environment Installation and Configuration
4.1. Golang Installation
- Install Golang and configure Golang-related environment variables.
4.2. vim-go Vim Plugin Installation
| |
Add the content from [File 3] to Vundle Plugins in the ~/.vimrc file to configure Vundle to install vim-go.
: PluginInstallInstall the vim-go Vim plugin. Execute in Vim command mode.
4.3. Golang Binary Installation
: GoInstallBinariesInstall tools required for Golang development. Execute in Vim command mode.
4.4. YouCompleteMe Reinstallation
$ cd ~/.vim/bundle/YouCompleteMe
$ ./install.py --clang-completer --gocode-completerCompile and install YouCompleteMe with the Golang option added.
5. Usage
5.1. YouCompleteMe
For C, Cpp projects, copy the ~/.vim/.ycm_extra_conf.py file to the project root folder to configure YouCompleteMe to work.
| Shortcut | Action |
|---|---|
| ctrl + p | YouCompleteMe Tag Jump |
| ctrl + o | Move to previous jump point (VIM shortcut) |
| ctrl + i | Move to next jump point (VIM shortcut) |
5.2. vim-clang-format
Auto Mode is a mode that automatically applies clang-format to files when saving.
| Shortcut | Action |
|---|---|
| \cf | Apply clang-format |
| \C | Enable/Disable Auto Mode |
5.3. vim-gutentags
vim-gutentags recognizes folders containing .git or .svn files as project root folders. If these files do not exist, you can create a .tag_root file in the project root folder to make vim-gutentags recognize the project root folder.
6. References
- Vundle: https://github.com/gmarik/Vundle.vim
- Colorscheme: https://github.com/junegunn/seoul256.vim
- YouCompleteMe Install: http://neverapple88.tistory.com/26