vim/README.md

5.2 KiB

Vim Configuration

Plugins

YouCompleteMe

The plugin is cloned to ~/.vim/pack/minpac/opt/YouCompleteMe recursively using minpac. Making the plugin optional can be useful when completion is not desired and for fast Vim loading times, when completion is desired it can be loaded with Vim command:

$ :packadd YouCompleteMe

Post clone the compiled C++ components must be built before completion can be used, run the following command from the root of the YouCompleteMe repository:

$ ./install --clang-completer

This uses the older libclang.so based completer despite YouCompleteMe recommending the use of clangd due to working on projects which predate the newer completer and the migration overhead of switching to it. To completely disable the clangd completer this must also be present in ~/.vim/vimrc:

let g:ycm_use_clangd = 0

The following two options are for customising bindings for cycling through the completion menu when multiple completions are available.

let g:ycm_key_list_select_completion = ['<C-n>', '<Down>']
let g:ycm_key_list_previous_completion = ['<C-p>', '<Up>']

The next options enable populating the list of potential completions beyond those suggested by the semantic language completer.

let g:ycm_collect_identifiers_from_comments_and_strings = 1
let g:ycm_seed_identifiers_with_syntax = 1

These options enable completions inside comments and strings.

let g:ycm_complete_in_comments = 1
let g:ycm_complete_in_strings = 1

Trigger the completion menu after entering a single character.

let g:ycm_min_num_of_chars_for_completion = 1

Populating the location list with warnings and errors in the current buffer is very useful for jumping to those source locations, especially when using [mappings][location-list-mappings].

let g:ycm_always_populate_location_list = 1

When a completion is selected the signature, and help comments if there is any available, are displayed in a separate buffer. This option enables automatically closing that buffer.

let g:ycm_autoclose_preview_window_after_insertion = 1

Control how a split is created when using the :YcmCompleter Goto command.

let g:ycm_goto_buffer_command = 'horizontal-split'

Warnings and errors are displayed in the Vim gutter, to the left of line numbers, these override the default characters used to display them.

let g:ycm_error_symbol = '▸'
let g:ycm_warning_symbol = '▸'

Mappings

YouCompleteMe Mappings

Apply the compilers suggestion to fix a warning or error.

nnoremap <leader>fi :YcmCompleter FixIt<CR>

Go to the declaration of the symbol under the cursor.

nnoremap <leader>gd :YcmCompleter GoTo<CR>

Get the type of the symbol under the cursor.

nnoremap <leader>gt :YcmCompleter GetType<CR>

Display the full compiler diagnostic output for the warning or error on the line under the cursor.

nnoremap <leader>sd :YcmShowDetailedDiagnostic<CR>

Location List Mappings

Open the location list buffer.

nnoremap <leader>lo :lopen<CR>

Close the location list buffer.

nnoremap <leader>lc :lclose<CR>

Jump to the current location in the location list.

nnoremap <leader>ll :ll<CR>

Jump to the next location in the location list.

nnoremap <leader>ln :lnext<CR>

Jump to the previous location in the location list.

nnoremap <leader>lp :lprevious<CR>

Jump to the first location in the location list.

nnoremap <leader>lf :lfirst<CR>

Jump to the last location in the location list.

nnoremap <leader>la :llast<CR>