Vim users, please share any vim tips you have below in the replies! - thanks Jeremy
Hi, this thread will help setup the vim with tags(creation) for fast lookups of functions and classes. I felt the need for this thread because in the past i had tried setting up this tags thing, but was overwhelmed by the plugins available and in the end always messed up with my system.
However this time i managed to setup this tags thing without any plugin. So just wanted to share for those who might be stuck.
Here are the steps from scratch(for linux):
- sudo apt install vim
- sudo apt install exuberant-ctags
Setup Vundle (Optional)
- Go to vundle and follow the steps. It’s pretty straight-forward.
- Here please remember to comment out (using " ) the packages you don’t need.(especially the YouCompleteMe package(takes a lot of time))
- Simply put
Plugin 'tmhedberg/SimpylFold'after the
call vundle#begin()line to enable automatic
code folding just as in jeremy’s terminal.
- open vim using
Creating tags for projects (Important)
This is the step that will do the magic.
So suppose you want to create tags for
fastai library so that you can check for any function,class defined in the library.
For that you need to first locate where the library is installed.Simple step for that would be
this will show all the paths matching fastai word.Something like this
Now just get the base path where the fastai lib is installed. In my case, it would be
Now to generate the tags, simply write
ctags -R -o ~/fasttags /home/shang/.conda/envs/pyfast/lib/python3.7/site-packages/fastai/
This will generate a tags file and will store it at home directory named as
fasttags. Here remember to provide the full path for both the output file and input file otherwise vim won’t be able to find the tags(happened with me).
To keep things in order and tidy, you can create a directory at home as
.tags and move this fasttags file over there.
All done! Now simply open up your
.vimrc file using
vi ~/.vimrc and add the following line at the end -
This line will tell the vim where the tags file is located.
Now just fire up the vim and search for any definition of functions/class you want to search from fastai lib like DataBunch.
Here are the results of
you can provide multiple no. of tags file to vim using
set tags=/path/to/file1,/path/to/file2 etc.
But here if you are maintaining different tag files for different libs supposed you have one for pytorch, one for working fastai, one for development mode fastai, one for the part-2 course,
then this like will be a bit messy. The workaround would be to structure the different tag file in different folders like this
Just make sure the file name inside the folders is same.
Now change the tags line in the .vimrc file like this -
and this will load all the different tag files you want.
I know the whole above setup is pretty straight forward, but still i wanted to share incase somebody got stuck like me.