YCM(YouCompleteMe)常用命令大全

一、Ycm Commands

1、YcmRestartServer command

If the ycmd completion server suddenly stops for some reason, you can restart it with this command.

2、YcmForceCompileAndDiagnostics command

Calling this command will force YCM to immediately recompile your file and display any new diagnostics it encounters. Do note that recompilation with this command may take a while and during this time the Vim GUI will be blocked.

You may want to map this command to a key; try putting nnoremap <F5> :YcmForceCompileAndDiagnostics<CR> in your vimrc.

3、YcmDiags command

Calling this command will fill Vim's locationlist with errors or warnings if any were detected in your file and then open it. If a given error or warning can be fixed by a call to :YcmCompleter FixIt, then (FixIt available) is appended to the error or warning text. See the FixIt completer subcommand for more information.

NOTE: The absence of (FixIt available) does not strictly imply a fix-it is not available as not all completers are able to provide this indication. For example, the c-sharp completer provides many fix-its but does not add this additional indication.

The g:ycm_open_loclist_on_ycm_diags option can be used to prevent the location list from opening, but still have it filled with new diagnostic data. See the Options section for details.

4、YcmShowDetailedDiagnostic command

This command shows the full diagnostic text when the user's cursor is on the line with the diagnostic.

5、YcmDebugInfo command

This will print out various debug information for the current file. Useful to see what compile commands will be used for the file if you're using the semantic completion engine.

6、YcmToggleLogs command

This command presents the list of logfiles created by YCM, the ycmd server, and the semantic engine server for the current filetype, if any. One of these logfiles can be opened in the editor (or closed if already open) by entering the corresponding number or by clicking on it with the mouse. Additionally, this command can take the logfile names as arguments. Use the <TAB> key (or any other key defined by the wildchar option) to complete the arguments or to cycle through them (depending on the value of the wildmode option). Each logfile given as an argument is directly opened (or closed if already open) in the editor. Only for debugging purposes.

7、YcmCompleter command

This command gives access to a number of additional IDE-like features in YCM, for things like semantic GoTo, type information, FixIt and refactoring.

This command accepts a range that can either be specified through a selection in one of Vim's visual modes (see :h visual-use) or on the command line. For instance, :2,5YcmCompleter will apply the command from line 2 to line 5. This is useful for the Format subcommand.

Call YcmCompleter without further arguments for a list of the commands you can call for the current completer.

See the file type feature summary for an overview of the features available for each file type. See the YcmCompleter subcommands section for more information on the available subcommands and their usage.

二、YcmCompleter Subcommands

NOTE: See the docs for the YcmCompleter command before tackling this section.

The invoked subcommand is automatically routed to the currently active semantic completer, so :YcmCompleter GoToDefinition will invoke the GoToDefinition subcommand on the Python semantic completer if the currently active file is a Python one and on the Clang completer if the currently active file is a C-family language one.

You may also want to map the subcommands to something less verbose; for instance, nnoremap <leader>jd :YcmCompleter GoTo<CR> maps the <leader>jd sequence to the longer subcommand invocation.

1、GoTo Commands

These commands are useful for jumping around and exploring code. When moving the cursor, the subcommands add entries to Vim's jumplist so you can use CTRL-O to jump back to where you were before invoking the command (and CTRL-I to jump forward; see :h jumplist for details). If there is more than one destination, the quickfix list (see :h quickfix) is populated with the available locations and opened to full width at the bottom of the screen. You can change this behavior by using the YcmQuickFixOpened autocommand.

1.1、 GoToInclude subcommand

Looks up the current line for a header and jumps to it.

Supported in filetypes: c, cpp, objc, objcpp, cuda

1.2、GoToDeclaration subcommand

Looks up the symbol under the cursor and jumps to its declaration.

Supported in filetypes: c, cpp, objc, objcpp, cuda, cs, go, java, javascript, python, rust, typescript

1.3、GoToDefinition subcommand

Looks up the symbol under the cursor and jumps to its definition.

NOTE: For C-family languages this only works in certain situations, namely when the definition of the symbol is in the current translation unit. A translation unit consists of the file you are editing and all the files you are including with #include directives (directly or indirectly) in that file.

Supported in filetypes: c, cpp, objc, objcpp, cuda, cs, go, java, javascript, python, rust, typescript

1.4、 GoTo subcommand

This command tries to perform the "most sensible" GoTo operation it can. Currently, this means that it tries to look up the symbol under the cursor and jumps to its definition if possible; if the definition is not accessible from the current translation unit, jumps to the symbol's declaration. For C-family languages, it first tries to look up the current line for a header and jump to it. For C#, implementations are also considered and preferred.

