ref nvim
This commit is contained in:
parent
9337889968
commit
05f6385865
@ -80,9 +80,6 @@ echo "Hello $USER!"
|
||||
| <kbd>,rr</kbd> | Run script in new tab (python, go, preview markdown)|
|
||||
| <kbd>,rm</kbd> | Run script (make run) |
|
||||
| <kbd>,rf</kbd> | Format file (go) |
|
||||
| <kbd>,nn</kbd> | Toggle NerdTree |
|
||||
| <kbd>,nf</kbd> | Toggle NerdTree focus |
|
||||
| <kbd>,ve</kbd> | Open ~/.vimrc or ~/.config/nvim/init.vim in new tab |
|
||||
|
||||
|
||||
<a id="chapter-1"></a>
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
require("base.options")
|
||||
require("base.maps")
|
||||
require("base.keys")
|
||||
require("base.plugins")
|
||||
|
||||
2
sub/nvim/lua/base/keys/init.lua
Normal file
2
sub/nvim/lua/base/keys/init.lua
Normal file
@ -0,0 +1,2 @@
|
||||
require("base.keys.keys")
|
||||
require("base.keys.run-scripts")
|
||||
97
sub/nvim/lua/base/keys/keys.lua
Normal file
97
sub/nvim/lua/base/keys/keys.lua
Normal file
@ -0,0 +1,97 @@
|
||||
local map = vim.keymap.set
|
||||
local opts = { noremap = true, silent = true }
|
||||
|
||||
|
||||
vim.g.mapleader = ','
|
||||
|
||||
|
||||
function create_function_tabdo(command)
|
||||
return function()
|
||||
local curr_tab = vim.fn.tabpagenr()
|
||||
vim.cmd.tabdo(command)
|
||||
vim.cmd.tabn(curr_tab)
|
||||
end
|
||||
end
|
||||
|
||||
-- Toggle line highlighting
|
||||
map('n', '<Leader>c', create_function_tabdo('set cursorline!'), opts)
|
||||
|
||||
map('n', '<Leader>/',
|
||||
function() vim.opt.hlsearch = not vim.opt.hlsearch["_value"] end,
|
||||
opts)
|
||||
|
||||
map('i', 'jk', '<ESC>', opts)
|
||||
map('i', 'ол', '<ESC>', opts)
|
||||
|
||||
|
||||
-- x to blackhole
|
||||
map('n', 'x', '"_x', opts)
|
||||
|
||||
-- Increment/decrement
|
||||
map('n', '+', '<C-a>', opts)
|
||||
map('n', '-', '<C-x>', opts)
|
||||
|
||||
-- map \ to prev finding
|
||||
map({"n", "v"}, [[\]], ',', opts)
|
||||
|
||||
-- Select all
|
||||
map('n', '<C-a>', 'gg<S-v>G', opts)
|
||||
|
||||
|
||||
-- Scroll tabs
|
||||
map("n", '<C-l>', vim.cmd.tabnext, opts)
|
||||
map("n", '<C-h>', vim.cmd.tabprev, opts)
|
||||
|
||||
|
||||
-- Kill current buffer
|
||||
map("n", '<Leader>qq', ':bd!<CR>', opts)
|
||||
-- Quick exit without saving
|
||||
map("n", '<Leader>qa', ':qa!<CR>', opts)
|
||||
|
||||
|
||||
map("n", '<Leader>eh', ':set list!<CR>', opts)
|
||||
vim.opt.listchars=[[tab:→\ ,eol:↵,trail:·,extends:↷,precedes:↶]]
|
||||
|
||||
|
||||
-- Tags panel (ctags required)
|
||||
map("n", '<Leader>t', ':TagbarToggle<CR>', opts)
|
||||
|
||||
|
||||
-- Telescope
|
||||
map("n", '<Leader>ff', '<cmd>Telescope find_files<CR>', opts)
|
||||
map("n", '<Leader>fg', '<cmd>Telescope live_grep<CR>', opts)
|
||||
|
||||
|
||||
-- Expand %% to dirname of current file in command line
|
||||
map("c", '%%', [[getcmdtype() == ':' ? expand('%:h').'/' : '%%']], {expr = true})
|
||||
|
||||
|
||||
-- Save from root
|
||||
vim.api.nvim_create_user_command('Sw', [[execute 'silent! write !SUDO_ASKPASS=$(which vim_askpass_helper) sudo -A tee % >/dev/null']], {})
|
||||
|
||||
|
||||
|
||||
-- Toggle line number style
|
||||
function toggle_number_style()
|
||||
|
||||
local opt = vim.opt
|
||||
local number = opt.number["_value"]
|
||||
local relativenumber = opt.relativenumber["_value"]
|
||||
|
||||
if (not number) and (not relativenumber) then
|
||||
opt.number = true
|
||||
opt.relativenumber = false
|
||||
elseif (number) and (not relativenumber) then
|
||||
opt.number = false
|
||||
opt.relativenumber = true
|
||||
elseif (not number) and (relativenumber) then
|
||||
opt.number = true
|
||||
opt.relativenumber = true
|
||||
elseif (number) and (relativenumber) then
|
||||
opt.number = false
|
||||
opt.relativenumber = false
|
||||
end
|
||||
end
|
||||
|
||||
-- Toggle line number style
|
||||
map('n', '<Leader>l', create_function_tabdo('lua toggle_number_style()'), opts)
|
||||
59
sub/nvim/lua/base/keys/run-scripts.lua
Normal file
59
sub/nvim/lua/base/keys/run-scripts.lua
Normal file
@ -0,0 +1,59 @@
|
||||
|
||||
function autocmd(func)
|
||||
local create_autocmd = vim.api.nvim_create_autocmd
|
||||
|
||||
create_autocmd("BufEnter",
|
||||
{ pattern = '*', callback = func}
|
||||
)
|
||||
end
|
||||
|
||||
function set_keymap_base(key, cmd)
|
||||
local map = vim.keymap.set
|
||||
keymap_keys = string.format([[<Leader>r%s]], key)
|
||||
map("n", keymap_keys, cmd, opts)
|
||||
end
|
||||
|
||||
function set_keymap_format_file(cmd)
|
||||
local cmd_string = string.format([[:!%s %% <CR>]], cmd)
|
||||
set_keymap_base("f", cmd_string)
|
||||
end
|
||||
|
||||
function set_keymap_run_script(cmd)
|
||||
local cmd_string = string.format([[:tabnew %% <CR> :terminal %s %% <CR> :set nocursorline number norelativenumber <CR> G <CR>]], cmd)
|
||||
set_keymap_base("r", cmd_string)
|
||||
end
|
||||
|
||||
function create_function_autocmd_filetype(set_keymap_func, ft, cmd)
|
||||
return function()
|
||||
if vim.bo.filetype == ft then
|
||||
set_keymap_func(cmd)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function create_function_autocmd_filename(set_keymap_func, fn, cmd)
|
||||
return function()
|
||||
if vim.fn.expand('%:t') == fn then
|
||||
set_keymap_func(cmd)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function autocmd_run_script_filetype(ft, cmd)
|
||||
autocmd(create_function_autocmd_filetype(set_keymap_run_script, ft, cmd))
|
||||
end
|
||||
|
||||
function autocmd_format_file_by_filetype(ft, cmd)
|
||||
autocmd(create_function_autocmd_filetype(set_keymap_format_file, ft, cmd))
|
||||
end
|
||||
|
||||
|
||||
autocmd_run_script_filetype('python', 'python3')
|
||||
autocmd_run_script_filetype('go', 'go run')
|
||||
autocmd_run_script_filetype('rust', 'cargo run')
|
||||
autocmd_run_script_filetype('markdown', 'glow')
|
||||
|
||||
autocmd(create_function_autocmd_filename(set_keymap_run_script, 'manpage', 'man -P cat -l'))
|
||||
|
||||
autocmd_format_file_by_filetype('rust', 'cargo fmt -p')
|
||||
autocmd_format_file_by_filetype('go', 'go fmt')
|
||||
@ -1,141 +0,0 @@
|
||||
local keymap = vim.keymap
|
||||
|
||||
|
||||
vim.g.mapleader = ','
|
||||
|
||||
local opts = { noremap = true, silent = true }
|
||||
|
||||
function create_function_tabdo(command)
|
||||
return function()
|
||||
local curr_tab = vim.fn.tabpagenr()
|
||||
vim.cmd.tabdo(command)
|
||||
vim.cmd.tabn(curr_tab)
|
||||
end
|
||||
end
|
||||
|
||||
-- Toggle line highlighting
|
||||
vim.opt.cursorline = true
|
||||
keymap.set('n', '<Leader>c', create_function_tabdo('set cursorline!'), opts)
|
||||
|
||||
keymap.set('n', '<Leader>/',
|
||||
function() vim.opt.hlsearch = not vim.opt.hlsearch["_value"] end,
|
||||
opts)
|
||||
|
||||
keymap.set('i', 'jk', '<ESC>', opts)
|
||||
keymap.set('i', 'ол', '<ESC>', opts)
|
||||
|
||||
|
||||
-- x to blackhole
|
||||
keymap.set('n', 'x', '"_x', opts)
|
||||
|
||||
-- Increment/decrement
|
||||
keymap.set('n', '+', '<C-a>', opts)
|
||||
keymap.set('n', '-', '<C-x>', opts)
|
||||
|
||||
-- map \ to prev finding
|
||||
keymap.set({"n", "v"}, [[\]], ',', opts)
|
||||
|
||||
-- Select all
|
||||
keymap.set('n', '<C-a>', 'gg<S-v>G', opts)
|
||||
|
||||
|
||||
-- Scroll tabs
|
||||
keymap.set("n", '<C-l>', vim.cmd.tabnext, opts)
|
||||
keymap.set("n", '<C-h>', vim.cmd.tabprev, opts)
|
||||
|
||||
|
||||
-- Kill current buffer
|
||||
keymap.set("n", '<Leader>qq', ':bd!<CR>', opts)
|
||||
-- Quick exit without saving
|
||||
keymap.set("n", '<Leader>qa', ':qa!<CR>', opts)
|
||||
|
||||
|
||||
keymap.set("n", '<Leader>eh', ':set list!<CR>', opts)
|
||||
vim.opt.listchars=[[tab:→\ ,eol:↵,trail:·,extends:↷,precedes:↶]]
|
||||
|
||||
|
||||
-- Tags panel (ctags required)
|
||||
keymap.set("n", '<Leader>t', ':TagbarToggle<CR>', opts)
|
||||
|
||||
|
||||
-- Telescope
|
||||
keymap.set("n", '<Leader>ff', '<cmd>Telescope find_files<CR>', opts)
|
||||
keymap.set("n", '<Leader>fg', '<cmd>Telescope live_grep<CR>', opts)
|
||||
|
||||
|
||||
-- Expand %% to dirname of current file in command line
|
||||
keymap.set("c", '%%', [[getcmdtype() == ':' ? expand('%:h').'/' : '%%']], {expr = true})
|
||||
|
||||
|
||||
-- Save from root
|
||||
vim.api.nvim_create_user_command('Sw', [[execute 'silent! write !SUDO_ASKPASS=$(which vim_askpass_helper) sudo -A tee % >/dev/null']], {})
|
||||
|
||||
|
||||
|
||||
function create_autocmd_filetype(func)
|
||||
local create_autocmd = vim.api.nvim_create_autocmd
|
||||
|
||||
create_autocmd("BufEnter",
|
||||
{ pattern = '*', callback = func}
|
||||
)
|
||||
end
|
||||
|
||||
function set_keymap_run_script(cmd)
|
||||
local cmd_string = string.format([[:tabnew %% <CR> :terminal %s %% <CR> :set nocursorline number norelativenumber <CR> G <CR>]], cmd)
|
||||
keymap.set("n", "<Leader>rr", cmd_string, opts)
|
||||
end
|
||||
|
||||
function create_function_create_autocmd_filetype(ft, cmd)
|
||||
return function()
|
||||
if vim.bo.filetype == ft then
|
||||
set_keymap_run_script(cmd)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function create_function_create_autocmd_filename(fn, cmd)
|
||||
return function()
|
||||
if vim.fn.expand('%:t') == fn then
|
||||
set_keymap_run_script(cmd)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- Run current file by type
|
||||
create_autocmd_filetype(create_function_create_autocmd_filetype('python', 'python3'))
|
||||
create_autocmd_filetype(create_function_create_autocmd_filetype('go', 'go run'))
|
||||
create_autocmd_filetype(create_function_create_autocmd_filetype('rust', 'cargo run'))
|
||||
create_autocmd_filetype(create_function_create_autocmd_filetype('markdown', 'glow'))
|
||||
|
||||
create_autocmd_filetype(create_function_create_autocmd_filename('manpage', 'man -P cat -l'))
|
||||
|
||||
|
||||
|
||||
-- Toggle line number style
|
||||
vim.opt.number = true
|
||||
vim.opt.relativenumber = true
|
||||
|
||||
|
||||
function toggle_number_style()
|
||||
|
||||
local number = vim.opt.number["_value"]
|
||||
local relativenumber = vim.opt.relativenumber["_value"]
|
||||
|
||||
if (not number) and (not relativenumber) then
|
||||
vim.opt.number = true
|
||||
vim.opt.relativenumber = false
|
||||
elseif (number) and (not relativenumber) then
|
||||
vim.opt.number = false
|
||||
vim.opt.relativenumber = true
|
||||
elseif (not number) and (relativenumber) then
|
||||
vim.opt.number = true
|
||||
vim.opt.relativenumber = true
|
||||
elseif (number) and (relativenumber) then
|
||||
vim.opt.number = false
|
||||
vim.opt.relativenumber = false
|
||||
end
|
||||
end
|
||||
|
||||
-- Toggle line number style
|
||||
keymap.set('n', '<Leader>l', create_function_tabdo('lua toggle_number_style()'), opts)
|
||||
@ -1,64 +1,74 @@
|
||||
local opt = vim.opt
|
||||
|
||||
vim.opt.ruler = true
|
||||
opt.ruler = true
|
||||
opt.encoding = 'utf-8'
|
||||
opt.fileencoding = 'utf-8'
|
||||
|
||||
opt.number = true
|
||||
opt.relativenumber = true
|
||||
|
||||
opt.clipboard:append { 'unnamedplus' }
|
||||
opt.shell = 'bash'
|
||||
|
||||
opt.ttimeoutlen = 0
|
||||
|
||||
vim.cmd([[
|
||||
filetype plugin indent on
|
||||
]])
|
||||
|
||||
vim.cmd([[
|
||||
syntax enable
|
||||
]])
|
||||
|
||||
opt.compatible = false
|
||||
|
||||
opt.hidden = true
|
||||
|
||||
opt.expandtab = true
|
||||
opt.smarttab = true
|
||||
opt.tabstop = 4
|
||||
|
||||
|
||||
vim.scriptencoding = 'utf-8'
|
||||
vim.opt.encoding = 'utf-8'
|
||||
vim.opt.fileencoding = 'utf-8'
|
||||
opt.cursorline = true
|
||||
opt.softtabstop = 4
|
||||
opt.shiftwidth = 4
|
||||
opt.autoindent = true
|
||||
opt.smartindent = true
|
||||
opt.wrap = false
|
||||
|
||||
vim.opt.clipboard:append { 'unnamedplus' }
|
||||
vim.opt.shell = 'bash'
|
||||
|
||||
vim.opt.ttimeoutlen = 0
|
||||
|
||||
vim.opt.compatible = false
|
||||
|
||||
vim.opt.hidden = true
|
||||
|
||||
vim.opt.expandtab = true
|
||||
vim.opt.smarttab = true
|
||||
vim.opt.tabstop = 4
|
||||
opt.ttyfast = true
|
||||
opt.autoread = true
|
||||
|
||||
|
||||
vim.opt.softtabstop = 4
|
||||
vim.opt.shiftwidth = 4
|
||||
vim.opt.autoindent = true
|
||||
vim.opt.smartindent = true
|
||||
vim.opt.wrap = false
|
||||
opt.errorbells = false
|
||||
opt.visualbell = false
|
||||
opt.showcmd = true
|
||||
opt.showtabline = 2
|
||||
|
||||
vim.opt.ttyfast = true
|
||||
vim.opt.autoread = true
|
||||
opt.smartcase = true -- if search line hasn`t Upper case chars - ignore case search, else case-sensivity search
|
||||
opt.incsearch = true
|
||||
|
||||
opt.mousehide = true
|
||||
opt.mouse = 'a'
|
||||
|
||||
opt.colorcolumn = '81'
|
||||
opt.scrolloff = 7
|
||||
|
||||
|
||||
vim.opt.errorbells = false
|
||||
vim.opt.visualbell = false
|
||||
vim.opt.showcmd = true
|
||||
vim.opt.showtabline = 2
|
||||
opt.termguicolors = true
|
||||
opt.background = 'dark'
|
||||
|
||||
vim.opt.smartcase = true -- if search line hasn`t Upper case chars - ignore case search, else case-sensivity search
|
||||
vim.opt.incsearch = true
|
||||
|
||||
vim.opt.mousehide = true
|
||||
vim.opt.mouse = 'a'
|
||||
|
||||
vim.opt.colorcolumn = '81'
|
||||
vim.opt.scrolloff = 7
|
||||
|
||||
|
||||
vim.opt.termguicolors = true
|
||||
vim.opt.background = 'dark'
|
||||
|
||||
vim.opt.backup = true
|
||||
vim.opt.swapfile = false
|
||||
vim.opt.undofile = true
|
||||
vim.opt.history = 1000
|
||||
vim.opt.undoreload = 1000
|
||||
opt.backup = true
|
||||
opt.swapfile = false
|
||||
opt.undofile = true
|
||||
opt.history = 1000
|
||||
opt.undoreload = 1000
|
||||
|
||||
local prefix = vim.fn.expand("~/.cache/nvim/tmp")
|
||||
|
||||
vim.opt.undodir = { prefix .. "/undo//" }
|
||||
vim.opt.backupdir = { prefix .. "/backup//" }
|
||||
vim.opt.directory = { prefix .. "/swp//" }
|
||||
opt.undodir = { prefix .. "/undo//" }
|
||||
opt.backupdir = { prefix .. "/backup//" }
|
||||
opt.directory = { prefix .. "/swp//" }
|
||||
|
||||
|
||||
function makeDirIfNoExists(path)
|
||||
@ -69,13 +79,13 @@ function makeDirIfNoExists(path)
|
||||
end
|
||||
|
||||
-- make this dirs if no exists previously
|
||||
makeDirIfNoExists(vim.opt.undodir)
|
||||
makeDirIfNoExists(vim.opt.backupdir)
|
||||
makeDirIfNoExists(vim.opt.directory)
|
||||
makeDirIfNoExists(opt.undodir)
|
||||
makeDirIfNoExists(opt.backupdir)
|
||||
makeDirIfNoExists(opt.directory)
|
||||
|
||||
vim.opt.ffs = 'unix,mac'
|
||||
opt.ffs = 'unix,mac'
|
||||
|
||||
vim.opt.path:append { '**' } -- Finding files - Search down into subfolders
|
||||
opt.path:append { '**' } -- Finding files - Search down into subfolders
|
||||
|
||||
|
||||
vim.cmd([[
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user