├── .gitignore ├── LICENSE ├── README.md ├── autoload └── gof.vim └── plugin └── gof.vim /.gitignore: -------------------------------------------------------------------------------- 1 | /doc/tags 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2020-2023 itchyny 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vim-gof 2 | 3 | ![gof](https://user-images.githubusercontent.com/375258/74085564-6448fa00-4abd-11ea-8122-4786b75c9f78.gif) 4 | 5 | ## Usage 6 | ``` 7 | :Gof 8 | 9 | " MRU using gof 10 | :let g:gof_mru = 1 11 | :Gof mru 12 | 13 | 14 | " Exclude files by pattern from MRU 15 | :let g:gof_mru_ignore_pattern = '\v/\.git/|/node_modules/' 16 | ``` 17 | 18 | ### Requirements 19 | - Vim with terminal feature (`exists('*term_start')`) 20 | - [gof](https://github.com/mattn/gof) 21 | 22 | ## Author 23 | itchyny (https://github.com/itchyny) 24 | 25 | ## License 26 | This software is released under the MIT License, see LICENSE. 27 | -------------------------------------------------------------------------------- /autoload/gof.vim: -------------------------------------------------------------------------------- 1 | " ============================================================================= 2 | " Filename: autoload/gof.vim 3 | " Author: itchyny 4 | " License: MIT License 5 | " Last Change: 2023/07/16 16:43:37. 6 | " ============================================================================= 7 | 8 | function! gof#start(args) abort 9 | if a:args ==# 'mru' 10 | let input = ' < ' .. (filereadable(gof#mru_path()) ? shellescape(gof#mru_path()) : '<(:)') 11 | elseif empty(system('git rev-parse')) 12 | let input = ' < <(git ls-files --deduplicate "$(git rev-parse --show-toplevel)")' 13 | else 14 | let input = '' 15 | endif 16 | botright call term_start( 17 | \ [&shell, &shellcmdflag, 'gof -a ctrl-t,ctrl-v -tf gof#tapi' .. input], 18 | \ #{ term_rows: max([&lines / 4, 10]), term_finish: 'close', term_api: 'gof#tapi' } 19 | \ ) 20 | endfunction 21 | 22 | function! gof#tapi(bufnr, arg) abort 23 | let command = get({ 'ctrl-t': 'tabnew', 'ctrl-v': 'vnew' }, a:arg.action_key, 'edit') 24 | call timer_start(50, {->execute(command .. ' ' .. fnamemodify(a:arg.filename, ':p'))}) 25 | endfunction 26 | 27 | let s:files = [] 28 | let s:files_map = {} 29 | function! gof#mru_opened(name) abort 30 | if !empty(&buftype) || !filereadable(a:name) 31 | return 32 | endif 33 | let name = fnamemodify(a:name, ':~') 34 | call filter(s:files, {->v:val !=# name}) 35 | if name !~# get(g:, 'gof_mru_ignore_pattern', '$^') 36 | call insert(s:files, name, 0) 37 | endif 38 | let s:files_map[name] = v:false 39 | call gof#mru_debounce_save() 40 | endfunction 41 | 42 | function! gof#mru_path() abort 43 | let data_home = has('win32') && exists('$LOCALAPPDATA') ? $LOCALAPPDATA 44 | \ : exists('$XDG_DATA_HOME') ? $XDG_DATA_HOME : expand('~/.local/share') 45 | let dir = data_home .. '/vim-gof' 46 | call mkdir(dir, 'p', 0700) 47 | return dir .. '/mru.txt' 48 | endfunction 49 | 50 | function! gof#mru_list() abort 51 | let path = gof#mru_path() 52 | return filereadable(path) ? readfile(path) : [] 53 | endfunction 54 | 55 | let s:timer_id = 0 56 | function! gof#mru_debounce_save() abort 57 | call timer_stop(s:timer_id) 58 | let s:timer_id = timer_start(3 * 60 * 1000, 'gof#mru_save') 59 | augroup gof-mru-save 60 | autocmd! 61 | autocmd VimLeavePre * call gof#mru_save() 62 | augroup END 63 | endfunction 64 | 65 | function! gof#mru_save(...) abort 66 | let path = gof#mru_path() 67 | let tmp = fnamemodify(path, ':r') .. '.' .. rand(srand()) .. '.txt' 68 | call writefile( 69 | \ extend(s:files, 70 | \ filter(gof#mru_list(), 71 | \ 'get(s:files_map, v:val, v:true) && 72 | \ (v:key % 10 > 0 || filereadable(fnamemodify(v:val, ":p")) && 73 | \ v:val !~# get(g:, "gof_mru_ignore_pattern", "$^"))' 74 | \ ) 75 | \ )[:99999], 76 | \ tmp) 77 | call rename(tmp, path) 78 | let s:files = [] 79 | let s:files_map = {} 80 | augroup gof-mru-save 81 | autocmd! 82 | augroup END 83 | endfunction 84 | -------------------------------------------------------------------------------- /plugin/gof.vim: -------------------------------------------------------------------------------- 1 | " ============================================================================= 2 | " Filename: plugin/gof.vim 3 | " Author: itchyny 4 | " License: MIT License 5 | " Last Change: 2020/11/11 03:03:36. 6 | " ============================================================================= 7 | 8 | if exists('g:loaded_gof') || !has('patch-8.1.2080') || !executable('gof') 9 | finish 10 | endif 11 | let g:loaded_gof = 1 12 | 13 | command! -nargs=* Gof call gof#start() 14 | 15 | if get(g:, 'gof_mru') 16 | augroup gof-mru 17 | autocmd! 18 | autocmd BufWinEnter,BufWritePost * call gof#mru_opened(expand(':p')) 19 | augroup END 20 | endif 21 | --------------------------------------------------------------------------------