-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.vimrc
More file actions
133 lines (114 loc) · 3.67 KB
/
.vimrc
File metadata and controls
133 lines (114 loc) · 3.67 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
set number
set cursorline
set clipboard+=unnamed
set laststatus=0
set cmdheight=0
set title
set titlestring=%t
set shortmess+=F
set noshowcmd
set noshowmode
set signcolumn=no
set autoread
set nobackup
set noswapfile
set backspace=indent,eol,start
set whichwrap=h,l
syntax on
filetype plugin indent on
set hlsearch
set incsearch
set ignorecase
set smartcase
set autoindent
set expandtab
set tabstop=4
set shiftwidth=4
set ambiwidth=double
set wildmenu
set wildmode=longest:full,full
autocmd FileType javascript,typescript,json,yaml setlocal tabstop=2 shiftwidth=2
inoremap jj <ESC>
nnoremap <Esc><Esc> :nohlsearch<Enter>
nnoremap ;; :
cnoreabbrev %y silent %y
let s:dotfiles_dir = fnamemodify(resolve(expand('<sfile>:p')), ':h')
let s:mise_shims = expand('~/.local/share/mise/shims')
if isdirectory(s:mise_shims) && index(split($PATH, ':'), s:mise_shims) < 0
let $PATH = s:mise_shims . ':' . $PATH
endif
function! s:resolve_executable(name) abort
let l:candidates = [
\ exepath(a:name),
\ expand('~/.local/share/mise/shims/' . a:name),
\ expand('~/.volta/bin/' . a:name),
\ '/opt/homebrew/bin/' . a:name,
\ '/usr/local/bin/' . a:name,
\ ]
for l:candidate in l:candidates
if !empty(l:candidate) && executable(l:candidate)
return l:candidate
endif
endfor
return a:name
endfunction
let s:npx = s:resolve_executable('npx')
let s:textlint_config = s:dotfiles_dir . '/.textlintrc.json'
let s:textlint_cmd = shellescape(s:npx)
\ . ' --yes'
\ . ' --package textlint'
\ . ' --package textlint-rule-ja-space-between-half-and-full-width'
\ . ' --package textlint-rule-no-space-between-full-width'
\ . ' textlint'
function! RunFormatAndFix()
let l:view = winsaveview()
let l:ext = expand('%:e')
let l:tempfile = tempname() . '.' . l:ext
try
call writefile(getline(1, '$'), l:tempfile)
let l:cmd_oxfmt = shellescape(s:npx) . ' oxfmt ' . shellescape(l:tempfile)
let l:oxfmt_output = system(l:cmd_oxfmt)
if v:shell_error != 0
if l:oxfmt_output =~ 'Expected at least one target file'
echo "oxfmt: skipped (unsupported file type)"
return
endif
echoerr "oxfmt failed! " . l:oxfmt_output
return
endif
echo "oxfmt: OK... "
" textlint (markdown のみ)
if &filetype == 'markdown'
let l:cmd_textlint = s:textlint_cmd
\ . ' --config ' . shellescape(s:textlint_config)
\ . ' --fix '
\ . shellescape(l:tempfile)
let l:textlint_output = system(l:cmd_textlint)
let l:textlint_exit = v:shell_error
if l:textlint_exit == 2
echoerr "textlint error! " . l:textlint_output
return
elseif l:textlint_exit == 1
echo "Formatted & Fixed (Issues remain) ⚠️"
else
echo "Formatted & Fixed (Perfect) ✨"
endif
else
echo "Formatted (oxfmt) ✨"
endif
let l:final_lines = readfile(l:tempfile)
let l:current_lines = getline(1, '$')
if l:final_lines != l:current_lines
silent %delete _
call setline(1, l:final_lines)
endif
call winrestview(l:view)
redraw
finally
call delete(l:tempfile)
endtry
endfunction
nnoremap <C-=> :call RunFormatAndFix()<CR>
let &makeprg = fnameescape(s:npx) . ' oxlint --type-aware %'
set errorformat=%f:%l:%c:\ %m
command! Lint silent make | redraw! | copen