Skip to content
Tomas Baca edited this page Dec 28, 2020 · 5 revisions

Vim

Vim has been heavily pluginized in this setup, which makes it more like IDE than a simple terminal editor. Plugins are maintained by a plugin manager called vim-plug, which should download them from their repositories automatically. To update them manually, call :PlugUpdate, to install them :PlugInstall in Vim. However, they will be installed automatically by install.sh.

Despite most of my key bindings might seem a bit arbitrary, they evolved in a time to match my needs and habits (no arrow keys, no mouse). Although it was not easy to find a way to navigate using h/j/k/l in all scenarios, it is possible most of the time. Just imagine you can navigate and swap windows in i3wm (alt + h/j/k/l, alt-shift + h/j/k/l), then navigate over panes in tmux (ctrl + h/j/k/l), then splits in vim (also ctrl + h/j/k/l), then move over suggestions from YouCompleteMe (ctrl + j/k, l), and lastly navigating through placeholders in newly inserted snippet (shift h/l). And I almost forgot, you navigate using h/j/k/l in vim! Yes, I am weird, but it works :-).. continue reading if you are interested.

List of plugins

Here is a list of plugins I use. I divide plugins into two groups according to how they integrate into my workflow. Plugins with new features, you are supposed to read their tutorials to know how to use them (but you don't have to if it does not suite you):

  • vim-fugitive - git integration
  • vimux - tmux integration
  • vim-tmux-runner - another tmux integration, slightly different than vimux
  • nerdtree - simple integrated file explorer
  • vim-abolish - automatic substitutions
  • ultisnips - code snippets
  • ReplaceWithRegister - adds "gr" action to replace text
  • vim-argwrap - clever function argumment wrapping
  • vim-multiple-cursors - adding mupltiple cursors feature
  • tagbar - windows with tag list of the current file
  • vim-ros - ROS integration
  • vim-commentary - clever code commenting
  • vim-surround - allows to manipulate with surrounding pairs of characters
  • vimtex - latex integration
  • vimwiki - notetaking and wikipedia editting
  • vim-exchange - allows exchaning two target locations
  • vim-unimpaired - clever new keybindings for e.g. quickfix and buffers
  • vim-clang-format - integration of clang-format -- c++ auto formatter
  • ctrl-p - great fuzzy finder
  • vim-easy-align - autoaligning text

Plugins you don't need to know about (their features integrate "seemlessly"):

  • vim-plug - vim plugin manager
  • jellybeans.vim - color scheme
  • vim-airline - status line
  • united-front - sharing register between vim instances
  • vim-startify - new home screen for vim
  • vim-signature - shows marks left to line numbers
  • targets.vim - additional target descriptions, that feel natural
  • vim-python-pep8-indent - python integration
  • GoldenView.Vim - split resizing in golden ratio
  • quick-scope - f/t motion helper
  • supertab - allows youcompleteme to work with ultisnips
  • youcompleteme - automatic code-aware code completion
  • tmuxline.vim - tmux and vim statusline integration
  • MatlabFilesEdition - should add matlab syntax highlighting
  • vim-tmux-navigator - makes tmux and vim split navigation possible
  • repeat.vim - makes "." work with some plugins (e.g. vim-surround)

New mappings?

My new mapping for moving within vim:

  • shift j/k move to next/previous tab
  • ctrl-h/j/k/l move to left/down/up/right split

Here is a short description of the most important plugins together with an example of their usage:

Startify

Run vim without parameters! Really, try that. Startify shows a useful list of recently opened files when running vim without parameters. It also allows to save and load sessions. Save the current session by calling

:SSave

you will be prompted to enter the name of the session. You can later see the session on the main Startify screen. Startify also displays random vim tips in the form of a 'barking dog'. Feel free to update those and submit them using a pull request on a file appconfig/vim/startify_quotes.txt.

  • <leader>s - opens new vim tab and shows Startify

NERDTree

NERDTree provides a simple file browser within a split. Toggle it by <leader>n. The current setup shows NERDTree also when you open vim with a folder in the argument. Read its documentation for further information.

  • <leader>t - opens new vim tab and shows NERDTree

Vimmux

Vimmux allows to open TMUX splits and run commands in them. I use them mainly for compiling my workspace. Commands can be configured in the ~/.my.vimrc file which will stay unchanged by git during updates.

United-front

This plugin allows sharing registers between different instances of vim. Thus allows to copy and paste regardless of splitting in vim od TMUX.

YouCompleteMe

Want to work like a pro in an IDE? Vim can do that. YouCompleteMe provides state-of-the-art code completion functions. YCM uses Clang compiler to make up suggestions and detect syntax and semantic errors in your code. Clang needs to know compile flags for your particular piece of code.

Key mappings for youcompleteme:

  • When suggestions appear, press either tab, up/down, ctrl-j/k to move within the menu.
  • When you are in the menu, move within it using tab, up/down, ctrl-j/k or j/k.
  • To confirm the selection, press enter or l.
  • If the suggestions spawn a code snippet, move by shift-h/l between its parts.

C++ and ROS code completion

To allow full ROS code completion, follow those:

  • Make sure a bash variable $ROS_WORKSPACE is set in your .bashrc. It should contain a list of locations of your ROS workspace(s), separated by spaces.
  • Since now, build your workspace with -DCMAKE_EXPORT_COMPILE_COMMANDS=ON flag. You can do it e.g. by modifying the default build profile as
catkin config --profile default --cmake-args -DCMAKE_EXPORT_COMPILE_COMMANDS=ON

Enjoy!

UltiSnips

Completing code snippets is an existential part of programming. Thanks to Ultisnip, pieces of code like if, while and more can be much simpler to write. Ultisnip completes those by hitting <tab> after writing the keyword. Then you can jump through placeholders in the code snippet.

Key mapping for Ultisnip:

  • When suggestions appear, press tab to expand the snippet.
  • While in the snippet, move right and left over the suggested parts by left/right or ctrl-h / ctrl-l.

Snippets can be used in visual mode by wrapping a selected code in e.g. if statement, by:

    1. select a piece of code
    1. hit <tab>, the code will disappear
    1. write a code word for a snipper, e.g. if
    1. hit <tab> again, the code will appear wrapped in new if statement.

Snippets are described in .vim/UltiSnips folder. A snippet file for the currently opened document can be opened by <leader>u.

Other vim stuff ...

The leader key

I have remapped the leader to a comma ",".

Macros

If you, just like me, tend to record everything to @a, following feature might be useful. When in visual line mode, the dot operator applies macro @a over all selected lines.

Other key bindings

  • <leader>a - toggles highlighting of words under the cursor
  • <leader>p - toggles :paste mode
  • <leader>g - automatically indents the whole document while staying on the current line
  • <leader>c - enables cursorline and cursorcolumnt
Clone this wiki locally