blob: 56ba209cb23044eda7457a34710d65a33b297b70 (
plain)
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
|
local user_at_host = vim.uv.os_get_passwd().username .. "@" .. vim.uv.os_gethostname()
-- insert user@host into statusline if running in ssh session
if vim.env.SSH_CONNECTION ~= nil or vim.env.SSH_TTY ~= nil then
local ssh_status = "[" .. user_at_host .. "] "
vim.o.statusline = vim.o.statusline:gsub("%%f", ssh_status .. "%%f", 1) -- before filename
end
-- insert user@host into titlestring
-- builtin titlestring must be reconstructed
function _G.title_flags()
local f = (vim.bo.readonly and "=" or "") .. (vim.bo.modified and "+" or "")
if not vim.bo.modifiable then f = f .. "-" end
return f ~= "" and (" " .. f) or ""
end
vim.o.titlestring = '%t%{v:lua.title_flags()} (' .. user_at_host .. ' %{expand("%:~:h")}%a) - Nvim'
--
vim.cmd [[
"" Extra functionality
"" Functions for changing the terminal emulator's class name to 'Vim'
"function GetTermPID(temu)
" let pinfo = ['', getpid(), '']
" while !(pinfo[2] =~ a:temu || pinfo[1] == '0')
" let pinfo = split(system('ps h -o pid,ppid,command= -p' . pinfo[1]))
" endwhile
" return pinfo[0]
"endfunction
"function SetTermClassName(termpid, name)
" " Command chaining in xdotool doesn't work here for some reason
" silent exec "!xdotool set_window --class " . a:name . " $(xdotool search --pid " . a:termpid . ")"
"endfunction
"" Behaviors exclusive to either a tty or a graphical terminal emulator
"if empty($DISPLAY)
" " Clear the tty screen after exiting vim
" autocmd VimLeave * :clear
"else
" " Highlight current line
" set cursorline
" " Change window title
" autocmd BufEnter * :set title
" let &titleold="st"
" " Change class name
" let temu = "st"
" let temupid = GetTermPID(temu)
" if (temupid != 1)
" autocmd VimEnter * call SetTermClassName(temupid, "Vim")
" autocmd VimLeave * call SetTermClassName(temupid, temu)
" endif
"endif
" Automatically deletes all trailing whitespace on save
function DelWS()
let l:save_view = winsaveview()
:%s/\s*$//e
call winrestview(l:save_view)
endfunction
autocmd BufWritePre * call DelWS()
" vim -b : edit binary using xxd-format!
augroup Binary
au!
au BufReadPre *.bin let &bin=1
au BufReadPost *.bin if &bin | %!xxd
au BufReadPost *.bin set ft=xxd | endif
au BufWritePre *.bin if &bin | %!xxd -r
au BufWritePre *.bin endif
au BufWritePost *.bin if &bin | %!xxd
au BufWritePost *.bin set nomod | endif
augroup END
]]
|