vim: convert lua files to tabstop = 2

This commit is contained in:
Fernando Schauenburg 2022-02-01 20:53:19 +01:00
parent f8181683e9
commit bef5e01951
4 changed files with 257 additions and 304 deletions

View file

@ -1,133 +1,86 @@
local colors = {} local colors = {}
if vim.opt.termguicolors:get() then if vim.opt.termguicolors:get() then
colors = { colors = {
base03 = '#002b36', yellow = '#b58900', base03 = '#002b36', yellow = '#b58900',
base02 = '#073642', orange = '#cb4b16', base02 = '#073642', orange = '#cb4b16',
base01 = '#586e75', red = '#dc322f', base01 = '#586e75', red = '#dc322f',
base00 = '#657b83', magenta = '#d33682', base00 = '#657b83', magenta = '#d33682',
base0 = '#839496', violet = '#6c71c4', base0 = '#839496', violet = '#6c71c4',
base1 = '#93a1a1', blue = '#268bd2', base1 = '#93a1a1', blue = '#268bd2',
base2 = '#eee8d5', cyan = '#2aa198', base2 = '#eee8d5', cyan = '#2aa198',
base3 = '#fdf6e3', green = '#859900', base3 = '#fdf6e3', green = '#859900',
} }
else else
colors = { colors = {
base03 = 8, yellow = 3, base03 = 8, yellow = 3,
base02 = 0, orange = 9, base02 = 0, orange = 9,
base01 = 10, red = 1, base01 = 10, red = 1,
base00 = 11, magenta = 5, base00 = 11, magenta = 5,
base0 = 12, violet = 13, base0 = 12, violet = 13,
base1 = 14, blue = 4, base1 = 14, blue = 4,
base2 = 7, cyan = 6, base2 = 7, cyan = 6,
base3 = 15, green = 2, base3 = 15, green = 2,
} }
end end
local progress = { '%3p%%×%L %3l:%-2v', padding = { left = 0, right = 1 } } local progress = { '%3p%%×%L %3l:%-2v', padding = { left = 0, right = 1 } }
local relative_path = { 'filename', path = 1 } local relative_path = { 'filename', path = 1 }
local encoding = function () local encoding = function ()
local fenc = vim.opt.fileencoding:get() local fenc = vim.opt.fileencoding:get()
if fenc ~= '' then if fenc ~= '' then
return fenc return fenc
end end
return vim.opt.encoding:get() return vim.opt.encoding:get()
end end
local fileformat = { 'fileformat', padding = { left = 0, right = 1} } local fileformat = { 'fileformat', padding = { left = 0, right = 1} }
require('lualine').setup { require('lualine').setup {
options = { options = {
icons_enabled = true, icons_enabled = true,
component_separators = { left = '', right = '' }, component_separators = { left = '', right = '' },
section_separators = { left = '', right = '' }, section_separators = { left = '', right = '' },
theme = { theme = {
normal = { normal = {
a = { fg = colors.base03, bg = colors.blue, gui='bold' }, a = { fg = colors.base03, bg = colors.blue, gui='bold' },
b = { fg = colors.base2, bg = colors.base00 }, b = { fg = colors.base2, bg = colors.base00 },
c = { fg = colors.base1, bg = colors.base02 }, c = { fg = colors.base1, bg = colors.base02 },
},
insert = { a = { fg = colors.base03, bg = colors.green, gui = 'bold' } },
visual = { a = { fg = colors.base03, bg = colors.magenta, gui = 'bold' } },
replace = { a = { fg = colors.base03, bg = colors.red, gui = 'bold' } },
inactive = {
a = { fg = colors.base1, bg = colors.base00 },
b = { fg = colors.base0, bg = colors.base01 },
c = { fg = colors.base00, bg = colors.base02 },
},
}, },
insert = { a = { fg = colors.base03, bg = colors.green, gui = 'bold' } },
visual = { a = { fg = colors.base03, bg = colors.magenta, gui = 'bold' } },
replace = { a = { fg = colors.base03, bg = colors.red, gui = 'bold' } },
inactive = {
a = { fg = colors.base1, bg = colors.base00 },
b = { fg = colors.base0, bg = colors.base01 },
c = { fg = colors.base00, bg = colors.base02 },
},
},
}, },
sections = { sections = {
lualine_a = { lualine_a = {
'mode', 'mode',
{ {
function() return 'PASTE' end, function() return 'PASTE' end,
color = { bg = colors.yellow }, color = { bg = colors.yellow },
cond = function() return vim.opt.paste:get() end cond = function() return vim.opt.paste:get() end
},
}, },
lualine_b = { 'diagnostics', 'branch' }, },
lualine_c = { relative_path }, lualine_b = { 'diagnostics', 'branch' },
lualine_x = { 'filetype' }, lualine_c = { relative_path },
lualine_y = { encoding, fileformat }, lualine_x = { 'filetype' },
lualine_z = { progress }, lualine_y = { encoding, fileformat },
lualine_z = { progress },
}, },
inactive_sections = { inactive_sections = {
lualine_a = {}, lualine_a = {},
lualine_b = { 'diagnostics', 'branch' }, lualine_b = { 'diagnostics', 'branch' },
lualine_c = { relative_path }, lualine_c = { relative_path },
lualine_x = { 'filetype' }, lualine_x = { 'filetype' },
lualine_y = { encoding, fileformat }, lualine_y = { encoding, fileformat },
lualine_z = { progress }, lualine_z = { progress },
}, },
extensions = { 'fugitive', 'quickfix' } extensions = { 'fugitive', 'quickfix' }
} }

