1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
| function! GotoFileWithLineNum()
" exclude comma from file name search
" change the 'isfname' option temporarily to pick up file name in ncverilog MSG
let bak_isfname = &isfname
set isfname=@,48-57,/,.,-,_,+,#,$,%,~,="
" filename under the cursor
let file_name = expand('<cfile>')
if !strlen(file_name)
echo 'NO FILE UNDER CURSOR'
return
endif
" look for a line number separated by any :,"<space>
if search('\%#\f*[:, "]*\zs[0-9]\+')
" change the 'iskeyword' option temporarily to pick up just numbers
let temp = &iskeyword
set iskeyword=48-57
let line_number = expand('<cword>')
exe 'set iskeyword=' . temp
endif
exe 'set isfname=' . bak_isfname
" edit the file
exe 'e '.file_name
" if there is a line number, go to it
if exists('line_number')
exe line_number
endif
endfunction
map gf :call GotoFileWithLineNum()<CR>
map gsf :sp<CR>:call GotoFileWithLineNum()<CR>
|