-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.vim
82 lines (69 loc) · 2.41 KB
/
utils.vim
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
"Remove trailing spaces on save for specified files
function! TrimWhitespace()
let l:save = winsaveview()
keeppatterns %s/\s\+$//e
call winrestview(l:save)
endfunction
" winsaveview() will save the current 'view', which includes the cursor position, folds, jumps, etc.
" winrestview() at the end will restore this from the saved variable.
" :keeppatterns prevents the \s\+$ pattern from being added to the search history.
" The last-used search term is automatically restored after leaving a function, so we don't have to do anything else for this.
augroup trimSpaces
autocmd!
" autocmd BufWritePre *.{js,jsx,ts,tsx,json} call TrimWhitespace()
augroup END
"Auto save files when focus is lost
"The command will complain if you have untitled buffers open.
augroup autoSave
autocmd!
autocmd FocusLost * wall
augroup END
augroup autoSourceVim
autocmd!
"automatically source all the neovim related files after saving it
autocmd bufwritepost *.vim source $MYVIMRC
augroup END
"add any cscope database in current directory
"if filereadable("cscope.out")
" cs add cscope.out
"" else add the database pointed to by environment variable
"elseif $CSCOPE_DB != ""
" cs add $CSCOPE_DB
"endif
function! InsertSkeleton(extention) abort
let filename = expand('%')
let componentName = expand('%:t:r')
" abort on non-empty buffer or exitant file
if !(line('$') == 1 && getline('$') == '') || filereadable(filename)
return
endif
execute '0r $HOME/.config/nvim/templates/skeleton.' . a:extention .''
\ .'| %s/Component/' . componentName . '/g'
\ .'| /function '
endfunction
augroup templates
autocmd!
autocmd BufNewFile *.jsx call InsertSkeleton('jsx')
autocmd BufNewFile *.tsx call InsertSkeleton('tsx')
augroup END
"rename current file with saving undo history via 'saveas'
function! RenameFile()
let old_name = expand('%')
let new_name = input('New file name: ', expand('%'), 'file')
if new_name != '' && new_name != old_name
exec ':saveas ' . new_name
exec ':silent !rm ' . old_name
exec ':silent bw ' . old_name
redraw!
endif
endfunction
nmap <Leader>n :call RenameFile()<cr>
"equalize Vim splits that have been munged by some type of resize event.
augroup resizeWindow
au!
au VimResized * wincmd =
augroup END
augroup highlightYank
au!
au TextYankPost * silent! lua vim.highlight.on_yank({ timeout = 200 })
augroup END