The fuchsia.vim
script sets up Vim to do the following:
:find
and gf
know how to find files./lib/fidl/tools/vim/
).:make
builds and populates the QuickFix window.The steps are:
Add the following line to your startup script (typically ~/.bashrc
):
export FUCHSIA_DIR=<your_fuchsia_source_directory>
This command uses the format fx set [PRODUCT].[BOARD]
. For example:
fx set core.x64
If the following line exists in your ~/.vimrc
file, remove it:
filetype plugin indent on
Then add the following lines to your ~/.vimrc
:
if $FUCHSIA_DIR != "" source $FUCHSIA_DIR/scripts/vim/fuchsia.vim endif filetype plugin indent on
Note: If you haven't installed YouCompleteMe, see this installation guide{:.external} to install YCM on your workstation.
To configure YouCompleteMe (YCM), you need to source the fuchsia.vim
file.
Restart your Vim to run the source $FUCHSIA_DIR/scripts/vim/fuchsia.vim
command in your ~/.vimrc
file (see Update your Vim startup file).
To verify that your YCM works, place the cursor on an identifier in a .cc
or .h
file in Vim, then hit Ctrl+]
to navigate to the definition of the identifier.
YCM uses the compilation database{:.external}, which is more reliable and efficient than the default ycm_extra_config.py
configuration.
To build a compilation database, run the following command:
fx compdb
Google's vim-codefmt can auto-format code on save. This can be installed using a package manager such as Vundle or vim-plug.
A plugin to format and syntax-highlight GN files is available separately. The following example .vimrc
demonstrates how to turn on auto-formatting of GN files using vim-plug and Fuchsia's prebuilt GN:
call plug#begin('~/.vim/plugged') Plug 'google/vim-maktaba' Plug 'google/vim-glaive' Plug 'google/vim-codefmt' Plug 'https://gn.googlesource.com/gn', { 'rtp': 'misc/vim' } call plug#end() call glaive#Install() " Set gn path to the Fuchsia prebuilt. let g:gn_path = systemlist('source ' . g:fuchsia_dir . '/tools/devshell/lib/vars.sh && echo $PREBUILT_GN')[0] execute ':Glaive codefmt gn_executable="' . g:gn_path . '"' augroup autoformat_gn autocmd! autocmd FileType gn AutoFormatBuffer gn augroup END