Differences

This shows you the differences between two versions of the page.

Link to this comparison view

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 ===== +Vim is one of my favorite tools. Whenever you are working and think, hey it 
-Installing vim with my plugins requires Vim with python. The reason for this is so that YCM works.  +would be really useful if I could do this, chances are Vim lets you do just that 
-There is an issue with YCMDVIM 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 Vim ===== 
 + 
 +Installing Vim with my plugins requires Vim with python. The reason for this is so that YCM works.  
 +There is an issue with YCMVim 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 VIM:+Follow this to compile Vim:
  
 <code bash> <code bash>
Line 20: Line 25:
 </code> </code>
  
-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:
      --prefix=/usr/local      --prefix=/usr/local
            
-make VIMRUNTIMEDIR=/usr/local/share/vim/vim80 -j8+make vimRUNTIMEDIR=/usr/local/share/vim/vim81 -j8
 sudo apt install checkinstall sudo apt install checkinstall
 sudo checkinstall sudo checkinstall
  
-sudo update-alternatives --install /usr/bin/editor editor /usr/local/bin/vim 1; +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 --set editor /usr/local/bin/vim  
-sudo update-alternatives --install /usr/bin/vi vi /usr/local/bin/vim 1;+sudo update-alternatives --install /usr/bin/vi vi /usr/local/bin/vim 1
 sudo update-alternatives --set vi /usr/local/bin/vim sudo update-alternatives --set vi /usr/local/bin/vim
 </code> </code>
  
 +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=/usr/local/share/vim/vim82 -j8
 +</code>
  
-    - git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim+Then grab the Vundle plugin manager. 
 +<code bash> 
 +git clone https://github.com/Vundlevim/Vundle.vim.git ~/.vim/bundle/Vundle.vim 
 +</code>
  
