-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
159 lines (133 loc) · 4.96 KB
/
init.lua
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
-- see :help lua-options for vim.o
-- - vim.go is for global == setglobal
-- - vim.wo is for window like set?
-- - vim.bo is for buffer == set, setlocal
-- see :help lua-vim-opt for vim.opt, which is for treat list/map options as lua list/map
--
-- In Lua using `vim.o`: `vim.o.listchars = 'space:_,tab:>~'`
-- In Lua using `vim.opt`:
-- `vim.opt.listchars = { space = '_', tab = '>~' }`
-- 1. initialization
-- NOTE: vim.cmd is an alias of vim.api.nvim_exec
vim.cmd('filetype off') -- disable filetype detection
vim.cmd('filetype plugin indent off') -- disable plugin based on filetype
-- TODO: why this is required?
vim.cmd('runtime! ftplugin/man.vim') -- source all ftplugin/man.vim file/Ex commands in runtimepath
--- global settings
if vim.env.XDG_CACHE_HOME == nil or vim.env.XDG_CACHE_HOME == '' then
vim.g.cache_home = os.getenv("HOME") .. '/.cache'
else
vim.g.cache_home = vim.env.XDG_CACHE_HOME
end
vim.g.vim_dir = vim.g.cache_home .. '/vim' -- this is now used to store undo history
if vim.env.DOTFILES_ROOT == nil or vim.env.DOTFILES_ROOT == '' then
vim.g.dotfiles_root = os.getenv("HOME") .. '/.dotfiles'
else
vim.g.dotfiles_root = vim.env.DOTFILES_ROOT
end
vim.g.dotfiles_vim_root = vim.g.dotfiles_root .. '/vim'
-- python
vim.g.python_host_prog = "python2"
vim.g.python3_host_prog = "python3"
print("python_host_prog: " .. vim.g.python_host_prog)
print("python3_host_prog: " .. vim.g.python3_host_prog)
-- TODO: vimベース、かつ書き換えをしているので、luaっぽく直す
local function source_rc(path, use_global)
print("sourcing " .. path)
use_global = use_global or not vim.v.vim_did_enter
local abspath = vim.fn.resolve(vim.fn.expand(vim.g.dotfiles_vim_root .. "/".. path))
if not use_global then
vim.cmd('source ' .. vim.fn.fnameescape(abspath))
return
end
-- substitute all 'set' to 'setglobal'
local content = vim.fn.readfile(abspath)
for i, line in ipairs(content) do
content[i] = line:gsub("^%s*set%s", "setglobal ")
end
-- create tempfile and source the tempfile
local tempfile = vim.fn.tempname()
pcall(function()
vim.fn.writefile(content, tempfile)
vim.cmd("source " .. vim.fn.fnameescape(tempfile))
end)
if vim.fn.filereadable(tempfile) > 0 then
vim.fn.delete(tempfile)
end
end
_G.source_rc = source_rc
vim.cmd('syntax on') -- enable syntax highlight
vim.o.compatible = false -- disable vi compatible mode
-- set encoding
vim.o.fileencoding = 'utf-8'
vim.o.encoding = 'utf-8'
-- vim.cmd('scriptencoding utf-8')
-- vim.opt.tenc = 'utf8'
vim.opt.mouse = 'a'
-- auto file control settings
vim.opt.backup = false -- do not create backupfile
vim.opt.swapfile = false -- do not create swapfile
vim.opt.confirm = true -- ask if save unsaved files on quit
vim.opt.autoread = true -- update unchanged buffer on external file change
vim.opt.hidden = true -- enable buffer switching
vim.opt.showcmd = true -- show command during input
vim.opt.modeline = true -- use modeline
vim.opt.modelines = 5 -- parse modeline to line 5
-- view settings
vim.opt.title = true
vim.opt.number = false
vim.opt.ruler = true
vim.opt.showmatch = true
vim.opt.matchtime = 1
vim.opt.cmdheight = 2
vim.opt.list = true
vim.opt.listchars = {tab = '▸\\ ', eol = '↲', extends = '❯', precedes = '❮'}
vim.opt.scrolloff = 4
-- spell settings
vim.opt.spell = false
vim.opt.spelllang = 'en'
-- fold settings
vim.opt.foldmethod = 'syntax'
vim.opt.foldcolumn = '1'
vim.opt.foldlevel = 100
-- search settings
vim.opt.hlsearch = true
vim.opt.incsearch = true
vim.opt.ignorecase = true -- ignore upper&lower case
vim.opt.smartcase = true -- care only upper case with ignorecase
vim.opt.wrapscan = true
vim.opt.wildmode = {'list', 'longest'}
-- vim.opt.wildchar = '<Tab>'
vim.opt.wildchar = 9 -- '\t'
-- clipboard settings
vim.opt.clipboard:remove('*')
vim.opt.clipboard:prepend('unnamedplus')
function OSCYankReg(reg)
local reg_contents = vim.fn.getreg(reg)
reg_contents = vim.fn.escape(reg_contents, '\\')
reg_contents = vim.fn.escape(reg_contents, '\\\\')
reg_contents = vim.fn.escape(reg_contents, '"')
reg_contents = vim.fn.escape(reg_contents, '$')
-- TODO: encode contents without shell call to avoid shell escape issue
local base64_contents = vim.fn.system('echo -n "'.. reg_contents ..'" | base64 | tr -d "\\n"')
local osc52 = "\x1b]52;c;" .. base64_contents .. "\x1b\\"
-- $TTY env var is unset by vim, so _TTY should be set in your .bashrc/.zshrc
local current_tty = vim.env._TTY
vim.fn.writefile({osc52}, current_tty, "b")
end
vim.cmd('autocmd TextYankPost * lua OSCYankReg(vim.v.event.regname)')
-- This line must be before require
vim.o.runtimepath = vim.o.runtimepath .. ',' .. vim.g.dotfiles_vim_root
print("RUNTIME_PATH==")
print(vim.o.runtimepath)
require('map')
-- source_rc("map.vim")
require("command")
-- source_rc("command.vim")
require("edit")
-- source_rc("edit.vim")
-- require("dein.rc")
source_rc("dein.rc.vim")
-- require('lazy-config')
vim.cmd('filetype on')
vim.cmd('filetype plugin indent on')