Skip to content

Commit

Permalink
Follow file paths without extension
Browse files Browse the repository at this point in the history
When a file path under the cursor does not have an extension (which is
quite common in `import` statements in JavaScript projects), Vim will
now try to append it so the `gf` command can function properly.

This has only been applied to JavaScript and TypeScript files (including
their JSX flavours).
  • Loading branch information
Chris Kobrzak committed Oct 17, 2020
1 parent a08e43f commit 481d656
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .vimrc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ let g:prettier#config#bracket_spacing = 'true'
let g:prettier#config#arrow_parens = 'avoid'
let g:prettier#config#trailing_comma = 'none'

au BufNewFile,BufRead *.jsx set filetype=javascript
au BufNewFile,BufRead *.tsx set filetype=typescript
au BufNewFile,BufRead *.ejs,*.hbs set filetype=html
au BufNewFile,BufRead *.js.ejs set filetype=javascript
au BufNewFile,BufRead *.json.ejs set filetype=json
Expand Down Expand Up @@ -96,6 +98,21 @@ nnoremap <C-l> :call LineNumberToggle()<CR>
:au FocusGained * :set relativenumber
" End: line number management

" Follow file paths without extensions
augroup suffixes
autocmd!

let fileTypeToExtensions = {
\'javascript': '.js,.jsx,.json',
\'typescript': '.ts,.tsx'
\}

for [fileType, extensions] in items(fileTypeToExtensions)
execute 'autocmd FileType ' . fileType . ' setlocal suffixesadd=' . extensions
unlet fileType extensions
endfor
augroup END

" Display buffer list in the alphabetical order
command! -bang Ls redir @" | silent ls<bang> | redir END | echo " " |
\ perl {
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ cursors)

**Ctrl-l** - toggle line numbers (including relative to the current line)

**gf** - follow local `import` paths even if they don't have e.g. the `.js` extension

**:Ls** - show file buffer list ordered alphabetically

# Working with plugins
Expand Down

0 comments on commit 481d656

Please sign in to comment.