Supported in filetypes: c, cpp, objc, objcpp, cuda, cs, go, java, javascript, python, rust, typescript

1.5、 GoToImprecise subcommand

WARNING: This command trades correctness for speed!

Same as the GoTo command except that it doesn't recompile the file with libclang before looking up nodes in the AST. This can be very useful when you're editing files that take long to compile but you know that you haven't made any changes since the last parse that would lead to incorrect jumps. When you're just browsing around your codebase, this command can spare you quite a bit of latency.

Supported in filetypes: c, cpp, objc, objcpp, cuda

1.6、 GoToSymbol <symbol query> subcommand

Finds the definition of all symbols matching a specified string. Note that this does not use any sort of smart/fuzzy matching.

Supported in filetypes: c, cpp, objc, objcpp, cuda, cs, java, javascript, python, typescript

1.7、 GoToReferences subcommand

This command attempts to find all of the references within the project to the identifier under the cursor and populates the quickfix list with those locations.

Supported in filetypes: c, cpp, objc, objcpp, cuda, java, javascript, python, typescript, rust

1.8、GoToImplementation subcommand

Looks up the symbol under the cursor and jumps to its implementation (i.e. non-interface). If there are multiple implementations, instead provides a list of implementations to choose from.

Supported in filetypes: cs, go, java, rust, typescript, javascript

1.9、 GoToImplementationElseDeclaration subcommand

Looks up the symbol under the cursor and jumps to its implementation if one, else jump to its declaration. If there are multiple implementations, instead provides a list of implementations to choose from.

Supported in filetypes: cs

1.10、 GoToType subcommand

Looks up the symbol under the cursor and jumps to the definition of its type e.g. if the symbol is an object, go to the definition of its class.

Supported in filetypes: go, java, javascript, typescript

2、Semantic Information Commands

These commands are useful for finding static information about the code, such as the types of variables, viewing declarations and documentation strings.

2.1、 GetType subcommand

Echos the type of the variable or method under the cursor, and where it differs, the derived type.

For example:

    std::string s;

Invoking this command on s returns std::string => std::basic_string<char>

NOTE: Causes re-parsing of the current translation unit.

Supported in filetypes: c, cpp, objc, objcpp, cuda, java, javascript, go, python, typescript, rust

2.2、 GetTypeImprecise subcommand

WARNING: This command trades correctness for speed!

Same as the GetType command except that it doesn't recompile the file with libclang before looking up nodes in the AST. This can be very useful when you're editing files that take long to compile but you know that you haven't made any changes since the last parse that would lead to incorrect type. When you're just browsing around your codebase, this command can spare you quite a bit of latency.

Supported in filetypes: c, cpp, objc, objcpp, cuda

2.3、 GetParent subcommand

Echos the semantic parent of the point under the cursor.

The semantic parent is the item that semantically contains the given position.

For example:

class C {
    void f();
};

void C::f() {

}

In the out-of-line definition of C::f, the semantic parent is the class C, of which this function is a member.

In the example above, both declarations of C::f have C as their semantic context, while the lexical context of the first C::f is C and the lexical context of the second C::f is the translation unit.

For global declarations, the semantic parent is the translation unit.

NOTE: Causes re-parsing of the current translation unit.

Supported in filetypes: c, cpp, objc, objcpp, cuda

2.4、 GetDoc subcommand

Displays the preview window populated with quick info about the identifier under the cursor. Depending on the file type, this includes things like:

  • The type or declaration of identifier,
  • Doxygen/javadoc comments,
  • Python docstrings,
  • etc.

Supported in filetypes: c, cpp, objc, objcpp, cuda, cs, go, java, javascript, python, typescript, rust

The GetDocImprecise subcommand

WARNING: This command trades correctness for speed!

Same as the GetDoc command except that it doesn't recompile the file with libclang before looking up nodes in the AST. This can be very useful when you're editing files that take long to compile but you know that you haven't made any changes since the last parse that would lead to incorrect docs. When you're just browsing around your codebase, this command can spare you quite a bit of latency.

Supported in filetypes: c, cpp, objc, objcpp, cuda

3、Refactoring Commands

These commands make changes to your source code in order to perform refactoring or code correction. YouCompleteMe does not perform any action which cannot be undone, and never saves or writes files to the disk.

3.1、 FixIt subcommand

Where available, attempts to make changes to the buffer to correct diagnostics on the current line. Where multiple suggestions are available (such as when there are multiple ways to resolve a given warning, or where multiple diagnostics are reported for the current line), the options are presented and one can be selected.