View file

@ -1,39 +1,39 @@
local function make_autocmds(groups) local function make_autocmds(groups)
for name, commands in pairs(groups) do for name, commands in pairs(groups) do
vim.cmd('augroup my_' .. name) vim.cmd('augroup my_' .. name)
vim.cmd('autocmd!') vim.cmd('autocmd!')
for _, item in ipairs(commands) do for _, item in ipairs(commands) do
vim.cmd('autocmd ' .. table.concat(item, ' ')) vim.cmd('autocmd ' .. table.concat(item, ' '))
end
vim.cmd('augroup END')
end end
vim.cmd('augroup END')
end
end end
make_autocmds { make_autocmds {
buffers = { buffers = {
{ 'BufNewFile,BufRead', 'bash_profile,bashrc,profile', 'set filetype=sh' }, { 'BufNewFile,BufRead', 'bash_profile,bashrc,profile', 'set filetype=sh' },
{ 'BufNewFile,BufRead', 'gitconfig', 'set filetype=gitconfig' }, { 'BufNewFile,BufRead', 'gitconfig', 'set filetype=gitconfig' },
{ 'BufNewFile,BufRead', '*.sx,*.s19', 'set filetype=srec' }, { 'BufNewFile,BufRead', '*.sx,*.s19', 'set filetype=srec' },
{ 'BufNewFile,BufRead', 'Vagrantfile', 'set filetype=ruby' }, { 'BufNewFile,BufRead', 'Vagrantfile', 'set filetype=ruby' },
-- Make it possible to use `gf` to jump to my configuration modules. -- Make it possible to use `gf` to jump to my configuration modules.
{ 'BufNewFile,BufRead', 'init.lua', { 'BufNewFile,BufRead', 'init.lua',
"setlocal path+=~/.config/nvim/lua includeexpr=substitute(v:fname,'\\\\.','/','g')"}, "setlocal path+=~/.config/nvim/lua includeexpr=substitute(v:fname,'\\\\.','/','g')"},
}, },
filetypes = { filetypes = {
{ 'FileType', 'gitcommit', 'setlocal textwidth=72' }, { 'FileType', 'gitcommit', 'setlocal textwidth=72' },
{ 'FileType', 'gitcommit,markdown,text', 'setlocal formatoptions+=t spell' }, { 'FileType', 'gitcommit,markdown,text', 'setlocal formatoptions+=t spell' },
{ 'FileType', 'python', 'setlocal foldmethod=indent foldignore=' }, { 'FileType', 'python', 'setlocal foldmethod=indent foldignore=' },
{ 'FileType', 'vim', 'set foldmethod=marker' }, { 'FileType', 'vim', 'set foldmethod=marker' },
}, },
windows = { windows = {
-- Disable cursorline when entering Insert mode (but remember it)... -- Disable cursorline when entering Insert mode (but remember it)...
{ 'InsertEnter', '*', 'let g:stored_cursorline=&cursorline | set nocursorline' }, { 'InsertEnter', '*', 'let g:stored_cursorline=&cursorline | set nocursorline' },
-- ...and re-enable when leaving if it had been set before. -- ...and re-enable when leaving if it had been set before.
{ 'InsertLeave', '*', 'let &cursorline=g:stored_cursorline' }, { 'InsertLeave', '*', 'let &cursorline=g:stored_cursorline' },
}, },
yank = { yank = {
-- Briefly highlight yanked text. -- Briefly highlight yanked text.
{ 'TextYankPost', '*', 'silent! lua vim.highlight.on_yank()' }, { 'TextYankPost', '*', 'silent! lua vim.highlight.on_yank()' },
}, },
} }

