nix/prog/nvim: move basic config to lua

This commit is contained in:
Dmitriy Pleshevskiy 2022-08-18 23:41:55 +03:00
parent 8cabd90732
commit 0909b2fbac
Signed by: pleshevskiy
GPG key ID: 1B59187B161C0215
4 changed files with 186 additions and 156 deletions

View file

@ -1,16 +1 @@
-- TreeSitter print('hello from basic.lua)
require'nvim-treesitter.configs'.setup {
-- A list of parser names, or "all"
-- ensure_installed = { "nix", "typescript", "tsx" },
-- Install parsers synchronously (only applied to `ensure_installed`)
-- sync_install = false,
highlight = {
enable = true,
},
indent = {
enable = true,
},
}

View file

@ -1,83 +1,4 @@
" Basic settings lua require('basic')
filetype off
" Leaders
let g:mapleader = ','
let g:maplocalleader = '-'
" Better Unix support
set viewoptions=folds,options,cursor,unix,slash
set encoding=utf-8
" True color support
set termguicolors
" Theme (required plugin 'material-vim')
"let g:material_theme_style = 'default' | 'palenight' | 'ocean' | 'lighter' |
" 'darker' | 'default-community' | 'palenight-community' | 'ocean-community' |
" 'lighter-community' | 'darker-community'
let g:material_theme_style = 'default'
let g:lightline = { 'colorscheme': 'material_vim' }
colorscheme material
" Other options
syntax on
set backspace=2
set laststatus=2
set noshowmode
" Tabs as spaces
set expandtab
set tabstop=2
set softtabstop=2
set shiftwidth=2
" Clear search highlighting
nnoremap <C-z> :nohlsearch<CR>
" Fixes broken cursor on Linux
set guicursor=
" General editor options
set hidden " Hide files when leaving them.
set number " Show line numbers.
set numberwidth=1 " Minimum line number column width.
set cmdheight=2 " Number of screen lines to use for the commandline.
set textwidth=0 " Lines length limit (0 if no limit).
set linebreak " Don't cut lines in the middle of a work.
set showmatch " Show matching parenthesis.
set matchtime=2 " Time during which the matching parenthesis is shown.
set formatoptions=jtcrq " Sensible default line auto cutting and formatting.
set clipboard=unnamedplus " Copy/Past to/from clipboard
set cursorline " Highlight line cursor is currently on
set completeopt+=noinsert " Select the first item of popup menu automatically without inserting it
set listchars=tab:→\ ,trail:~,nbsp:␣,eol" Invisible characters representation when :set list.
" Search
set incsearch " Incremental search.
set ignorecase " Case insensitive.
set smartcase " Case insensitive if no uppercase letter in pattern, case sensitive otherwise
" Set up a line limiter for each lang
aug line_limiter
au!
au BufNewFile,BufRead *.nix setlocal colorcolumn=101
au BufNewFile,BufRead *.vim setlocal colorcolumn=101
au BufNewFile,BufRead *.ts,*.tsx setlocal colorcolumn=101
au BufNewFile,BufRead *.js,*.jsx setlocal colorcolumn=101
au BufNewFile,BufRead *.rs setlocal colorcolumn=101
au BufNewFile,BufRead *.json setlocal colorcolumn=81
au BufNewFile,BufRead *.yml,*.yaml setlocal colorcolumn=81
au BufNewFile,BufRead *.md setlocal colorcolumn=81
au BufNewFile,BufRead *.html setlocal colorcolumn=81
" TODO: add limiter for haskell
aug END
" Spell check for markdown files
aug spell_check
au!
au BufNewFile,BufRead *.md setlocal spell
aug END
" Set up folding " Set up folding
aug folding aug folding
@ -86,59 +7,3 @@ aug folding
au BufNewFile,BufRead *.ts,*.tsx syntax on | setlocal foldmethod=syntax au BufNewFile,BufRead *.ts,*.tsx syntax on | setlocal foldmethod=syntax
aug END aug END
" Enable fast navigation between windows
nnoremap <C-h> <C-W>h
nnoremap <C-l> <C-W>l
nnoremap <C-j> <C-W>j
nnoremap <C-k> <C-W>k
" Disable the annoying and useless ex-mode
nnoremap Q <nop>
nnoremap gQ <nop>
" Disable arrow keys
noremap <Up> <nop>
noremap <Down> <nop>
noremap <Left> <nop>
noremap <Right> <nop>
vnoremap <Up> <nop>
vnoremap <Down> <nop>
vnoremap <Left> <nop>
vnoremap <Right> <nop>
"... instead of insert mode for rus lang
"inoremap <Up> <nop>
"inoremap <Down> <nop>
"inoremap <Left> <nop>
"inoremap <Right> <nop>
" Disable page up / down
noremap <PageUp> <nop>
noremap <PageDown> <nop>
inoremap <PageUp> <nop>
inoremap <PageDown> <nop>
vnoremap <PageUp> <nop>
vnoremap <PageDown> <nop>
" Disable mouse / touchpad (only in vim)
set mouse=
inoremap <ScrollWheelUp> <nop>
inoremap <S-ScrollWheelUp> <nop>
inoremap <C-ScrollWheelUp> <nop>
inoremap <ScrollWheelDown> <nop>
inoremap <S-ScrollWheelDown> <nop>
inoremap <C-ScrollWheelDown> <nop>
inoremap <ScrollWheelLeft> <nop>
inoremap <S-ScrollWheelLeft> <nop>
inoremap <C-ScrollWheelLeft> <nop>
inoremap <ScrollWheelRight> <nop>
inoremap <S-ScrollWheelRight> <nop>
inoremap <C-ScrollWheelRight> <nop>
" Incremental substitutin
set inccommand=split
" Misc
nnoremap <leader>sv :source $MYVIMRC<CR>
cabbrev bsp belowright split
cabbrev rvsp belowright vsplit

View file

@ -45,10 +45,6 @@ let
cocSettings = builtins.toJSON (import ./coc_settings.nix); cocSettings = builtins.toJSON (import ./coc_settings.nix);
vimConfig = baseConfig + pluginsConfig + cocConfig; vimConfig = baseConfig + pluginsConfig + cocConfig;
# I get an error if I try copying lua script to lua folder
# TODO: think about this solution
luaConfig = builtins.readFile ./config.lua;
in in
{ {
options.progs.nvim = { options.progs.nvim = {
@ -77,6 +73,7 @@ in
}; };
xdg.configFile = { xdg.configFile = {
"nvim/lua".source = ./lua;
"nvim/coc-settings.json".text = cocSettings; "nvim/coc-settings.json".text = cocSettings;
}; };

View file

@ -0,0 +1,183 @@
-------------------------------------------------------------------------------
--
-- Basic Settings
--
vim.cmd 'filetype off'
-- Leaders
vim.g.mapleader = ','
vim.g.maplocalleader = '-'
-- Better Unix support
vim.opt.viewoptions = {'folds', 'options', 'cursor', 'unix', 'slash'}
vim.opt.encoding = 'utf-8'
-- True color support
vim.opt.termguicolors = true
-- Theme (required plugin 'material-vim')
-- Available styles: default, planight, ocean, lighter
-- darker, default-community, palenight-community, ocean-community,
-- lighter-community, darker-community
vim.g.material_theme_style = 'default'
vim.g.lightline = { colorscheme = 'material_vim' }
vim.cmd 'colorscheme material'
-- Other options
vim.cmd 'syntax on'
vim.opt.backspace = {'indent', 'eol', 'start'}
vim.opt.laststatus = 2
vim.opt.showmode = false
-- Tabs as spaces
vim.opt.expandtab = true
vim.opt.tabstop = 2
vim.opt.softtabstop = 2
vim.opt.shiftwidth = 2
-- Fixes broken cursor on Linux
vim.opt.guicursor = ''
-- Disable mouse / touchpad
vim.opt.mouse = ''
-- Incremental substitutin
vim.opt.inccommand = 'split'
-------------------------------------------------------------------------------
--
-- General editor options
--
-- Hide files when leaving them.
vim.opt.hidden = true
-- Show line numbers.
vim.opt.number = true
-- Minimum line number column width.
vim.opt.numberwidth = 1
-- Number of screen lines to use for the commandline.
vim.opt.cmdheight = 2
-- Lines length limit (0 if no limit).
vim.opt.textwidth = 0
-- Don't cut lines in the middle of a work.
vim.opt.linebreak = true
-- Show matching parenthesis.
vim.opt.showmatch = true
-- Time during which the matching parenthesis is shown.
vim.opt.matchtime = 2
-- Sensible default line auto cutting and formatting.
vim.opt.formatoptions = 'jtcrq'
-- Copy/Past to/from clipboard.
vim.opt.clipboard = 'unnamedplus'
-- Highlight line cursor is currently on.
vim.opt.cursorline = true
-- Select the first item of popup menu automatically without inserting it.
vim.opt.completeopt:append('noinsert')
-- Invisible characters representation when :set list
vim.opt.listchars = {
tab = '',
trail = '~',
nbsp = '',
eol = '¬',
}
-- Search
-- Incremental search.
vim.opt.incsearch = true
-- Case insensitive.
vim.opt.ignorecase = true
-- Case insensitive if no uppercase letter in pattern, case sensitive otherwise.
vim.opt.smartcase = true
-- Spell
vim.opt.spelllang = 'en,ru'
-------------------------------------------------------------------------------
--
-- File type specified
--
local bufReadFile = {'BufNewFile', 'BufRead'}
-- Set up a line limiter for each lang
local line_limiter_augroup = vim.api.nvim_create_augroup('line_limiter', {})
local function set_line_limiter(pattern, limit)
vim.api.nvim_create_autocmd(bufReadFile, {
pattern = pattern,
group = line_limiter_augroup,
callback = function () vim.wo.colorcolumn = limit end,
})
end
set_line_limiter('*.nix', '101')
set_line_limiter('*.vim', '101')
set_line_limiter('*.lua', '101')
set_line_limiter('*.ts,*.tsx', '101')
set_line_limiter('*.js.*.jsx', '101')
set_line_limiter('*.rs', '101')
set_line_limiter('*.json', '81')
set_line_limiter('*.yml','*.yaml', '81')
set_line_limiter('*.md', '81')
set_line_limiter('*.html', '81')
set_line_limiter('*.css', '81')
-- TODO: add line limiter for haskell
-- Spell check for markdown files
local spell_check_augroup = vim.api.nvim_create_augroup('spell_check', {})
local function enable_spell_check(pattern)
vim.api.nvim_create_autocmd(bufReadFile, {
pattern = pattern,
group = spell_check_augroup,
callback = function () vim.wo.spell = true end,
})
end
enable_spell_check '*.md'
-------------------------------------------------------------------------------
--
-- Bindings
--
local function disable_search_highlighting() vim.opt.hlsearch = false end
vim.keymap.set('n', '<C-z>', disable_search_highlighting, { desc = 'Clear search highlighting' })
-- Enable fast navigation between windows
vim.keymap.set('n', '<C-h>', '<C-W>h')
vim.keymap.set('n', '<C-l>', '<C-W>l')
vim.keymap.set('n', '<C-j>', '<C-W>j')
vim.keymap.set('n', '<C-k>', '<C-W>k')
-- Disable the annoying and useless ex-mode
vim.keymap.set('n', 'Q', '<nop>')
vim.keymap.set('n', 'gQ', '<nop>')
-- Disable arrow keys
vim.keymap.set('n', '<Up>', '<nop>')
vim.keymap.set('n', '<Down>', '<nop>')
vim.keymap.set('n', '<Left>', '<nop>')
vim.keymap.set('n', '<Right>', '<nop>')
vim.keymap.set('v', '<Up>', '<nop>')
vim.keymap.set('v', '<Down>', '<nop>')
vim.keymap.set('v', '<Left>', '<nop>')
vim.keymap.set('v', '<Right>', '<nop>')
-- ... instead of insert mode for rus lang
vim.keymap.set('i', '<Up>', '<nop>')
vim.keymap.set('i', '<Down>', '<nop>')
vim.keymap.set('i', '<Left>', '<nop>')
vim.keymap.set('i', '<Right>', '<nop>')
-- Disable page up / down
vim.keymap.set('n', '<PageUp>', '<nop>')
vim.keymap.set('n', '<PageDown>', '<nop>')
vim.keymap.set('v', '<PageUp>', '<nop>')
vim.keymap.set('v', '<PageDown>', '<nop>')
vim.keymap.set('i', '<PageUp>', '<nop>')
vim.keymap.set('i', '<PageDown>', '<nop>')
-------------------------------------------------------------------------------
--
-- Abbreviatures
--
vim.cmd 'cabbrev bsp belowright split'
vim.cmd 'cabbrev rvsp belowright vsplit'