Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
vim [2019/02/15 21:09] paul [Compiling] |
vim [2020/10/19 17:24] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== Vim ====== | ====== Vim ====== | ||
- | ===== Installing | + | Vim is one of my favorite tools. Whenever you are working and think, hey it |
- | Installing | + | would be really useful if I could do this, chances are Vim lets you do just that |
- | There is an issue with YCMD, VIM and Ubuntu 16.04 which is a conflict between python 2 and 3. | + | in a couple of keystrokes. |
- | 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 | + | ===== Installing |
+ | |||
+ | Installing | ||
+ | There is an issue with YCM, Vim and Ubuntu 16.04 which is a conflict between python 2 and 3. | ||
+ | What we do is configure 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 | 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. | install ruby for the fantastic Command-T plugin to work. | ||
- | Follow this to compile | + | Follow this to compile |
<code bash> | <code bash> | ||
Line 20: | Line 25: | ||
</ | </ | ||
- | Make sure vim is removed! When you type vim you should see nothing | + | Make sure Vim is removed! When you type vim you should see nothing |
==== Compiling ==== | ==== Compiling ==== | ||
+ | |||
+ | To compile execute the following. | ||
+ | |||
<code bash> | <code bash> | ||
cd | cd | ||
Line 28: | Line 36: | ||
cd vim | cd vim | ||
git checkout | git checkout | ||
- | |||
./configure --with-features=huge \ | ./configure --with-features=huge \ | ||
Line 43: | Line 50: | ||
| | ||
- | make VIMRUNTIMEDIR=/ | + | make vimRUNTIMEDIR=/ |
sudo apt install checkinstall | sudo apt install checkinstall | ||
sudo checkinstall | sudo checkinstall | ||
- | sudo update-alternatives --install / | + | sudo update-alternatives --install / |
- | sudo update-alternatives --set editor / | + | sudo update-alternatives --set editor / |
- | sudo update-alternatives --install /usr/bin/vi vi / | + | sudo update-alternatives --install /usr/bin/vi vi / |
sudo update-alternatives --set vi / | sudo update-alternatives --set vi / | ||
</ | </ | ||
+ | Be sure to change the version when executing the make command. For instance, if the major Vim version is at 8.2, then make line should be: | ||
+ | <code bash> | ||
+ | make vimRUNTIMEDIR=/ | ||
+ | </ | ||
- | - git clone https:// | + | Then grab the Vundle plugin manager. |
+ | <code bash> | ||
+ | git clone https:// | ||
+ | </ | ||
- | Get the .vimrc file from git. It will contain this line that makes it work: | + | Get the '' |
- | let g:ycm_server_python_interpreter = '/usr/ | + | Run Vim and use command <code vim>:PluginInstall< |
- | Run vim and use command | + | YouCompleteMe requires a bit more processing to install: |
<code bash> | <code bash> | ||
Line 67: | Line 81: | ||
</ | </ | ||
- | And then do this: | + | And then do this to get the autostyler to work: |
<code bash> | <code bash> | ||
- | sudo apt install astyle | + | sudo apt install astyle |
</ | </ | ||
- | Also disable the unattended updates. If you do not do this, every day vim will get | + | 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: | + | downgraded to 7.4.1689. To do this, add Vim to the black list, by editing: |
+ | <code bash> | ||
/ | / | ||
+ | </ | ||
It should look like this: | It should look like this: | ||
- | < | + | < |
// List of packages to not update (regexp are supported) | // List of packages to not update (regexp are supported) | ||
Unattended-Upgrade:: | Unattended-Upgrade:: | ||
Line 88: | Line 104: | ||
</ | </ | ||
- | ==== Notes ==== | + | ===== General |
- | Discussion on the python issue with YCM and VIM: https:// | + | Discussion on the python issue with YCM and Vim |
+ | [[https:// | ||
- | < | + | < |
- | :echo has(" | + | :echo has(" |
- | | + | :echo has(" |
+ | :ruby 1 " | ||
+ | </ | ||
- | :echo has(" | + | If Vim looks like it freezes inside tmux, it's because I accidentally pressed <C-s> |
- | - this tells you if you have python3 support | + | which disables flow control in the terminal. Just hit <C-q> and everything will be |
+ | alright. | ||
- | :ruby 1 | + | There are things called internal-variables in Vim. |
- | | + | |
+ | < | ||
+ | |buffer-variable| | ||
+ | |window-variable| | ||
+ | |tabpage-variable| | ||
+ | |global-variable| | ||
+ | |local-variable| | ||
+ | |script-variable| | ||
+ | |function-argument| | ||
+ | |vim-variable| | ||
</ | </ | ||
- | If vim looks like it freezes inside tmux, it's because I accidentally pressed | + | The following command shows you all the variables that are set. |
- | which disables flow control | + | < |
- | alright. | + | :let g: |
+ | </ | ||
+ | |||
+ | If you type a variable name after, you will get what it is currently set to. | ||
+ | <code vim> | ||
+ | :let g: | ||
+ | </ | ||
+ | |||
+ | To go to a tab, do '' | ||
+ | |||
+ | Send one command while in insert mode: '' | ||
+ | |||
+ | Open a link in mac with the cursor on it: '' | ||
+ | |||
+ | ===== Snippets ===== | ||
+ | |||
+ | To use snippets for repetive code, put that code in a folder. Then use the '' | ||
+ | ./ | ||
+ | Pease! | ||
+ | |||
+ | ==== Editing Remote Files ==== | ||
+ | |||
+ | To edit a remote file run the following command: | ||
+ | <code bash> | ||
+ | vim scp:// | ||
+ | </ | ||
===== Plugins ===== | ===== Plugins ===== | ||
+ | |||
+ | The following is info on the plugins I use. | ||
+ | |||
+ | ==== Airline ==== | ||
+ | |||
+ | It took me so long to figure this stupid plugin out. It doesn' | ||
+ | |||
+ | === For MacOS === | ||
+ | |||
+ | Install the patched font, then select the font in terminal. | ||
+ | |||
+ | {{: | ||
+ | ==== NerdTree ==== | ||
+ | |||
+ | NerdTree is one of my most used plugins. It is fantastic at navigating files, | ||
+ | along with moving and deleting them. There are a bunch of really useful | ||
+ | key mappings that I forget from time to time. Just remember to press ? in an open | ||
+ | NerdTree buffer and you'll get all the shortcuts to refresh yourself with. | ||
+ | |||
==== YCM ==== | ==== YCM ==== | ||
YCM uses a python script to tell it what to do in terms of syntax highlighting and | YCM uses a python script to tell it what to do in terms of syntax highlighting and | ||
error/ | error/ | ||
- | the .vimrc file: | + | the '' |
- | | + | <code vim> |
+ | let g: | ||
+ | </ | ||
- | There is a good write up about this here: | + | This is a good write up about YCM [[https:// |
- | https:// | + | |
- | 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:// | + | |
+ | I used this '' | ||
+ | me a stupid warning that obscures | ||
+ | everything ((https:// | ||
- | YCM Colors!!!! | + | |
+ | === YCM Colors | ||
Ok so YCM uses highlighting colors to change the colors of errors. Default they are | Ok so YCM uses highlighting colors to change the colors of errors. Default they are | ||
Line 132: | Line 206: | ||
worry about that. We use cterm colors, and there are ctermfg and ctermbg. | worry about that. We use cterm colors, and there are ctermfg and ctermbg. | ||
- | | + | < |
- | cterm == terminal. | + | gui == gvim. |
- | fg == foreground | + | cterm == terminal. |
- | bg == background | + | fg == foreground |
+ | bg == background | ||
+ | </ | ||
You can also style the line that has the warning/ | You can also style the line that has the warning/ | ||
- | *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. | 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/ | The syntax groups used to highlight regions of text with errors/ | ||
- | *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, | + | So to change the warning highlight color, |
+ | <code vim> | ||
highlight YcmWarningSection ctermfg=XTERMCOLORNUMBER | highlight YcmWarningSection ctermfg=XTERMCOLORNUMBER | ||
+ | </ | ||
The xterm color numbers are 3 digit numbers. Look em up. | The xterm color numbers are 3 digit numbers. Look em up. | ||
- | |||
==== Command-T ==== | ==== Command-T ==== | ||
- | command-t plugin, need to go into ~/ | + | For the command-t plugin, |
- | is to fix the command-t.vim could not load the c extension error. | + | type in '' |
+ | c extension" | ||
- | The documenation here has a great how to section: https:// | + | The documenation here has a great how-to section |
- | Press leader-t and you done. Leader is the \. To cancel (dismiss a file listing) | + | < |
- | press <C-c> | + | Leader |
+ | < | ||
+ | <C-v> opens file in new split window | ||
+ | </code> | ||
I always got confused with Command T's starting search directory. And I had good | I always got confused with Command T's starting search directory. And I had good | ||
Line 170: | Line 251: | ||
repo. SO. I just had to set it the traversal to " | repo. SO. I just had to set it the traversal to " | ||
directory the file is in. Ok no more wasting time!!! | directory the file is in. Ok no more wasting time!!! | ||
+ | |||
+ | ===== unimpared ===== | ||
+ | |||
+ | unimpared is a Tim Pope plugin that provides a set of key mappings paired with | ||
+ | brackets. There are lots of ones I use regularly and to refresh do | ||
+ | |||
+ | <code vim> | ||
+ | :help unimpared | ||
+ | </ | ||
+ | |||
+ | Some of the ones I use are: | ||
+ | < | ||
+ | ]e move line up | ||
+ | [e move line down | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== vim Operations ===== | ||
==== Exuberant Ctags ==== | ==== Exuberant Ctags ==== | ||
- | c-tags | + | Vim has native |
+ | run it in the project folder. | ||
+ | <code bash> | ||
sudo apt install exuberant-ctags | sudo apt install exuberant-ctags | ||
+ | </ | ||
- | run ctags -R * in the project directory | + | Then run this in the project directory to generate |
- | Then in vim just go over any text you want and press <C-]> to go to the token' | + | |
- | implementation | + | |
- | to an x server that doesn' | + | |
- | exist. I fixed this by not compiling it with xsmpl. | + | |
- | ===== Vim Operations ===== | + | <code bash> |
+ | ctags -R * | ||
+ | </ | ||
+ | |||
+ | Then in Vim just go over any text you want and press <C-]> to go to the token. | ||
==== General Operations ==== | ==== General Operations ==== | ||
Line 189: | Line 291: | ||
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: | 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: | ||
- | < | + | < |
: | : | ||
</ | </ | ||
+ | |||
==== Movement ==== | ==== Movement ==== | ||
+ | <code vim> | ||
+ | ]] " 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/ | ||
+ | [m " Jump backwords to begin of previous method/ | ||
- | < | + | ][ " |
- | ]] Jump forward to begin of next toplevel | + | [] " |
- | [[ Jump backwards to begin of current toplevel (if already there, previous toplevel) | + | ]M " |
- | ]m Jump forward to begin of next method/ | + | [M " |
- | [m Jump backwords to begin of previous method/ | + | |
- | + | ||
- | ][ Jump forward to end of current toplevel | + | |
- | [] Jump backward to end of previous of toplevel | + | |
- | ]M Jump forward to end of current method/ | + | |
- | [M Jump backward to end of previous method/ | + | |
</ | </ | ||
Line 211: | Line 313: | ||
I use plugin [[https:// | I use plugin [[https:// | ||
- | < | + | < |
- | gc{motion} | + | gc{motion} |
- | gc< | + | gc< |
- | gcc :: Toggle comment for the current line | + | gcc " |
- | ctrl - - | + | ctrl - - |
</ | </ | ||
==== Programming ==== | ==== Programming ==== | ||
+ | <code vim> | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | ==== Ordered Number List ==== | ||
+ | |||
+ | Make a list of 1's, then block select the second one, and then press g < | ||
+ | |||
+ | ==== Quickfix ==== | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | To navigate to the quick fix, <C-w> j. | ||
+ | |||
+ | ==== Vidir ==== | ||
+ | |||
+ | To edit filenames in a directory using Vim, use the linux executable '' | ||
+ | ===== Programming C/C++ in Vim ===== | ||
+ | |||
+ | I use YCM and ctags extensively while coding in C/C++. | ||
+ | |||
+ | === Vim Shortcuts === | ||
< | < | ||
- | <leader> r :: Toggle true/false | + | |
+ | <C-w> gf Opens file under cursor in new tab | ||
+ | |||
+ | K Get documentation info pop up its man page. | ||
+ | |||
+ | [i Pressing on a function gives its signature. | ||
</ | </ | ||
+ | |||
+ | ==== File Management ==== | ||
+ | |||
+ | '' | ||
+ | |||
+ | '' | ||
===== Troubleshooting ===== | ===== Troubleshooting ===== | ||
- | If VIM is slow in tmux: | + | If Vim is slow in tmux: |
- | Link: Problem | + | Link: [[https:// |
- | Link: Helpful | + | Link: [[http:// |
Issue is because of xsmp init. Vim is trying to connect | Issue is because of xsmp init. Vim is trying to connect | ||
+ | |||
+ |