View file

@ -1,83 +1,83 @@
local M = function(mode, lhs, rhs, opts) local M = function(mode, lhs, rhs, opts)
local merged_opts = vim.tbl_extend('keep', opts or {}, { noremap = true }) local merged_opts = vim.tbl_extend('keep', opts or {}, { noremap = true })
local map = { mode = mode, lhs = lhs, rhs = rhs, opts = merged_opts } local map = { mode = mode, lhs = lhs, rhs = rhs, opts = merged_opts }
map.remap = function() map.opts.noremap = false; return map end map.remap = function() map.opts.noremap = false; return map end
map.silent = function() map.opts.silent = true; return map end map.silent = function() map.opts.silent = true; return map end
map.expr = function() map.opts.expr = true; return map end map.expr = function() map.opts.expr = true; return map end
map.unique = function() map.opts.unique = true; return map end map.unique = function() map.opts.unique = true; return map end
map.nowait = function() map.opts.nowait = true; return map end map.nowait = function() map.opts.nowait = true; return map end
map.script = function() map.opts.script = true; return map end map.script = function() map.opts.script = true; return map end
return map return map
end end
local register = function(maps) local register = function(maps)
for _, m in ipairs(maps) do for _, m in ipairs(maps) do
vim.api.nvim_set_keymap(m.mode, m.lhs, m.rhs, m.opts) vim.api.nvim_set_keymap(m.mode, m.lhs, m.rhs, m.opts)
end end
end end
vim.g.mapleader = ' ' vim.g.mapleader = ' '
register { register {
-- better navigation for wrapped lines -- better navigation for wrapped lines
M('n', 'j', 'gj'), M('n', 'j', 'gj'),
M('n', 'k', 'gk'), M('n', 'k', 'gk'),
-- retain selection when indenting/unindenting in visual mode -- retain selection when indenting/unindenting in visual mode
M('v', '>', '><cr>gv'), M('v', '>', '><cr>gv'),
M('v', '<', '<<cr>gv'), M('v', '<', '<<cr>gv'),
-- easier window navigation -- easier window navigation
M('n', '<c-j>', '<c-w>j'), M('n', '<c-j>', '<c-w>j'),
M('n', '<c-k>', '<c-w>k'), M('n', '<c-k>', '<c-w>k'),
M('n', '<c-h>', '<c-w>h'), M('n', '<c-h>', '<c-w>h'),
M('n', '<c-l>', '<c-w>l'), M('n', '<c-l>', '<c-w>l'),
-- window resizing -- window resizing
M('n', '<Up>', '<cmd>resize +1<cr>'), M('n', '<Up>', '<cmd>resize +1<cr>'),
M('n', '<Down>', '<cmd>resize -1<cr>'), M('n', '<Down>', '<cmd>resize -1<cr>'),
M('n', '<Left>', '<cmd>vertical resize -1<cr>'), M('n', '<Left>', '<cmd>vertical resize -1<cr>'),
M('n', '<Right>', '<cmd>vertical resize +1<cr>'), M('n', '<Right>', '<cmd>vertical resize +1<cr>'),
-- easier tab navigation -- easier tab navigation
M('n', '<c-n>', ':tabprevious<cr>').silent(), M('n', '<c-n>', ':tabprevious<cr>').silent(),
M('n', '<c-m>', ':tabnext<cr>' ).silent(), M('n', '<c-m>', ':tabnext<cr>' ).silent(),
-- move lines up and down -- move lines up and down
M('n', '<A-j>', [[:move .+1<cr>==]] ).silent(), M('n', '<A-j>', [[:move .+1<cr>==]] ).silent(),
M('n', '<A-k>', [[:move .-2<cr>==]] ).silent(), M('n', '<A-k>', [[:move .-2<cr>==]] ).silent(),
M('v', '<A-j>', [[:move '>+1<cr>gv=gv]] ).silent(), M('v', '<A-j>', [[:move '>+1<cr>gv=gv]] ).silent(),
M('v', '<A-k>', [[:move '<-2<cr>gv=gv]] ).silent(), M('v', '<A-k>', [[:move '<-2<cr>gv=gv]] ).silent(),
M('i', '<A-j>', [[<esc>:move .+1<cr>==gi]] ).silent(), M('i', '<A-j>', [[<esc>:move .+1<cr>==gi]] ).silent(),
M('i', '<A-k>', [[<esc>:move .-2<cr>==gi]] ).silent(), M('i', '<A-k>', [[<esc>:move .-2<cr>==gi]] ).silent(),
-- cycle through line numbering modes -- cycle through line numbering modes
M('n', '<leader>ln', ':set nonumber norelativenumber<CR>' ).silent(), M('n', '<leader>ln', ':set nonumber norelativenumber<CR>' ).silent(),
M('n', '<leader>ll', ':set number norelativenumber<CR>' ).silent(), M('n', '<leader>ll', ':set number norelativenumber<CR>' ).silent(),
M('n', '<leader>lr', ':set number relativenumber<CR>' ).silent(), M('n', '<leader>lr', ':set number relativenumber<CR>' ).silent(),
-- show list of buffers and prepare to switch -- show list of buffers and prepare to switch
M('n', '<leader>bf', ':ls<CR>:b<Space>'), M('n', '<leader>bf', ':ls<CR>:b<Space>'),
-- quickly change background -- quickly change background
M('n', '<leader>bg', [[:let &background = &background ==? 'light' ? 'dark' : 'light'<cr>]]), M('n', '<leader>bg', [[:let &background = &background ==? 'light' ? 'dark' : 'light'<cr>]]),
-- use fugitive -- use fugitive
M('n', '<leader>gg', ':G<cr>'), M('n', '<leader>gg', ':G<cr>'),
M('n', '<leader>g<space>', ':G '), M('n', '<leader>g<space>', ':G '),
-- disable highlight until next search -- disable highlight until next search
M('n', '<leader>h', ':nohlsearch<cr>'), M('n', '<leader>h', ':nohlsearch<cr>'),
-- toggle NERDTree -- toggle NERDTree
M('n', '<leader>n', ':NERDTreeToggle<cr>'), M('n', '<leader>n', ':NERDTreeToggle<cr>'),
-- toggle rainbow parens -- toggle rainbow parens
M('n', '<leader>p', ':RainbowParentheses!!<cr>'), M('n', '<leader>p', ':RainbowParentheses!!<cr>'),
-- edit init.lua -- edit init.lua
M('n', '<leader>v', ':e $MYVIMRC<cr>'), M('n', '<leader>v', ':e $MYVIMRC<cr>'),
-- fix whitespace -- fix whitespace
M('n', '<leader>w', ':FixWhitespace<cr>'), M('n', '<leader>w', ':FixWhitespace<cr>'),
} }

