/vim-gf-improved

Primary LanguageVim ScriptMIT LicenseMIT

vim-gf-improved

Enhanced gf command for Vim with line:column support and multi-line path detection.

Features

  • Line and column support - Jump to file:line:column format (Vim's built-in gf only supports file:line)
  • Vertical split support - Smart vsplit handling via g:gf_improved_vertical or automatic detection from diffopt
  • Multi-line path detection - Handles file paths split across multiple lines (especially useful for terminal buffer output)
  • Works with all standard gf variations (gf, gF, <C-w>f, <C-w>F, <C-w>gf, <C-w>gF)

Installation

Using vim-plug

Plug 'lambdalisue/vim-gf-improved'

Using dein.vim

call dein#add('lambdalisue/vim-gf-improved')

Using packer.nvim

use 'lambdalisue/vim-gf-improved'

Usage

The plugin automatically maps the standard gf commands to the improved versions:

  • gf - Open file under cursor
  • gF - Same as gf but with line/column support
  • <C-w>f - Open file in split
  • <C-w>F - Open file in split with line/column support
  • <C-w>gf - Open file in new tab
  • <C-w>gF - Open file in new tab with line/column support

Examples

Line and column support

Place your cursor on any of these formats and press gF:

  • path/to/file.txt - Opens file
  • path/to/file.txt:42 - Opens file at line 42
  • path/to/file.txt:42:10 - Opens file at line 42, column 10

Multi-line path support

The plugin can detect paths that span multiple lines, useful for terminal output:

Error in /path/to/very/long/
filename/that/spans/multiple/lines.txt:10:5

Place your cursor on the first line of the path (/path/to/very/long/) and press gf - the plugin will search subsequent lines to complete the path.

Configuration

Disable default mappings

If you want to define your own mappings:

let g:gf_improved_no_mappings = 1

" Define your own mappings
nmap <Leader>gf <Plug>(gf-improved-gf)
nmap <Leader>gF <Plug>(gf-improved-gF)

Vertical splits

Control whether <C-w>f and <C-w>F open vertical or horizontal splits:

" Use vertical splits (default: follows 'diffopt' setting)
let g:gf_improved_vertical = 1

" Use horizontal splits
let g:gf_improved_vertical = 0

License

The code in this repository follows MIT license texted in LICENSE. Contributors need to agree that any modifications sent in this repository follow the license.