From 9442b1202c6d85309aa23d7f6b63c458e733a328 Mon Sep 17 00:00:00 2001 From: zevav Date: Tue, 30 Jul 2019 16:55:20 +0200 Subject: [PATCH] added a blog post --- blog/index.html | 127 ++++++++++++++++++++++++++ blog/vim_and_ctags.html | 197 ++++++++++++++++++++++++++++++++++++++++ index.html | 5 + projects.html | 5 + 4 files changed, 334 insertions(+) create mode 100644 blog/index.html create mode 100644 blog/vim_and_ctags.html 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 @@ + + + + Zev Averbach + + + + + + + + + + + +
+ + + + +
+ Full Stack Developer +
+ + + +
+
+ + +
Blog Posts
+ + + + +
+ + \ No newline at end of file diff --git a/blog/vim_and_ctags.html b/blog/vim_and_ctags.html new file mode 100644 index 0000000..5fc45fd --- /dev/null +++ b/blog/vim_and_ctags.html @@ -0,0 +1,197 @@ + + + + Zev Averbach + + + + + + + + + + + +
+ + + + +
+ Full Stack Developer +
+ + + +
+
+ << back to blog index + + +
How I Got "Go To Definition" Working in Vim in 2019
+ +

+ +

+👇👇👇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. +

+ +
What I Miss From IDEs
+ +

+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. +

+ +
Getting It To Work + Timesucks to Avoid
+ +

+ 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. +

+ +
Final Product + User Experience
+ +

+ 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. +

+ +
Bonus: 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! +

+ + +
+ + \ No newline at end of file diff --git a/index.html b/index.html index 3a93e40..548f375 100644 --- a/index.html +++ b/index.html @@ -64,6 +64,11 @@ + Blog + + + + Blog + + + +