[coc.nvim]: UnhandledRejection: Launching server “jedi” using command jedi-language-server failed.

Recently I switched over to coc.nvim, and when trying to edit a Python file, I encountered the following error:

[coc.nvim]: UnhandledRejection: Launching server "jedi" using command jedi-language-server failed.

The first problem turned out to be that while I had jedi installed, I hadn’t installed jedi-language-server. This can be done using:

pip install --user jedi-language-server

Next, coc.nvim couldn’t find the jedi-language-server executable, even though it was on my $PATH. The solution was to specifically define it in ~/.vim/coc-settings.json:

{
  "jedi.executable.command": "/home/guyru/.local/bin/jedi-language-server",
}

View man Pages Properly in gVim

Vim’s ability to display man pages easily using the K mapping often comes in handy. It has been bothering me for a while that the same thing doesn’t work properly in gVim, which I use more. The reason is that Vim’s ability to display man pages depends on having a terminal emulator, which just isn’t true for gVim, hence the garbled display of man pages one sees if one tries viewing a man page in gVim.

Today, I found a way around this limitation. It turns out Vim comes with support for displaying man pages in a split window, and it does it perfectly – colors, links, and all the necessary stuff. The first line enables this feature, which includes by default the K mapping to open the man page in a new split. The second part, which I find very convenient, makes the regular K do the same in gVim. And unlike the original mapping, it also accepts a count before it, so pressing 3K will search section 3 of the man pages for the keyword under the cursor.

" Properly display man pages
" ==========================
runtime ftplugin/man.vim
if has("gui_running")
	nnoremap K :<C-U>exe "Man" v:count "<C-R><C-W>"<CR>
endif

Quickly Exiting Insert Mode in Vim

Changing from insert mode to normal mode is usually quick. The other direction is more cumbersome. You either have to reach for the Escape key or use Ctrl-[ (which I never got used to).

After seeing a blog post suggesting mapping jk to exit insert mode, I was inspired to create my own mapping. I chose kj because it’s faster to type, as typing inward is faster than outward (you can check for yourself by tapping your fingers on your desk). To use it, add the following to your .vimrc:

:inoremap kj <ESC>

Now, whenever you are in insert mode, quickly typing kj will exit insert mode. It will introduce a short pause after typing k, but this is only a visual one, so it doesn’t actually slow you down. kj is one of the rarest bigrams in English, so you’ll almost never have to actually type it inside a text, but if you do, just wait a bit after typing k before typing the j.

After writing this post, I came across a Vim Wiki page listing all kinds of ways to avoid the Escape key.

I’ve recently published my vimrc; take a look – it might give you ideas for other neat tricks.

Vim: Creating .clang_complete using CMake

The clang_complete plugin for Vim offers superior code completion. If your project is anything but trivial, it will only do so if you provide a .clang_complete file with the right compilation arguments. The easy way to do so is by using the cc_args.py script that comes with it to record the options directly into the .clang_complete file. Usually, one does

make CXX='~/.vim/bin/cc_args.py clang++'

However, the makefile generated by CMake doesn’t support the CXX configuration.

The solution is to call CMake with the CXX environment variable set:

CXX="$HOME/.vim/bin/cc_args.py clang++" cmake ..
make

Note that this will create the .clang_complete file in the build directory (I’ve assumed an out-of-place build), so just copy the file over to Vim’s working directory so it can find it. You’ll need to re-run CMake again (without CXX) to disable re-creating the .clang_complete file each time.

While looking for this solution, I first tried solving it by setting the CMAKE_CXX_COMPILER variable in CMake. However, for some strange reason, it didn’t like it, saying that the compiler wasn’t found (it shuns command-line arguments given in the compiler command).

The more I use clang_complete, the more awesome I find it. It has its quirks, but nonetheless it’s much simpler and better than manually creating tag files for each library.

Updated 6/1/2014: When setting CXX, use $HOME instead of ~ (to fix issues with newer versions of CMake).

Bye Bye OmniCppComplete, Hello Clang Complete

For years OmniCppComplete has been the de facto standard for C++ completion in Vim. But as time progressed, I got more and more annoyed by its shortcomings. OmniCppComplete is based on tokenizing provided by ctags. The ctags parsing of C++ code is problematic; you can’t even run it on libstdc++ headers (you need to download modified headers). You want to use an external library? You’ll need to run ctags separately on each library. Not to mention its inability to deduce types of anything more than trivial code. The core of the problem is that OmniCppComplete isn’t a compiler, and you can’t expect something that isn’t a compiler to fully understand code. This is what makes Visual Studio’s IntelliSense so great: it uses the Visual C++ compiler for parsing. It isn’t making wild guesses at types or what the current scope is – it knows it.
Continue reading Bye Bye OmniCppComplete, Hello Clang Complete

Vim Syntax Highlighting for Google Gadgets

I started developing Google Gadgets for LabPixies, so one of the first things I looked for was syntax highlighting. Vim recognized the gadgets’ code as an XML file (which is correct), but I also wanted HTML syntax highlighting for the HTML part. So, after searching a bit for an existing solution, I found one, but I didn’t like it, as it required me to wrap the HTML code with a specific comment. As I don’t like this kind of solution, I’ve decided to create my own syntax highlighting file for Vim.
Continue reading Vim Syntax Highlighting for Google Gadgets

Setting Up OmniComplete (Autocompletion) for wxWidgets in Vim

I use Vim as my main IDE for C/C++-related development (as well as for almost all other development). If you use (or are thinking about using) Vim as an IDE, you better get some good autocompletion functionality. This kind of autocompletion is provided by OmniComplete, which has been available since Vim 7.0. Just having OmniComplete is a nice thing, but it’s much more helpful if it’s configured properly to work with the libraries you use, such as wxWidgets. In this post, I will show you how to get OmniComplete working for wxWidgets. However, the procedure I will show can be easily adapted to almost all libraries.
Continue reading Setting Up OmniComplete (Autocompletion) for wxWidgets in Vim

Vim Macros for Wrapping Strings for Gettext

I’m working on a website, and we decided to localize it using GNU gettext. Soon enough, I found it tiring to wrap each string manually in _( and ), and also to do it in Smarty (using {t}string{/t}). So I decided that I needed a macro that would let me highlight the string that needs translation, and the macro would wrap it for me.

I ended up writing two macros: one for PHP files (but it’s also good for C/C++, etc.) and one for Smarty.

:vmap tg di_(<ESC>pa)<ESC>
:vmap ts di{t}<ESC>pa{/t}<ESC>

To use these macros, just highlight the string for translation in Vim’s visual mode and press tg (or ts), and your string will be wrapped for translation.