This is an old revision of the document!
Vim
Installing VIM
Installing vim with my plugins requires Vim with python. The reason for this is so that YCM works. There is an issue with YCMD, VIM and Ubuntu 16.04 which is a conflict between python 2 and 3. What we do is pic vim to compile with python2 and set YCM to also compile with just python2. We then have to run an install script which makes it work. Also, this compilation of VIM gives us the awesome clipboard support that works right out of the box. We also install ruby for the fantastic Command-T plugin to work.
Follow this to compile VIM:
sudo apt-get install cmake libncurses5-dev libgnome2-dev libgnomeui-dev \ libgtk2.0-dev libatk1.0-dev libbonoboui2-dev \ libcairo2-dev libx11-dev libxpm-dev libxt-dev python-dev \ python3-dev ruby-dev lua5.1 lua5.1-dev libperl-dev git
- sudo apt-get remove vim vim-runtime gvim vim-common
Make sure vim is removed! When you type vim you should see nothing
Compiling
cd git clone https://github.com/vim/vim.git cd vim git checkout ./configure --with-features=huge \ --enable-multibyte \ --enable-rubyinterp=yes \ --enable-pythoninterp=yes \ --with-python-config-dir=/usr/lib/python2.7/config \ --enable-python3interp=no \ --with-python3-config-dir=/usr/lib/python3.5/config \ --enable-perlinterp=yes \ --enable-luainterp=yes \ --enable-gui=gtk2 \ --enable-cscope \ --prefix=/usr/local make VIMRUNTIMEDIR=/usr/local/share/vim/vim80 -j8 sudo apt install checkinstall sudo checkinstall sudo update-alternatives --install /usr/bin/editor editor /usr/local/bin/vim 1; sudo update-alternatives --set editor /usr/local/bin/vim; sudo update-alternatives --install /usr/bin/vi vi /usr/local/bin/vim 1; sudo update-alternatives --set vi /usr/local/bin/vim
- git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
Get the .vimrc file from git. It will contain this line that makes it work:
let g:ycm_server_python_interpreter = '/usr/bin/python'
Run vim and use command :PluginInstall . This will download the YCM plugin.
- cd .vim/bundle/YouCompleteMe - ./install.py --clang-completer
And then do this:
- sudo apt install astyle (this makes my auto styler work)
Also disable the unattended updates. If you do not do this, every day vim will get downgraded to 7.4.1689. To do this, add vim to the black list, by editing:
/etc/apt/apt.conf.d/50unattended-upgrades
It should look like this:
// List of packages to not update (regexp are supported) Unattended-Upgrade::Package-Blacklist { "vim"; // "libc6"; // "libc6-dev"; // "libc6-i686"; };
Notes
Discussion on the python issue with YCM and VIM: https://github.com/Valloric/YouCompleteMe/issues/2136
:echo has("python") - this tells you if you have python2 support :echo has("python3") - this tells you if you have python3 support :ruby 1 - this tells you if you have ruby installed. Gives an error if ruby not present.
If vim looks like it freezes inside tmux, it's because I accidentally pressed <C-s> which disables flow control in the terminal. Just hit <C-q> and everything will be alright.
Plugins
YCM
YCM uses a python script to tell it what to do in terms of syntax highlighting and error/warning display. You have to tell it where to use this script by adding this in the .vimrc file:
let g:ycm_global_ycm_extra_conf = '~/.vim/.ycm_extra_conf.py'
There is a good write up about this here: https://jonasdevlieghere.com/a-better-youcompleteme-config/ I used this .ycm_extra_conf.py file because it had the new -std flags and didn't give me a stupid warning that obscures everything. https://github.com/arximboldi/dotfiles/blob/master/emacs/.ycm_extra_conf.py
YCM Colors!!!!
Ok so YCM uses highlighting colors to change the colors of errors. Default they are red, and they cover any text making it super annoying. SO. You have to change the color. THIS IS NOT EASY as there are like a bajillion different colors. There are cterm colors and gui colors. Gui colors are for gvim, which we don't use so don't worry about that. We use cterm colors, and there are ctermfg and ctermbg.
gui == gvim. cterm == terminal. fg == foreground bg == background
You can also style the line that has the warning/error with these groups:
*YcmErrorLine*, which falls back to group SyntasticErrorLine if it exists *YcmWarningLine*, which falls back to group SyntasticWarningLine if it exists Note that the line highlighting groups only work when gutter signs are turned on.
The syntax groups used to highlight regions of text with errors/warnings:
*YcmErrorSection*, which falls back to group SyntasticError if it exists and then SpellBad *YcmWarningSection*, which falls back to group SyntasticWarning if it exists and then SpellCap
So to change the warning highlight color, i would say:
highlight YcmWarningSection ctermfg=XTERMCOLORNUMBER
The xterm color numbers are 3 digit numbers. Look em up.
Command-T
command-t plugin, need to go into ~/.vim/bundle/command-t and type in rake make. This is to fix the command-t.vim could not load the c extension error.
The documenation here has a great how to section: https://github.com/wincent/command-t/blob/master/doc/command-t.txt
Press leader-t and you done. Leader is the \. To cancel (dismiss a file listing) press <C-c>
I always got confused with Command T's starting search directory. And I had good reason! It uses what is called SCM traversal, which finds the git repo the file you're working with is in and uses that as the search directory. Smart for stuff where the main project is in one git repo, but sucky for stuff that is in a bigger repo. SO. I just had to set it the traversal to “pwd” which is the current directory the file is in. Ok no more wasting time!!!
Exuberant Ctags
c-tags isn't a plugin but requires you to install a program and run it in the project folder. VIM has native ctags functionality.
sudo apt install exuberant-ctags
run ctags -R * in the project directory Then in vim just go over any text you want and press <C-]> to go to the token's implementation
Troubleshooting
If VIM is slow in tmux:
Link: Problem https://github.com/christoomey/dotfiles/issues/13 Link: Helpful http://usevim.com/2012/04/18/startuptime/
Issue is because of xsmp init. Vim is trying to connect to an x server that doesn't exist. I fixed this by not compiling it with xsmpl.
Vim Operations
General Operations
To search and replace within a visual selection within a line you must use the %V atom. Make a selection and use the following command:
:%s/\%Vselection/replace/g
Movement
]] Jump forward to begin of next toplevel [[ Jump backwards to begin of current toplevel (if already there, previous toplevel) ]m Jump forward to begin of next method/scope [m Jump backwords to begin of previous method/scope ][ Jump forward to end of current toplevel [] Jump backward to end of previous of toplevel ]M Jump forward to end of current method/scope [M Jump backward to end of previous method/scope
Commenting
I use plugin tcomment for commenting lines. Keybindings are:
gc{motion} :: Toggle comments gc<Count>c{motion} :: Toggle comment with count argument gcc :: Toggle comment for the current line ctrl - - :: Toggle comment for the current line
Programming
<leader> r :: Toggle true/false