Completers which provide diagnostics may also provide trivial modifications to the source in order to correct the diagnostic. Examples include syntax errors such as missing trailing semi-colons, spurious characters, or other errors which the semantic engine can deterministically suggest corrections.

If no fix-it is available for the current line, or there is no diagnostic on the current line, this command has no effect on the current buffer. If any modifications are made, the number of changes made to the buffer is echo'd and the user may use the editor's undo command to revert.

When a diagnostic is available, and g:ycm_echo_current_diagnostic is set to 1, then the text (FixIt) is appended to the echo'd diagnostic when the completer is able to add this indication. The text (FixIt available) is also appended to the diagnostic text in the output of the :YcmDiags command for any diagnostics with available fix-its (where the completer can provide this indication).

NOTE: Causes re-parsing of the current translation unit.

Supported in filetypes: c, cpp, objc, objcpp, cuda, cs, go, java, javascript, rust, typescript

3.2、 RefactorRename <new name> subcommand

In supported file types, this command attempts to perform a semantic rename of the identifier under the cursor. This includes renaming declarations, definitions and usages of the identifier, or any other language-appropriate action. The specific behavior is defined by the semantic engine in use.

Similar to FixIt, this command applies automatic modifications to your source files. Rename operations may involve changes to multiple files, which may or may not be open in Vim buffers at the time. YouCompleteMe handles all of this for you. The behavior is described in the following section.

Supported in filetypes: c, cpp, objc, objcpp, cuda, java, javascript, typescript, rust, cs

Multi-file Refactor

When a Refactor or FixIt command touches multiple files, YouCompleteMe attempts to apply those modifications to any existing open, visible buffer in the current tab. If no such buffer can be found, YouCompleteMe opens the file in a new small horizontal split at the top of the current window, applies the change, and then hides the window. NOTE: The buffer remains open, and must be manually saved. A confirmation dialog is opened prior to doing this to remind you that this is about to happen.

Once the modifications have been made, the quickfix list (see :help quickfix) is populated with the locations of all modifications. This can be used to review all automatic changes made by using :copen. Typically, use the CTRL-W <enter> combination to open the selected file in a new split. It is possible to customize how the quickfix window is opened by using the YcmQuickFixOpened autocommand.

The buffers are not saved automatically. That is, you must save the modified buffers manually after reviewing the changes from the quickfix list. Changes can be undone using Vim's powerful undo features (see :help undo). Note that Vim's undo is per-buffer, so to undo all changes, the undo commands must be applied in each modified buffer separately.

NOTE: While applying modifications, Vim may find files which are already open and have a swap file. The command is aborted if you select Abort or Quit in any such prompts. This leaves the Refactor operation partially complete and must be manually corrected using Vim's undo features. The quickfix list is not populated in this case. Inspect :buffersor equivalent (see :help buffers) to see the buffers that were opened by the command.

3.3、 Format subcommand

This command formats the whole buffer or some part of it according to the value of the Vim options shiftwidth and expandtab (see :h 'sw' and :h et respectively). To format a specific part of your document, you can either select it in one of Vim's visual modes (see :h visual-use) and run the command or directly enter the range on the command line, e.g. :2,5YcmCompleter Format to format it from line 2 to line 5.

Supported in filetypes: c, cpp, objc, objcpp, cuda, java, javascript, go, typescript, rust, cs

3.4、OrganizeImports subcommand

This command removes unused imports and sorts imports in the current file. It can also group imports from the same module in TypeScript and resolves imports in Java.

Supported in filetypes: java, javascript, typescript   #很不幸,不支持C/C++、python、golang

4、Miscellaneous Commands

These commands are for general administration, rather than IDE-like features. They cover things like the semantic engine server instance and compilation flags.

4.1、 ExecuteCommand <args> subcommand

Some LSP completers (currently Rust and Java completers) support executing server specific commands. Consult the rlsand jdt.ls respective documentations to find out what commands are supported and which arguments are expected.

The support for ExecuteCommand was implemented to support plugins like vimspector to debug java, but isn't limited to that specific use case.

4.2、 RestartServer subcommand

Restarts the semantic-engine-as-localhost-server for those semantic engines that work as separate servers that YCM talks to.

Supported in filetypes: c, cpp, objc, objcpp, cuda, cs, go, java, javascript, rust, typescript

4.3、 ReloadSolution subcommand

Instruct the Omnisharp-Roslyn server to clear its cache and reload all files from disk. This is useful when files are added, removed, or renamed in the solution, files are changed outside of Vim, or whenever Omnisharp-Roslyn cache is out-of-sync.

Supported in filetypes: cs

猜你喜欢

转载自blog.csdn.net/lianshaohua/article/details/108365868