One to edit all
A large portion of a programmer’s everyday work is to manipulate text and knowing how to do this effortlessly can enhance his/her efficiency at coding. The best way, in my opinion, to be proficient with an editor is to pick one, which ever one you want, and use it every day to edit just anything and in genaral stick with it. Occasionally tweak it a little, try to cut down the number of keystrokes you need to type for a specific task and think about what can be improved in your workflow.
I remember when the senior who was responsible for me, told me at my very first day at work that was ok to spend a couple of days to setup my editor, as all this initial lost time would be amortized in the long run. He was using emacs so I selected Vim, more specifically Neovim, for obvious reasons. 😄
The path to glory
At the beginning was somewhat cumbersome to edit everything with Nvim as our codebase was big and complex but I stuck with my plan and this little everyday habit increased my productivity over time. Till now Nvim is my sole editor and is the first program that I fire up every day. It has been converted into a lightweight IDE as I will describe bellow and I am happy seeing my editing skills progressing alongside with the programming ones. By the way init.vim of this repo is my Nvim configuration.
Traits of a Lighweight Champion
Nvim which is heavily based on Vim is a very powerful editor but in order to be used efficiently in large codebases one has to configure it. I wanted to keep my configuration as simple as possible and also not to be relied upon a myriad of plugins in order to not disrupt the core mechanics of the editor and to be almost equal efficient when confronted with a plain Vim/Nvim in another machine. Also I try to use plugins that are sharpening the saw as drew neil says and which fit the Vim philosophy well. All of them are separated into the below categories:
Eyecandy: I use gruvbox for a nice colorscheme and lightline.vim for a light and configurable statusline/tabline. Nothing special here.
Utilities: vim-trailing-whitespace anotates trailing spaces and creates a new command “:FixWhitespace” for instant cleaning of them and vim-gitgutter which operates like a git diff and shows a quick preview of your changes on the file you are editing. Well, nothing special again, you can live happily without them.
Project-wide search: The plugins of this category are the most important ones. They enhance my workflow and convert Nvim to a lightweigth IDE. These plugins are related to how quickly you can find a specific symbol (function, parameter etc) or getting familiar with large codebases. More specifically, I use tagbar which provides an easy way to browse the tags of the current file and get an overview of its structure (super useful when opening a file for first time!) and vim-vinegar. Split windows and the project drawer go together like oil and vinegar (an eye opener article for my workflow). So instead of using project drawer plugins like the famous NerdTree I prefer using a less well-known built in file explorer for Nvim called netrw vinegar just enhances the built in file explorer. That way I can be productive also in stock Vim/Nvim.
Also for project-wide searching I use two external tools, ctags and cscope. Ctags is used for jumping from function calls to their definitions while cscope tool adds the ability to jump to any of the places where a function is called. Usually I run the cscope_gen.sh script (see below the shell commands) to create a file which contains the filenames of all the files of the project that I am working on. This file is later fed on cscope and ctags to create the cscope database and tags file respectively.
find /path/to/source/code/root/directory -path /path/to/folder/for/exclusion -prune -o -print | egrep -i "\.(c|h|cpp|hpp)$" > cscope.files
cscope -b -q
ctags -L cscope.files
This way I am only a g] or CTRL-] keystrokes away from jumping to the place where that method is defined or implemented and with the command “:cs find e “C symbol”” I can find the C symbol everywhere in the project. Both of them are extremely fast because they work on prebuilt indexes to search for the required C symbol. Of course sometimes I use the very well known and beloved tool grep.
Dead simple right? This is of course under constant work in progress and I recommend everyone to check drew neil’s vimcasts as they contain a lot of high quality information. Last but not least, this is how my configured Nvim currenlty looks like!
If you want to know more about my setup, or want to share yours please leave a comment below.