Skip to main content

Vim goto definition

For navigation in large code bases. Mostly these have been tried with C/C++, but works similarly for other languages - Go, PHP, Elixir with some customization.
OS used - Ubuntu

Goto definition
Install ctags -> sudo apt-get install exuberant-ctags 
Activate ctags from project root -> ctags -R 
Open all source files from this project root in Vim
To goto function/variable definition under cursor -> Ctrl + ]  
To jump back ->  Ctrl + t  

Goto local variable/global variable declaration
If tag not found for some global variable/local variable/static/function
For definition and search(keyword under cursor) in same file(highlighter works with some good vim plugins) -> gd 
For global definitions -> gD 
To jump back -> Ctrl + o 

Goto header files
To go-to file ->   gf  
To jump back -> Ctrl + o 

This article will get updated more. The main aim is to keep it minimal.

Comments

Popular posts from this blog

error: invalid application of ‘sizeof’ to incomplete type ‘struct ’

list.c:47:39: error: invalid application of ‘sizeof’ to incomplete type ‘struct Litsnode’ So, I was trying to run a program based on linked list and this is what I got. This is a very silly problem. I am mentioning it here just to help those who got frustrated like me :-\ Let me show you the line where this error occurred : 46   struct Listnode * newnode; 47   newnode = (struct Listnode *) malloc(sizeof(struct Litsnode)); Now, View it properly. Check the name(spelling) of the structure mentioned to sizeof : " struct Li ts node ". Though the defined name of the structure was : " struct Listnode " That's it.  This happens all the time that we may type something wrong. The important thing is to identify it. :-) Feel free to give any suggestions :)

Expandable Arrays in C : behind the code

Arrays. They are beautiful. In C, we always try to work through restrictions arrays have i.e the size of the array must be statically defined. We always want a dynamic array whose size can be decided at run-time. There are ways which we use widely for e.g by using pointers and then dynamically allocating memory to it using malloc or calloc. But depending on the situation, we might require more efficient and organizable ways. I will explain the concept with a series of examples as in how simple arrays evolved to the tricky expandable ones. The classic way is to use pointers This snippet will allocate a memory block of size = array_size(integer array). Though this is not what I wanted to explain because this way is too clumsy. Imagine if you need 10 dynamic arrays in your program, you have to write these four lines each time and you have to keep track of all the 10 sizes. A better way is to use structures: We can simply create a structure containing two elements: array_size and...

error: stray '\' in program

 stray.c:6: error: stray '\315' in program   stray.c:7: error: stray '\242' in program   stray.c:8: error: stray '\234' in program  If you are getting error messages like above in your C/C++ program, then don't worry. ;-) Perhaps you have copied the code from somewhere. If your code is small ,then the simplest solution is that you should start typing it from zero. That is , delete all the code ( the lines you know you have copied) and re-type it. If your code is lengthy and you do not want to type it, then you should use this software : Hex Editor Wiki You may be wondering that why this problem even occurred. The reason for this is that your code might contain some hidden octal (not-readable) characters which the compiler cant understand and you can not see. They are present in your code because you have perhaps copied it from somewhere. So, simply you can retype the same code to solve the problem. ----- Happy Coding :-)