Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
vim [2019/01/18 14:15] paul [Commenting] |
vim [2020/10/19 17:24] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== Vim ====== | ====== Vim ====== | ||
- | ===== Movement | + | Vim is one of my favorite tools. Whenever you are working and think, hey it |
+ | would be really useful if I could do this, chances are Vim lets you do just that | ||
+ | in a couple of keystrokes. | ||
+ | |||
+ | ===== 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 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 | ||
+ | install ruby for the fantastic Command-T plugin to work. | ||
+ | |||
+ | Follow this to compile Vim: | ||
+ | |||
+ | <code bash> | ||
+ | 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 ==== | ||
+ | |||
+ | To compile execute the following. | ||
+ | |||
+ | <code bash> | ||
+ | cd | ||
+ | git clone https:// | ||
+ | cd vim | ||
+ | git checkout | ||
+ | |||
+ | ./configure --with-features=huge \ | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | make vimRUNTIMEDIR=/ | ||
+ | sudo apt install checkinstall | ||
+ | sudo checkinstall | ||
+ | |||
+ | sudo update-alternatives --install / | ||
+ | sudo update-alternatives --set editor / | ||
+ | sudo update-alternatives --install /usr/bin/vi 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=/ | ||
+ | </ | ||
+ | |||
+ | Then grab the Vundle plugin manager. | ||
+ | <code bash> | ||
+ | git clone https:// | ||
+ | </ | ||
+ | |||
+ | Get the '' | ||
+ | |||
+ | Run Vim and use command <code vim>: | ||
+ | |||
+ | YouCompleteMe requires a bit more processing to install: | ||
+ | |||
+ | <code bash> | ||
+ | cd .vim/ | ||
+ | ./ | ||
+ | </ | ||
+ | |||
+ | And then do this to get the autostyler to work: | ||
+ | <code bash> | ||
+ | sudo apt install astyle | ||
+ | </ | ||
+ | |||
+ | 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: | ||
+ | |||
+ | <code bash> | ||
+ | / | ||
+ | </ | ||
+ | |||
+ | It should look like this: | ||
+ | <code bash> | ||
+ | // List of packages to not update (regexp are supported) | ||
+ | Unattended-Upgrade:: | ||
+ | " | ||
+ | // | ||
+ | // | ||
+ | // | ||
+ | }; | ||
+ | </ | ||
+ | |||
+ | ===== General Notes ===== | ||
+ | |||
+ | Discussion on the python issue with YCM and Vim | ||
+ | [[https:// | ||
+ | |||
+ | <code vim> | ||
+ | :echo has(" | ||
+ | :echo has(" | ||
+ | :ruby 1 " | ||
+ | </ | ||
+ | |||
+ | If Vim looks like it freezes inside tmux, it's because I accidentally pressed < | ||
+ | which disables flow control in the terminal. Just hit <C-q> and everything will be | ||
+ | alright. | ||
+ | |||
+ | There are things called internal-variables in Vim. | ||
< | < | ||
- | ]] Jump forward | + | |buffer-variable| |
- | [[ Jump backwards | + | |window-variable| |
- | ]m Jump forward | + | |tabpage-variable| |
- | [m Jump backwords | + | |global-variable| |
+ | |local-variable| | ||
+ | |script-variable| | ||
+ | |function-argument| | ||
+ | |vim-variable| | ||
+ | </code> | ||
- | ][ Jump forward to end of current toplevel | + | The following command shows you all the variables that are set. |
- | [] Jump backward to end of previous of toplevel | + | <code vim> |
- | ]M Jump forward to end of current method/ | + | :let g: |
- | [M Jump backward to end of previous method/ | + | |
</ | </ | ||
- | ===== Commenting ===== | + | If you type a variable name after, you will get what it is currently set to. |
+ | <code vim> | ||
+ | :let g: | ||
+ | </ | ||
- | I use plugin [[https://github.com/tomtom/tcomment_vim|tcomment]] for commenting lines. Keybindings | + | 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 ===== | ||
+ | |||
+ | The following is info on the plugins | ||
+ | |||
+ | ==== Airline ==== | ||
+ | |||
+ | It took me so long to figure this stupid | ||
+ | |||
+ | === 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 uses a python script to tell it what to do in terms of syntax highlighting and | ||
+ | error/ | ||
+ | the '' | ||
+ | |||
+ | <code vim> | ||
+ | let g: | ||
+ | </ | ||
+ | |||
+ | This is a good write up about YCM [[https://jonasdevlieghere.com/a-better-youcompleteme-config/|link]] | ||
+ | |||
+ | I used this '' | ||
+ | me a stupid warning that obscures | ||
+ | everything ((https:// | ||
+ | |||
+ | |||
+ | === 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' | ||
+ | worry about that. We use cterm colors, and there are ctermfg and ctermbg. | ||
< | < | ||
- | gc{motion} | + | gui == gvim. |
- | gc< | + | cterm == terminal. |
- | gcc :: Toggle comment for the current line | + | fg == foreground |
+ | bg == background | ||
+ | </ | ||
+ | |||
+ | You can also style the line that has the warning/ | ||
+ | |||
+ | '' | ||
+ | '' | ||
+ | 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/ | ||
+ | |||
+ | '' | ||
+ | '' | ||
+ | |||
+ | So to change the warning highlight color, I would say: | ||
+ | |||
+ | <code vim> | ||
+ | highlight YcmWarningSection ctermfg=XTERMCOLORNUMBER | ||
+ | </ | ||
+ | |||
+ | The xterm color numbers are 3 digit numbers. Look em up. | ||
+ | |||
+ | ==== Command-T ==== | ||
+ | For the command-t plugin, you need to go to '' | ||
+ | type in '' | ||
+ | c extension" | ||
+ | |||
+ | The documenation here has a great how-to section [[https:// | ||
+ | |||
+ | < | ||
+ | Leader - t to open search | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | 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 " | ||
+ | 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 ==== | ||
+ | |||
+ | Vim has native c-tags functionality but requires you to install a program and | ||
+ | run it in the project folder. | ||
+ | |||
+ | <code bash> | ||
+ | sudo apt install exuberant-ctags | ||
+ | </ | ||
+ | |||
+ | Then run this in the project directory to generate the tags. | ||
+ | |||
+ | <code bash> | ||
+ | ctags -R * | ||
+ | </ | ||
+ | |||
+ | Then in Vim just go over any text you want and press <C-]> to go to the token. | ||
+ | |||
+ | ==== 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: | ||
+ | |||
+ | <code vim> | ||
+ | : | ||
+ | </ | ||
+ | |||
+ | ==== 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 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/ | ||
+ | </ | ||
+ | |||
+ | ==== Commenting ==== | ||
+ | |||
+ | I use plugin [[https:// | ||
+ | |||
+ | <code vim> | ||
+ | gc{motion} | ||
+ | gc< | ||
+ | gcc " Toggle comment for the current line | ||
+ | ctrl - - " | ||
</ | </ | ||
+ | |||
+ | ==== 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 === | ||
+ | < | ||
+ | |||
+ | <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 ===== | ||
+ | |||
+ | If Vim is slow in tmux: | ||
+ | |||
+ | Link: [[https:// | ||
+ | Link: [[http:// | ||
+ | |||
+ | Issue is because of xsmp init. Vim is trying to connect | ||
+ | |||