-Get the .vimrc file from git. It will contain this line that makes it work+Get the ''%%.vimrc%%'' file from my git repo [[https://github.com/paulsammut/paul_scripts/blob/master/install/res/.vimrc|link]].
  
-let g:ycm_server_python_interpreter = '/usr/bin/python'+Run Vim and use command <code vim>:PluginInstall</code> 
  
-Run vim and use command :PluginInstall . This will download the YCM plugin. +YouCompleteMe requires a bit more processing to install:
    
 <code bash> <code bash>
Line 67: Line 81:
 </code> </code>
  
-And then do this:+And then do this to get the autostyler to work:
 <code bash> <code bash>
-sudo apt install astyle      (this makes my auto styler work)+sudo apt install astyle      this makes my auto styler work
 </code> </code>
  
-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>
 /etc/apt/apt.conf.d/50unattended-upgrades /etc/apt/apt.conf.d/50unattended-upgrades
 +</code>
  
 It should look like this:  It should look like this: 
-<code>+<code bash>
 // List of packages to not update (regexp are supported) // List of packages to not update (regexp are supported)
 Unattended-Upgrade::Package-Blacklist { Unattended-Upgrade::Package-Blacklist {
Line 88: Line 104:
 </code> </code>
            
-==== Notes ====+===== General Notes =====
  
-Discussion on the python issue with YCM and VIM: https://github.com/Valloric/YouCompleteMe/issues/2136+Discussion on the python issue with YCM and Vim 
 +[[https://github.com/Valloric/YouCompleteMe/issues/2136|link]].
            
-<code> +<code vim
-:echo has("python")  +:echo has("python"    " this tells you if you have python2 support 
-    this tells you if you have python2 support+:echo has("python3"   this tells you if you have python3 support 
 +:ruby 1                 " Gives an error if ruby not present. 
 +</code>
  
-:echo has("python3") +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
-    this tells you if you have ruby installed. Gives an error if ruby not present.+
  
 +<code>
 +|buffer-variable|    b:   Local to the current buffer.
 +|window-variable|    w:   Local to the current window.
 +|tabpage-variable|   t:   Local to the current tab page.
 +|global-variable|    g:   Global.
 +|local-variable|     l:   Local to a function.
 +|script-variable|    s:   Local to a |:source|'ed Vim script.
 +|function-argument|  a:   Function argument (only inside a function).
 +|vim-variable|       v:   Global, predefined by Vim.
 </code> </code>
  
-If vim looks like it freezes inside tmux, it's because I accidentally pressed <C-s+The following command shows you all the variables that are set. 
-which disables flow control in the terminalJust hit <C-qand everything will be +<code vim
-alright.+:let g: 
 +</code> 
 + 
 +If you type a variable name afteryou will get what it is currently set to.  
 +<code vim
 +:let g:CommandTTraverseSCM 
 +</code> 
 + 
 +To go to a tab, do ''{count}gt'' where count is the tab number (first is one). 
 + 
 +Send one command while in insert mode: ''CTRL-O'' 
 + 
 +Open a link in mac with the cursor on it: ''gx .'' 
 + 
 +===== Snippets ===== 
 + 
 +To use snippets for repetive code, put that code in a folder. Then use the ''r: 
 +./location/of/snippet'' command to dump the text in the active buffer. Easy 
 +Pease! 
 + 
 +==== Editing Remote Files ==== 
 + 
 +To edit a remote file run the following command: 
 +<code bash
 +vim scp://user@myserver[:port]//path/to/file.txt 
 +</code>
  
 ===== 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't work out of the box. You need to dig through all kinds of documentation.
 +
 +=== For MacOS ===
 +
 +Install the patched font, then select the font in terminal.
 +
 +{{:screen_shot_2019-12-26_at_9.45.42_pm.png?400|}}
 +==== 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/warning display. You have to tell it where to use this script by adding this in error/warning display. You have to tell it where to use this script by adding this in
-the .vimrc file:+the ''%%.vimrc%%'' file:
  
-    let g:ycm_global_ycm_extra_conf = '~/.vim/.ycm_extra_conf.py'+<code vim> 
 +let g:ycm_global_ycm_extra_conf = '~/.vim/.ycm_extra_conf.py' 
 +</code>
  
-There is a good write up about this here: +This is a good write up about YCM [[https://jonasdevlieghere.com/a-better-youcompleteme-config/|link]]
-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+
  
 +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!!!!+ 
 +=== 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. 
  
-    gui == gvim. +<code> 
-    cterm == terminal. +gui == gvim. 
-    fg == foreground +cterm == terminal. 
-    bg == background+fg == foreground 
 +bg == background 
 +</code>
  
 You can also style the line that has the warning/error with these groups: You can also style the line that has the warning/error with these groups:
  
-*YcmErrorLine*, which falls back to group SyntasticErrorLine if it exists +''%%YcmErrorLine%%'' which falls back to group SyntasticErrorLine if it exists 
-*YcmWarningLine*, which falls back to group SyntasticWarningLine 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/warnings: 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 +''%%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+''%%YcmWarningSection%%'' which falls back to group SyntasticWarning if it exists and then SpellCap
  
-So to change the warning highlight color, would say: +So to change the warning highlight color, would say: 
  
 +<code vim>
 highlight YcmWarningSection ctermfg=XTERMCOLORNUMBER highlight YcmWarningSection ctermfg=XTERMCOLORNUMBER
 +</code>
  
 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 ~/.vim/bundle/command-t and type in rake make. This +For the command-t plugin, you need to go to ''%%~/.vim/bundle/command-t%%'' and 
-is to fix the command-t.vim could not load the c extension error.+type in ''%%rake make%%''. This is to fix the command-t "vim could not load the 
 +c extensionerror.
  
-The documenation here has a great how to sectionhttps://github.com/wincent/command-t/blob/master/doc/command-t.txt+The documenation here has a great how-to section [[https://github.com/wincent/command-t/blob/master/doc/command-t.txt|link]]. 
  
-Press leader-t and you done. Leader is the \. To cancel (dismiss a file listing) +<code> 
-press <C-c>+Leader - t  to open search 
 +<C-c>       to cancel (dismiss a file listing) 
 +<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 "pwd" which is the current  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!!! 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
 +</code>
 +
 +Some of the ones I use are:
 +<code>
 +]e    move line up
 +[e    move line down
 +</code>
 +
 +
 +===== vim Operations =====
  
 ==== Exuberant Ctags ==== ==== 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.+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 sudo apt install exuberant-ctags
 +</code>
  
-run ctags -R * in the project directory +Then run this in the project directory to generate the tags.
-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't  +
-exist. I fixed this by not compiling it with xsmpl.+
  
-===== Vim Operations =====+<code bash> 
 +ctags -R *  
 +</code> 
 + 
 +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:
  
-<code>+<code vim>
 :%s/\%Vselection/replace/g :%s/\%Vselection/replace/g
 </code> </code>
 +
 ==== 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/scope
 +[m  " Jump backwords to begin of previous method/scope
  
-<code> +][  " Jump forward to end of current toplevel 
-]] Jump forward to begin of next toplevel +[]  " Jump backward to end of previous of toplevel 
-[[ Jump backwards to begin of current toplevel (if already there, previous toplevel) +]M  " Jump forward to end of current method/scope 
-]m Jump forward to begin of next method/scope +[M  " Jump backward to end of previous 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+
 </code> </code>
  
Line 211: Line 313:
 I use plugin [[https://github.com/tomtom/tcomment_vim|tcomment]] for commenting lines. Keybindings are: I use plugin [[https://github.com/tomtom/tcomment_vim|tcomment]] for commenting lines. Keybindings are:
  
-<code> +<code vim
-gc{motion}          :: Toggle comments  +gc{motion}          Toggle comments  
-gc<Count>c{motion}  :: Toggle comment with count argument                    +gc<Count>c{motion}  Toggle comment with count argument                    
-gcc                 :: Toggle comment for the current line +gcc                 Toggle comment for the current line 
-ctrl - -            :: Toggle comment for the current line+ctrl - -            Toggle comment for the current line
  </code>  </code>
  
 ==== Programming ==== ==== Programming ====
 +<code vim>
 +<leader> r          " Toggle true/false
 +</code>
 +
 +==== Ordered Number List ====
 +
 +Make a list of 1's, then block select the second one, and then press g <cnrl-a>.
 +
 +==== Quickfix ====
 +
 +{{ :quickfix.png?400 |}}
 +
 +To navigate to the quick fix, <C-w> j. 
 +
 +==== Vidir ====
 +
 +To edit filenames in a directory using Vim, use the linux executable ''%%vidir%%'' from the ''%%moreutils%%'' package. Changes take effect after exiting.
 +===== Programming C/C++ in Vim =====
 +
 +I use YCM and ctags extensively while coding in C/C++.
 +
 +=== Vim Shortcuts ===
 <code> <code>
-<leader         :: Toggle true/false+ 
 +<C-wgf    Opens file under cursor in new tab 
 + 
 +K           Get documentation info pop up its man page.  
 + 
 +[i          Pressing on a function gives its signature.
 </code> </code>
 +
 +==== File Management ====
 +
 +''%%:checkpath%%''  shows you a list of included files not found in the path.
 +
 +''%%$locate [header]%%''  gives you the location of the system header file.
  
 ===== Troubleshooting ===== ===== Troubleshooting =====
  
-If VIM is slow in tmux:+If Vim is slow in tmux:
  
-Link: Problem https://github.com/christoomey/dotfiles/issues/13 +Link: [[https://github.com/christoomey/dotfiles/issues/13|Problem]] 
-Link: Helpful http://usevim.com/2012/04/18/startuptime/+Link: [[http://usevim.com/2012/04/18/startuptime/|Helpful]]
  
 Issue is because of xsmp init. Vim is trying to connect Issue is because of xsmp init. Vim is trying to connect
 +
 +
  • vim.1550264966.txt.gz
  • Last modified: 2019/02/15 21:09
  • by paul