Coder Social home page Coder Social logo

vim-goto-header's Introduction

Vim Goto-Header

Vim Goto-Header is a plugin I made to quickly jump to header files with vim/neovim.
It can also be used to jump back and forth between .c/.h or .cpp/.hpp.
It can be use for both c or cpp.

Example :
alt text

Dependencies

Goto-Header uses fd (a find alternative) to look for headers.
To install it on your system see : https://github.com/sharkdp/fd#installation \

Installation

Using Plug

Plug 'Yohannfra/Vim-Goto-Header'

Manual installation

git clone https://github.com/Yohannfra/Vim-Goto-Header/ ~/.vim/plugin/

Configuration

How to open the file

By default the file you open will be in the same tab.
If you want to open the file in a new tab put this in your .vimrc

let g:goto_header_open_in_new_tab = 1

Directories

By default the script will look in these directories (in this order):

  • .
  • /usr/include
  • ..
  • ~

To change the directories or the order add this in your .vimrc

let g:goto_header_includes_dirs = ["DIR1", "DIR2", "DIR3.", "DIR4"]

" example:
let g:goto_header_includes_dirs = [".", "/usr/include", "..", "~"]

Exclude Directories (ONLY IF YOU USE FD)

If you want to exclude directories from the search path.
Put this in your .vimrc

let g:goto_header_excludes_dirs = ["DIR1", "DIR2", "DIR3", "DIR4"]

" example
" It uses the exclude feature of fd, dont put full path , just the directory name.

" Good
let g:goto_header_excludes_dirs = ["Music", "Logiciels", "Pictures", "Downloads"]

" Bad
let g:goto_header_excludes_dirs = ["~/Music", "~/Logiciels", "~/Pictures", "~/Downloads"]

Flags

fd uses -L flag (follow symlink). You can't change it using the following lines, it must stay.

You can customize other fd flags by putting this in your .vimrc

let g:goto_header_fd_command = "-t f -s" " Use any flag you want except -L

Prompt

If you want to print a shorter path in the prompt (usefull if your have a small terminal window)

g:goto_header_use_shorter_path = 1

By default

The default configuration is the following one:

let g:goto_header_includes_dirs = [".", "/usr/include", "..", "~"]
let g:goto_header_search_flags = "-t f -s"
let g:goto_header_excludes_dirs = []
let g:goto_header_open_in_new_tab = 0
let g:goto_header_use_shorter_path = 0

Usage

Put the following lines in your .vimrc to map F12 to search header under the cursor

nnoremap <F12> :GotoHeader <CR>
imap <F12> <Esc>:GotoHeader <CR>

Put the following lines in your .vimrc to map gh to switch between .c/.h or .cpp/.hpp

nnoremap gh :GotoHeaderSwitch <CR>

If you need to switch between a ".cpp" file and a ".h" file (like in #2) add this to your .vimrc

let g:goto_header_associate_cpp_h = 1

Now you'll just need to press F12 on a line like one of those and it will open the corresponding file in a new tab

#include <stdio.h>
#include "my_header.hpp"

If Vim Goto-Header finds more than one header it will show you a little prompt and you'll have to chose which one.

alt text

License

This project is licensed under the terms of the MIT license.

vim-goto-header's People

Contributors

yohannfra avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.