-
+
+
+
+
- How I Got "Go To Definition" Working in Vim in 2019 + + + +
diff --git a/blog/index.html b/blog/index.html new file mode 100644 index 0000000..0417499 --- /dev/null +++ b/blog/index.html @@ -0,0 +1,127 @@ + + +
+
+
+
+
+👇👇👇tl;dr
+
+# .vimrc
+set tags=tags
+autocmd BufWritePost *.py silent! !ctags -R --python-kinds=-i --languages=python 2> /dev/null &
+
+$ brew install ctags
+
+
+
+ In the last two years I've spent a significant amount of time in PyCharm and a somewhat shorter + time with Visual Studio Code, both with vim keyboard bindings, writing mostly Python and JS. Ultimately, I came back to some + flavor of terminal-based vim: First Vim 8, now Neovim. There were too many missing features in + "vim mode" in both of the IDEs, and the speed difference—brain-to-screen—was noticeable + compared to vim. +
+ +
+Because I'm not yet a sed/grep expert in the context of search and replace, I still miss the
+ refactoring tools in PyCharm for renaming and reorganizing code. Automatic imports is also
+ something I haven't replicated in vim.
+
+ However, what I was missing most was "go to definition", which I had mapped in VSC and PyCharm to
+ C-] as it is by default in vim.
+
+ As with most of my efforts to make vim more ergonomic/IDE-like, getting "go to definition" working took + longer than I had hoped. + The low-hanging options didn't work as advertised: I tried to set up git hooks like Mr. + Pope suggested, +but for whatever reason the tags file never refreshed on commit. Avoid this timesuck! And + anyway, don't you want "go to definition" to work between commits too? +
+ ++ What ended up working to refresh the tags file *on every save* was a modified version of something I found in the comments of a StackOverflow answer. + I was only interested to start out with in tagging my Python projects, so I + modified it accordingly. +
+
+ Then, interestingly, without python-kinds=-i "go to definition"
+ didn't work as expected on MacOS (it was fine on an Ubuntu droplet). Inspecting my
+ tags file,
+ it was including imports, which caused by C-] invocations to only jump to the top of the current
+ module, where the import was, not to the definition of the function/module/constant/class.
+
+ What's nice about this usage of ctags is 1) it runs in the background and never
+ interrupts you, 2) it's fast, and 3) it runs every time you save.
+ I haven't tried this at all with JS yet, and Mr. Pope alludes to that ctags might not be as
+ helpful there, but it is lightning fast and accurate for jumping around in large Python-based
+ projects.
+
gf
+gf bridges a significant gap that ctags don't cover:
+It stands for "go to file". Type gf when your cursor over a filename, and it opens it!
+