View file

@ -2,123 +2,123 @@ vim.cmd([[let &t_8f = "\<ESC>[38:2:%lu:%lu:%lum"]])
vim.cmd([[let &t_8b = "\<ESC>[48:2:%lu:%lu:%lum"]]) vim.cmd([[let &t_8b = "\<ESC>[48:2:%lu:%lu:%lum"]])
local set_options = function(options) local set_options = function(options)
local opt = vim.opt local opt = vim.opt
for k, v in pairs(options) do for k, v in pairs(options) do
opt[k] = v opt[k] = v
end end
end end
set_options { set_options {
-- General -- General
belloff = 'all', -- never ring bells belloff = 'all', -- never ring bells
hidden = true, -- hide abandoned buffers hidden = true, -- hide abandoned buffers
clipboard = 'unnamedplus', -- synchronize with system clipboard clipboard = 'unnamedplus', -- synchronize with system clipboard
lazyredraw = true, -- don't redraw screen during macros lazyredraw = true, -- don't redraw screen during macros
modelines = 0, -- never use modelines modelines = 0, -- never use modelines
fileformats = 'unix,mac,dos', -- prioritize unix <EOL> format fileformats = 'unix,mac,dos', -- prioritize unix <EOL> format
pastetoggle = '<F20>', -- toggle paste with P on Moonlander pastetoggle = '<F20>', -- toggle paste with P on Moonlander
swapfile = false, -- don't use swap files swapfile = false, -- don't use swap files
writebackup = true, -- Make a backup before writing a file... writebackup = true, -- Make a backup before writing a file...
backup = false, -- ...but don't keep it around. backup = false, -- ...but don't keep it around.
shortmess = vim.opt.shortmess + 'I', -- no intro message when starting Vim shortmess = vim.opt.shortmess + 'I', -- no intro message when starting Vim
shada = { shada = {
"'1000", -- remember marks for this many files "'1000", -- remember marks for this many files
"/1000", -- remember this many search patterns "/1000", -- remember this many search patterns
":1000", -- remember this many command line items ":1000", -- remember this many command line items
"<100", -- maximum number of lines to remember per register "<100", -- maximum number of lines to remember per register
"h", -- disable 'hlsearch' while reading shada file "h", -- disable 'hlsearch' while reading shada file
"s100", -- limit size of remembered items to this many KiB "s100", -- limit size of remembered items to this many KiB
}, },
-- Searching -- Searching
ignorecase = true, -- Ignore case when searching... ignorecase = true, -- Ignore case when searching...
smartcase = true, -- ...unless pattern contains uppercase characters. smartcase = true, -- ...unless pattern contains uppercase characters.
-- Editing -- Editing
expandtab = true, -- use spaces whe <Tab> is inserted expandtab = true, -- use spaces whe <Tab> is inserted
tabstop = 4, -- tabs are 4 spaces tabstop = 4, -- tabs are 4 spaces
shiftwidth = 0, -- (auto)indent using 'tabstop' spaces shiftwidth = 0, -- (auto)indent using 'tabstop' spaces
smartindent = true, -- use smart autoindenting smartindent = true, -- use smart autoindenting
inccommand = 'split', -- preview command partial results inccommand = 'split', -- preview command partial results
joinspaces = false, -- use one space after a period whe joining lines joinspaces = false, -- use one space after a period whe joining lines
showmatch = true, -- briefly jump to matching bracket if insert one showmatch = true, -- briefly jump to matching bracket if insert one
virtualedit = 'block', -- position the cursor anywhere in Visual Block mode virtualedit = 'block', -- position the cursor anywhere in Visual Block mode
formatlistpat = [[^\s*\(\d\+[\]:.)}\t ]\|[-+*]\|[\[(][ x][\])]\)\s*]], formatlistpat = [[^\s*\(\d\+[\]:.)}\t ]\|[-+*]\|[\[(][ x][\])]\)\s*]],
formatoptions = vim.opt.formatoptions formatoptions = vim.opt.formatoptions
- 't' -- Don't auto-wrap on 'textwidth'... - 't' -- Don't auto-wrap on 'textwidth'...
+ 'c' -- ...but do it within comment blocks... + 'c' -- ...but do it within comment blocks...
+ 'l' -- ...but not if line was already long before entering Insert mode. + 'l' -- ...but not if line was already long before entering Insert mode.
+ 'r' -- Insert comment leader when pressing Enter... + 'r' -- Insert comment leader when pressing Enter...
- 'o' -- ...but not when opening a new line with o & O. - 'o' -- ...but not when opening a new line with o & O.
+ 'q' -- allow formatting of comments with gq + 'q' -- allow formatting of comments with gq
- 'a' -- don't auto-format every time text is inserted - 'a' -- don't auto-format every time text is inserted
+ 'n' -- indent lists automatically acc. 'formatlistpat' + 'n' -- indent lists automatically acc. 'formatlistpat'
+ 'j' -- remove comment leader when joining lines + 'j' -- remove comment leader when joining lines
+ '1', -- don't break lines after a one letter word but rather before it + '1', -- don't break lines after a one letter word but rather before it
-- Appearance -- Appearance
showmode = false, -- don't show mode (shown in statusline instead) showmode = false, -- don't show mode (shown in statusline instead)
relativenumber = true, -- Start off with realtive line numbers... relativenumber = true, -- Start off with realtive line numbers...
number = true, -- ...but real number for current line. number = true, -- ...but real number for current line.
wrap = false, -- don't wrap long lines initially wrap = false, -- don't wrap long lines initially
textwidth = 79, -- maximum width for text being inserted textwidth = 79, -- maximum width for text being inserted
colorcolumn = '+1', -- highlight column after 'textwidth' colorcolumn = '+1', -- highlight column after 'textwidth'
cursorline = true, -- highlight the line of the cursor cursorline = true, -- highlight the line of the cursor
showbreak = '', -- prefix for wrapped lines showbreak = '', -- prefix for wrapped lines
scrolloff = 3, -- min. # of lines above and below cursor scrolloff = 3, -- min. # of lines above and below cursor
sidescrolloff = 3, -- min. # of columns to left and right of cursor sidescrolloff = 3, -- min. # of columns to left and right of cursor
list = true, -- show invisible characters list = true, -- show invisible characters
listchars = { listchars = {
tab = '» ', tab = '» ',
extends = '', extends = '',
precedes = '', precedes = '',
trail = '·', trail = '·',
conceal = '', conceal = '',
}, },
-- Wildcard Expansion -- Wildcard Expansion
wildignore = { wildignore = {
'.git', '.git',
'.svn', '.svn',
'__pycache__', '__pycache__',
'**/tmp/**', '**/tmp/**',
'*.DS_Store', '*.DS_Store',
'*.dll', '*.dll',
'*.egg-info', '*.egg-info',
'*.exe', '*.exe',
'*.gif', '*.gif',
'*.jpeg', '*.jpeg',
'*.jpg', '*.jpg',
'*.o', '*.o',
'*.obj', '*.obj',
'*.out', '*.out',
'*.png', '*.png',
'*.pyc', '*.pyc',
'*.so', '*.so',
'*.zip', '*.zip',
'*~', '*~',
}, },
wildignorecase = true, -- ignore case when completing file names wildignorecase = true, -- ignore case when completing file names
wildmode = 'longest:full', -- longest common prefix first, then wildmenu wildmode = 'longest:full', -- longest common prefix first, then wildmenu
-- Window Splitting -- Window Splitting
splitbelow = true, -- :split below current window splitbelow = true, -- :split below current window
splitright = true, -- :vsplit to the right of current window splitright = true, -- :vsplit to the right of current window
equalalways = false, -- don't resize all windows when splitting equalalways = false, -- don't resize all windows when splitting
-- Folding -- Folding
foldenable = true, -- enable folding foldenable = true, -- enable folding
foldlevelstart = 100, -- start with all folds open foldlevelstart = 100, -- start with all folds open
foldmethod = 'syntax', -- fold based on syntax by default foldmethod = 'syntax', -- fold based on syntax by default
foldnestmax = 10, -- limit nested folds to 10 levels foldnestmax = 10, -- limit nested folds to 10 levels
-- Options for diff mode -- Options for diff mode
diffopt = { -- better side-by-side diffs diffopt = { -- better side-by-side diffs
'filler', -- show filler lines (so text ins vertically synced) 'filler', -- show filler lines (so text ins vertically synced)
'vertical', -- use vertical splits (files side-by-side) 'vertical', -- use vertical splits (files side-by-side)
'closeoff', -- disable diff mode when one window is closed 'closeoff', -- disable diff mode when one window is closed
}, },
} }