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

View file

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

View file

@ -1,83 +1,83 @@
local M = function(mode, lhs, rhs, opts)
local merged_opts = vim.tbl_extend('keep', opts or {}, { noremap = true })
local map = { mode = mode, lhs = lhs, rhs = rhs, opts = merged_opts }
map.remap = function() map.opts.noremap = false; return map end
map.silent = function() map.opts.silent = 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.nowait = function() map.opts.nowait = true; return map end
map.script = function() map.opts.script = true; return map end
return map
local merged_opts = vim.tbl_extend('keep', opts or {}, { noremap = true })
local map = { mode = mode, lhs = lhs, rhs = rhs, opts = merged_opts }
map.remap = function() map.opts.noremap = false; return map end
map.silent = function() map.opts.silent = 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.nowait = function() map.opts.nowait = true; return map end
map.script = function() map.opts.script = true; return map end
return map
end
local register = function(maps)
for _, m in ipairs(maps) do
vim.api.nvim_set_keymap(m.mode, m.lhs, m.rhs, m.opts)
end
for _, m in ipairs(maps) do
vim.api.nvim_set_keymap(m.mode, m.lhs, m.rhs, m.opts)
end
end
vim.g.mapleader = ' '
register {
-- better navigation for wrapped lines
M('n', 'j', 'gj'),
M('n', 'k', 'gk'),
-- better navigation for wrapped lines
M('n', 'j', 'gj'),
M('n', 'k', 'gk'),
-- retain selection when indenting/unindenting in visual mode
M('v', '>', '><cr>gv'),
M('v', '<', '<<cr>gv'),
-- retain selection when indenting/unindenting in visual mode
M('v', '>', '><cr>gv'),
M('v', '<', '<<cr>gv'),
-- easier window navigation
M('n', '<c-j>', '<c-w>j'),
M('n', '<c-k>', '<c-w>k'),
M('n', '<c-h>', '<c-w>h'),
M('n', '<c-l>', '<c-w>l'),
-- easier window navigation
M('n', '<c-j>', '<c-w>j'),
M('n', '<c-k>', '<c-w>k'),
M('n', '<c-h>', '<c-w>h'),
M('n', '<c-l>', '<c-w>l'),
-- window resizing
M('n', '<Up>', '<cmd>resize +1<cr>'),
M('n', '<Down>', '<cmd>resize -1<cr>'),
M('n', '<Left>', '<cmd>vertical resize -1<cr>'),
M('n', '<Right>', '<cmd>vertical resize +1<cr>'),
-- window resizing
M('n', '<Up>', '<cmd>resize +1<cr>'),
M('n', '<Down>', '<cmd>resize -1<cr>'),
M('n', '<Left>', '<cmd>vertical resize -1<cr>'),
M('n', '<Right>', '<cmd>vertical resize +1<cr>'),
-- easier tab navigation
M('n', '<c-n>', ':tabprevious<cr>').silent(),
M('n', '<c-m>', ':tabnext<cr>' ).silent(),
-- easier tab navigation
M('n', '<c-n>', ':tabprevious<cr>').silent(),
M('n', '<c-m>', ':tabnext<cr>' ).silent(),
-- move lines up and down
M('n', '<A-j>', [[:move .+1<cr>==]] ).silent(),
M('n', '<A-k>', [[:move .-2<cr>==]] ).silent(),
M('v', '<A-j>', [[:move '>+1<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-k>', [[<esc>:move .-2<cr>==gi]] ).silent(),
-- move lines up and down
M('n', '<A-j>', [[:move .+1<cr>==]] ).silent(),
M('n', '<A-k>', [[:move .-2<cr>==]] ).silent(),
M('v', '<A-j>', [[:move '>+1<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-k>', [[<esc>:move .-2<cr>==gi]] ).silent(),
-- cycle through line numbering modes
M('n', '<leader>ln', ':set nonumber norelativenumber<CR>' ).silent(),
M('n', '<leader>ll', ':set number norelativenumber<CR>' ).silent(),
M('n', '<leader>lr', ':set number relativenumber<CR>' ).silent(),
-- cycle through line numbering modes
M('n', '<leader>ln', ':set nonumber norelativenumber<CR>' ).silent(),
M('n', '<leader>ll', ':set number norelativenumber<CR>' ).silent(),
M('n', '<leader>lr', ':set number relativenumber<CR>' ).silent(),
-- show list of buffers and prepare to switch
M('n', '<leader>bf', ':ls<CR>:b<Space>'),
-- show list of buffers and prepare to switch
M('n', '<leader>bf', ':ls<CR>:b<Space>'),
-- quickly change background
M('n', '<leader>bg', [[:let &background = &background ==? 'light' ? 'dark' : 'light'<cr>]]),
-- quickly change background
M('n', '<leader>bg', [[:let &background = &background ==? 'light' ? 'dark' : 'light'<cr>]]),
-- use fugitive
M('n', '<leader>gg', ':G<cr>'),
M('n', '<leader>g<space>', ':G '),
-- use fugitive
M('n', '<leader>gg', ':G<cr>'),
M('n', '<leader>g<space>', ':G '),
-- disable highlight until next search
M('n', '<leader>h', ':nohlsearch<cr>'),
-- disable highlight until next search
M('n', '<leader>h', ':nohlsearch<cr>'),
-- toggle NERDTree
M('n', '<leader>n', ':NERDTreeToggle<cr>'),
-- toggle NERDTree
M('n', '<leader>n', ':NERDTreeToggle<cr>'),
-- toggle rainbow parens
M('n', '<leader>p', ':RainbowParentheses!!<cr>'),
-- toggle rainbow parens
M('n', '<leader>p', ':RainbowParentheses!!<cr>'),
-- edit init.lua
M('n', '<leader>v', ':e $MYVIMRC<cr>'),
-- edit init.lua
M('n', '<leader>v', ':e $MYVIMRC<cr>'),
-- fix whitespace
M('n', '<leader>w', ':FixWhitespace<cr>'),
-- fix whitespace
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"]])
local set_options = function(options)
local opt = vim.opt
for k, v in pairs(options) do
opt[k] = v
end
local opt = vim.opt
for k, v in pairs(options) do
opt[k] = v
end
end
set_options {
-- General
belloff = 'all', -- never ring bells
hidden = true, -- hide abandoned buffers
clipboard = 'unnamedplus', -- synchronize with system clipboard
lazyredraw = true, -- don't redraw screen during macros
modelines = 0, -- never use modelines
fileformats = 'unix,mac,dos', -- prioritize unix <EOL> format
pastetoggle = '<F20>', -- toggle paste with P on Moonlander
-- General
belloff = 'all', -- never ring bells
hidden = true, -- hide abandoned buffers
clipboard = 'unnamedplus', -- synchronize with system clipboard
lazyredraw = true, -- don't redraw screen during macros
modelines = 0, -- never use modelines
fileformats = 'unix,mac,dos', -- prioritize unix <EOL> format
pastetoggle = '<F20>', -- toggle paste with P on Moonlander
swapfile = false, -- don't use swap files
writebackup = true, -- Make a backup before writing a file...
backup = false, -- ...but don't keep it around.
swapfile = false, -- don't use swap files
writebackup = true, -- Make a backup before writing a file...
backup = false, -- ...but don't keep it around.
shortmess = vim.opt.shortmess + 'I', -- no intro message when starting Vim
shada = {
"'1000", -- remember marks for this many files
"/1000", -- remember this many search patterns
":1000", -- remember this many command line items
"<100", -- maximum number of lines to remember per register
"h", -- disable 'hlsearch' while reading shada file
"s100", -- limit size of remembered items to this many KiB
},
shortmess = vim.opt.shortmess + 'I', -- no intro message when starting Vim
shada = {
"'1000", -- remember marks for this many files
"/1000", -- remember this many search patterns
":1000", -- remember this many command line items
"<100", -- maximum number of lines to remember per register
"h", -- disable 'hlsearch' while reading shada file
"s100", -- limit size of remembered items to this many KiB
},
-- Searching
ignorecase = true, -- Ignore case when searching...
smartcase = true, -- ...unless pattern contains uppercase characters.
-- Searching
ignorecase = true, -- Ignore case when searching...
smartcase = true, -- ...unless pattern contains uppercase characters.
-- Editing
expandtab = true, -- use spaces whe <Tab> is inserted
tabstop = 4, -- tabs are 4 spaces
shiftwidth = 0, -- (auto)indent using 'tabstop' spaces
smartindent = true, -- use smart autoindenting
inccommand = 'split', -- preview command partial results
joinspaces = false, -- use one space after a period whe joining lines
showmatch = true, -- briefly jump to matching bracket if insert one
virtualedit = 'block', -- position the cursor anywhere in Visual Block mode
formatlistpat = [[^\s*\(\d\+[\]:.)}\t ]\|[-+*]\|[\[(][ x][\])]\)\s*]],
formatoptions = vim.opt.formatoptions
- 't' -- Don't auto-wrap on 'textwidth'...
+ 'c' -- ...but do it within comment blocks...
+ 'l' -- ...but not if line was already long before entering Insert mode.
+ 'r' -- Insert comment leader when pressing Enter...
- 'o' -- ...but not when opening a new line with o & O.
+ 'q' -- allow formatting of comments with gq
- 'a' -- don't auto-format every time text is inserted
+ 'n' -- indent lists automatically acc. 'formatlistpat'
+ 'j' -- remove comment leader when joining lines
+ '1', -- don't break lines after a one letter word but rather before it
-- Editing
expandtab = true, -- use spaces whe <Tab> is inserted
tabstop = 4, -- tabs are 4 spaces
shiftwidth = 0, -- (auto)indent using 'tabstop' spaces
smartindent = true, -- use smart autoindenting
inccommand = 'split', -- preview command partial results
joinspaces = false, -- use one space after a period whe joining lines
showmatch = true, -- briefly jump to matching bracket if insert one
virtualedit = 'block', -- position the cursor anywhere in Visual Block mode
formatlistpat = [[^\s*\(\d\+[\]:.)}\t ]\|[-+*]\|[\[(][ x][\])]\)\s*]],
formatoptions = vim.opt.formatoptions
- 't' -- Don't auto-wrap on 'textwidth'...
+ 'c' -- ...but do it within comment blocks...
+ 'l' -- ...but not if line was already long before entering Insert mode.
+ 'r' -- Insert comment leader when pressing Enter...
- 'o' -- ...but not when opening a new line with o & O.
+ 'q' -- allow formatting of comments with gq
- 'a' -- don't auto-format every time text is inserted
+ 'n' -- indent lists automatically acc. 'formatlistpat'
+ 'j' -- remove comment leader when joining lines
+ '1', -- don't break lines after a one letter word but rather before it
-- Appearance
showmode = false, -- don't show mode (shown in statusline instead)
relativenumber = true, -- Start off with realtive line numbers...
number = true, -- ...but real number for current line.
wrap = false, -- don't wrap long lines initially
textwidth = 79, -- maximum width for text being inserted
colorcolumn = '+1', -- highlight column after 'textwidth'
cursorline = true, -- highlight the line of the cursor
showbreak = '', -- prefix for wrapped lines
scrolloff = 3, -- min. # of lines above and below cursor
sidescrolloff = 3, -- min. # of columns to left and right of cursor
list = true, -- show invisible characters
listchars = {
tab = '» ',
extends = '',
precedes = '',
trail = '·',
conceal = '',
},
-- Appearance
showmode = false, -- don't show mode (shown in statusline instead)
relativenumber = true, -- Start off with realtive line numbers...
number = true, -- ...but real number for current line.
wrap = false, -- don't wrap long lines initially
textwidth = 79, -- maximum width for text being inserted
colorcolumn = '+1', -- highlight column after 'textwidth'
cursorline = true, -- highlight the line of the cursor
showbreak = '', -- prefix for wrapped lines
scrolloff = 3, -- min. # of lines above and below cursor
sidescrolloff = 3, -- min. # of columns to left and right of cursor
list = true, -- show invisible characters
listchars = {
tab = '» ',
extends = '',
precedes = '',
trail = '·',
conceal = '',
},
-- Wildcard Expansion
wildignore = {
'.git',
'.svn',
'__pycache__',
'**/tmp/**',
'*.DS_Store',
'*.dll',
'*.egg-info',
'*.exe',
'*.gif',
'*.jpeg',
'*.jpg',
'*.o',
'*.obj',
'*.out',
'*.png',
'*.pyc',
'*.so',
'*.zip',
'*~',
},
wildignorecase = true, -- ignore case when completing file names
wildmode = 'longest:full', -- longest common prefix first, then wildmenu
-- Wildcard Expansion
wildignore = {
'.git',
'.svn',
'__pycache__',
'**/tmp/**',
'*.DS_Store',
'*.dll',
'*.egg-info',
'*.exe',
'*.gif',
'*.jpeg',
'*.jpg',
'*.o',
'*.obj',
'*.out',
'*.png',
'*.pyc',
'*.so',
'*.zip',
'*~',
},
wildignorecase = true, -- ignore case when completing file names
wildmode = 'longest:full', -- longest common prefix first, then wildmenu
-- Window Splitting
splitbelow = true, -- :split below current window
splitright = true, -- :vsplit to the right of current window
equalalways = false, -- don't resize all windows when splitting
-- Window Splitting
splitbelow = true, -- :split below current window
splitright = true, -- :vsplit to the right of current window
equalalways = false, -- don't resize all windows when splitting
-- Folding
foldenable = true, -- enable folding
foldlevelstart = 100, -- start with all folds open
foldmethod = 'syntax', -- fold based on syntax by default
foldnestmax = 10, -- limit nested folds to 10 levels
-- Folding
foldenable = true, -- enable folding
foldlevelstart = 100, -- start with all folds open
foldmethod = 'syntax', -- fold based on syntax by default
foldnestmax = 10, -- limit nested folds to 10 levels
-- Options for diff mode
diffopt = { -- better side-by-side diffs
'filler', -- show filler lines (so text ins vertically synced)
'vertical', -- use vertical splits (files side-by-side)
'closeoff', -- disable diff mode when one window is closed
},
-- Options for diff mode
diffopt = { -- better side-by-side diffs
'filler', -- show filler lines (so text ins vertically synced)
'vertical', -- use vertical splits (files side-by-side)
'closeoff', -- disable diff mode when one window is closed
},
}