mirror of
https://github.com/Smaug123/nix-dotfiles
synced 2025-10-16 20:08:38 +00:00
Move more stuff to Lua
This commit is contained in:
@@ -148,6 +148,11 @@
|
|||||||
in {
|
in {
|
||||||
enable = true;
|
enable = true;
|
||||||
plugins = [
|
plugins = [
|
||||||
|
{
|
||||||
|
plugin = nixpkgs.vimPlugins.which-key-nvim;
|
||||||
|
type = "lua";
|
||||||
|
config = builtins.readFile ./nvim/which-key.lua;
|
||||||
|
}
|
||||||
{
|
{
|
||||||
plugin = nixpkgs.vimPlugins.tokyonight-nvim;
|
plugin = nixpkgs.vimPlugins.tokyonight-nvim;
|
||||||
config = builtins.readFile ./nvim/tokyonight.lua;
|
config = builtins.readFile ./nvim/tokyonight.lua;
|
||||||
|
@@ -1 +1,103 @@
|
|||||||
vim.g.python3_host_prog = "%PYTHONENV%/bin/python"
|
vim.g.python3_host_prog = "%PYTHONENV%/bin/python"
|
||||||
|
vim.opt.mouse = ""
|
||||||
|
vim.opt.history = 500
|
||||||
|
vim.opt.background = "dark"
|
||||||
|
|
||||||
|
vim.opt.langmenu = "en"
|
||||||
|
|
||||||
|
-- Always show current position
|
||||||
|
vim.opt.ruler = true
|
||||||
|
vim.opt.number = true
|
||||||
|
|
||||||
|
-- A bit of extra margin to the left
|
||||||
|
vim.opt.foldcolumn = "1"
|
||||||
|
|
||||||
|
vim.opt.autoread = true
|
||||||
|
vim.opt.backup = false
|
||||||
|
vim.opt.swapfile = false
|
||||||
|
|
||||||
|
-- Use spaces instead of tabs
|
||||||
|
vim.opt.expandtab = true
|
||||||
|
vim.opt.smarttab = true
|
||||||
|
vim.opt.shiftwidth = 4
|
||||||
|
vim.opt.tabstop = 4
|
||||||
|
|
||||||
|
vim.opt.hlsearch = true
|
||||||
|
|
||||||
|
-- Don't redraw while executing macros
|
||||||
|
vim.opt.lazyredraw = true
|
||||||
|
|
||||||
|
-- Show matching brackets when text indicator is on one of them
|
||||||
|
vim.opt.showmatch = true
|
||||||
|
vim.opt.mat = 2
|
||||||
|
|
||||||
|
-- Turn off sound
|
||||||
|
vim.opt.errorbells = false
|
||||||
|
vim.opt.visualbell = false
|
||||||
|
|
||||||
|
vim.api.nvim_set_keymap('n', ';', '<Nop>', { noremap = true })
|
||||||
|
vim.api.nvim_set_var("maplocalleader", ";")
|
||||||
|
|
||||||
|
function MarkdownPreview()
|
||||||
|
local temp_file = vim.fn.tempname() .. ".md"
|
||||||
|
local file_name = vim.fn.substitute(vim.fn.tolower(vim.fn.expand('%:t')), '\\W', '_', 'g')
|
||||||
|
local temp_html = "/tmp/" .. file_name .. "_tmp.html"
|
||||||
|
|
||||||
|
-- Write the current buffer to the temp file
|
||||||
|
vim.cmd('write! ' .. temp_file)
|
||||||
|
|
||||||
|
local pandoc_cmd = 'pandoc ' .. temp_file .. ' -o ' .. temp_html
|
||||||
|
|
||||||
|
-- Execute the pandoc command
|
||||||
|
vim.fn.system(pandoc_cmd)
|
||||||
|
|
||||||
|
-- Use tmux and lynx to preview the HTML file
|
||||||
|
local lynx_cmd = 'tmux split-window -h lynx ' .. temp_html
|
||||||
|
vim.fn.jobstart(vim.split(lynx_cmd, ' '), {silent=true})
|
||||||
|
|
||||||
|
-- Delete the temp markdown file
|
||||||
|
vim.fn.delete(temp_file, 'rf')
|
||||||
|
end
|
||||||
|
|
||||||
|
function RemoveCarriageReturn()
|
||||||
|
vim.cmd("mark m")
|
||||||
|
vim.cmd("normal! Hmt")
|
||||||
|
vim.cmd("%s/\r//ge")
|
||||||
|
vim.cmd("normal! 'tzt'm")
|
||||||
|
end
|
||||||
|
|
||||||
|
function FormatJson()
|
||||||
|
local curpos = vim.api.nvim_win_get_cursor(0)
|
||||||
|
vim.cmd("%!python -m json.tool")
|
||||||
|
vim.api.nvim_win_set_cursor(0, curpos)
|
||||||
|
end
|
||||||
|
|
||||||
|
function ChangeToCurrentDirectory()
|
||||||
|
vim.cmd(":cd %:p:h")
|
||||||
|
vim.cmd(":pwd")
|
||||||
|
end
|
||||||
|
|
||||||
|
local status, whichkey = pcall(require, "which-key")
|
||||||
|
if status then
|
||||||
|
whichkey.register({
|
||||||
|
["mp"] = {
|
||||||
|
MarkdownPreview, "Preview Markdown in Lynx"
|
||||||
|
},
|
||||||
|
["md"] = {
|
||||||
|
RemoveCarriageReturns, "Delete carriage returns from file"
|
||||||
|
},
|
||||||
|
["j"] = {
|
||||||
|
FormatJson, "Auto-format JSON"
|
||||||
|
},
|
||||||
|
["cd"] = {
|
||||||
|
ChangeToCurrentDirectory, "Switch CWD to the directory of the open buffer"
|
||||||
|
}
|
||||||
|
}, { prefix = vim.api.nvim_get_var("maplocalleader") })
|
||||||
|
else
|
||||||
|
vim.api.nvim_set_keymap('n', '<localleader>mp', ':lua MarkdownPreview()<CR>', { noremap = true, silent = true })
|
||||||
|
-- Remove the Windows ^M - when the encodings gets messed up
|
||||||
|
vim.api.nvim_set_keymap('n', '<localleader>md', ':lua RemoveCarriageReturn()<CR>', { noremap=true })
|
||||||
|
vim.api.nvim_set_keymap('n', '<localleader>j', ':lua FormatJson()<CR>', { noremap=true })
|
||||||
|
vim.api.nvim_set_keymap('n', '<localleader>cd', ':lua ChangeToCurrentDirectory()<CR>', { noremap=true })
|
||||||
|
end
|
||||||
|
|
||||||
|
@@ -1,7 +1,3 @@
|
|||||||
set nu
|
|
||||||
|
|
||||||
set mouse=
|
|
||||||
|
|
||||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||||
" Maintainer:
|
" Maintainer:
|
||||||
" Amir Salihefendic — @amix3k
|
" Amir Salihefendic — @amix3k
|
||||||
@@ -34,21 +30,13 @@ set mouse=
|
|||||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||||
" => General
|
" => General
|
||||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||||
" Sets how many lines of history VIM has to remember
|
|
||||||
set history=500
|
|
||||||
|
|
||||||
" Enable filetype plugins
|
" Enable filetype plugins
|
||||||
filetype plugin on
|
filetype plugin on
|
||||||
filetype indent on
|
filetype indent on
|
||||||
|
|
||||||
" Set to auto read when a file is changed from the outside
|
|
||||||
set autoread
|
|
||||||
|
|
||||||
" With a map leader it's possible to do extra key combinations
|
" With a map leader it's possible to do extra key combinations
|
||||||
" like <leader>w saves the current file
|
" like <leader>w saves the current file
|
||||||
let mapleader = "`"
|
let mapleader = "`"
|
||||||
noremap ";" <Nop>
|
|
||||||
let maplocalleader = ";"
|
|
||||||
|
|
||||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||||
" => VIM user interface
|
" => VIM user interface
|
||||||
@@ -73,9 +61,6 @@ else
|
|||||||
set wildignore+=*/.git/*,*/.hg/*,*/.svn/*,*/.DS_Store
|
set wildignore+=*/.git/*,*/.hg/*,*/.svn/*,*/.DS_Store
|
||||||
endif
|
endif
|
||||||
|
|
||||||
"Always show current position
|
|
||||||
set ruler
|
|
||||||
|
|
||||||
" Height of the command bar
|
" Height of the command bar
|
||||||
set cmdheight=2
|
set cmdheight=2
|
||||||
|
|
||||||
@@ -88,27 +73,13 @@ set ignorecase
|
|||||||
" When searching try to be smart about cases
|
" When searching try to be smart about cases
|
||||||
set smartcase
|
set smartcase
|
||||||
|
|
||||||
" Highlight search results
|
|
||||||
set hlsearch
|
|
||||||
|
|
||||||
" Makes search act like search in modern browsers
|
" Makes search act like search in modern browsers
|
||||||
set incsearch
|
set incsearch
|
||||||
|
|
||||||
" Don't redraw while executing macros (good performance config)
|
|
||||||
set lazyredraw
|
|
||||||
|
|
||||||
" For regular expressions turn magic on
|
" For regular expressions turn magic on
|
||||||
set magic
|
set magic
|
||||||
|
|
||||||
" Show matching brackets when text indicator is over them
|
|
||||||
set showmatch
|
|
||||||
" How many tenths of a second to blink when matching brackets
|
|
||||||
set mat=2
|
|
||||||
|
|
||||||
" No annoying sound on errors
|
" No annoying sound on errors
|
||||||
set noerrorbells
|
|
||||||
set novisualbell
|
|
||||||
set t_vb=
|
|
||||||
set tm=500
|
set tm=500
|
||||||
|
|
||||||
" Properly disable sound on errors on MacVim
|
" Properly disable sound on errors on MacVim
|
||||||
@@ -116,11 +87,6 @@ if has("gui_macvim")
|
|||||||
autocmd GUIEnter * set vb t_vb=
|
autocmd GUIEnter * set vb t_vb=
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
" Add a bit extra margin to the left
|
|
||||||
set foldcolumn=1
|
|
||||||
|
|
||||||
|
|
||||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||||
" => Colors and Fonts
|
" => Colors and Fonts
|
||||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||||
@@ -132,8 +98,6 @@ if $COLORTERM == 'gnome-terminal'
|
|||||||
set t_Co=256
|
set t_Co=256
|
||||||
endif
|
endif
|
||||||
|
|
||||||
set background=dark
|
|
||||||
|
|
||||||
" Set extra options when running in GUI mode
|
" Set extra options when running in GUI mode
|
||||||
if has("gui_running")
|
if has("gui_running")
|
||||||
set guioptions-=T
|
set guioptions-=T
|
||||||
@@ -152,25 +116,11 @@ set ffs=unix
|
|||||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||||
" => Files, backups and undo
|
" => Files, backups and undo
|
||||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||||
" Turn backup off, since most stuff is in SVN, git et.c anyway...
|
|
||||||
set nobackup
|
|
||||||
set nowb
|
set nowb
|
||||||
set noswapfile
|
|
||||||
|
|
||||||
|
|
||||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||||
" => Text, tab and indent related
|
" => Text, tab and indent related
|
||||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||||
" Use spaces instead of tabs
|
|
||||||
set expandtab
|
|
||||||
|
|
||||||
" Be smart when using tabs ;)
|
|
||||||
set smarttab
|
|
||||||
|
|
||||||
" 1 tab == 4 spaces
|
|
||||||
set shiftwidth=4
|
|
||||||
set tabstop=4
|
|
||||||
|
|
||||||
" Linebreak on 500 characters
|
" Linebreak on 500 characters
|
||||||
set lbr
|
set lbr
|
||||||
set tw=500
|
set tw=500
|
||||||
@@ -183,29 +133,6 @@ set wrap "Wrap lines
|
|||||||
" => Moving around, tabs, windows and buffers
|
" => Moving around, tabs, windows and buffers
|
||||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||||
|
|
||||||
" Disable highlight when <leader><cr> is pressed
|
|
||||||
map <silent> <leader><cr> :noh<cr>
|
|
||||||
|
|
||||||
" Useful mappings for managing tabs
|
|
||||||
map <leader>tn :tabnew<cr>
|
|
||||||
map <leader>to :tabonly<cr>
|
|
||||||
map <leader>tc :tabclose<cr>
|
|
||||||
map <leader>tm :tabmove
|
|
||||||
map <leader>t<leader> :tabnext
|
|
||||||
|
|
||||||
" Let 'tl' toggle between this and the last accessed tab
|
|
||||||
let g:lasttab = 1
|
|
||||||
nmap <Leader>tl :exe "tabn ".g:lasttab<CR>
|
|
||||||
au TabLeave * let g:lasttab = tabpagenr()
|
|
||||||
|
|
||||||
|
|
||||||
" Opens a new tab with the current buffer's path
|
|
||||||
" Super useful when editing files in the same directory
|
|
||||||
map <leader>te :tabedit <c-r>=expand("%:p:h")<cr>/
|
|
||||||
|
|
||||||
" Switch CWD to the directory of the open buffer
|
|
||||||
map <leader>cd :cd %:p:h<cr>:pwd<cr>
|
|
||||||
|
|
||||||
" Specify the behavior when switching between buffers
|
" Specify the behavior when switching between buffers
|
||||||
try
|
try
|
||||||
set switchbuf=useopen,usetab,newtab
|
set switchbuf=useopen,usetab,newtab
|
||||||
@@ -255,14 +182,6 @@ map <leader>sp [s
|
|||||||
map <leader>sa zg
|
map <leader>sa zg
|
||||||
map <leader>s? z=
|
map <leader>s? z=
|
||||||
|
|
||||||
|
|
||||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
||||||
" => Misc
|
|
||||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
||||||
" Remove the Windows ^M - when the encodings gets messed up
|
|
||||||
noremap <Leader>m mmHmt:%s/<C-V><cr>//ge<cr>'tzt'm
|
|
||||||
|
|
||||||
|
|
||||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||||
" => Helper functions
|
" => Helper functions
|
||||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||||
@@ -316,33 +235,8 @@ function! VisualSelection(direction, extra_filter) range
|
|||||||
let @" = l:saved_reg
|
let @" = l:saved_reg
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
nnoremap <leader>c :!cargo clippy
|
|
||||||
nnoremap <leader>j :%!python -m json.tool
|
|
||||||
|
|
||||||
set statusline+=%#warningmsg#
|
set statusline+=%#warningmsg#
|
||||||
set statusline+=%{SyntasticStatuslineFlag()}
|
set statusline+=%{SyntasticStatuslineFlag()}
|
||||||
set statusline+=%*
|
set statusline+=%*
|
||||||
" Format the status line
|
" Format the status line
|
||||||
set statusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ Line:\ %l\ \ Column:\ %c
|
set statusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ Line:\ %l\ \ Column:\ %c
|
||||||
|
|
||||||
set fileformat=unix
|
|
||||||
set fileformats=unix
|
|
||||||
|
|
||||||
function MarkdownPreview()
|
|
||||||
let temp_file = tempname() . ".md"
|
|
||||||
let file_name = substitute(tolower(expand('%:t')), '\W', '_', 'g')
|
|
||||||
let temp_html = "/tmp/" . file_name . "_tmp.html"
|
|
||||||
|
|
||||||
execute 'write! ' . temp_file
|
|
||||||
|
|
||||||
let pandoc_cmd = 'pandoc ' . temp_file . ' -o ' . temp_html
|
|
||||||
|
|
||||||
call system(pandoc_cmd)
|
|
||||||
|
|
||||||
" Use tmux and lynx to preview the HTML file
|
|
||||||
let lynx_cmd = 'tmux split-window -h lynx ' . temp_html
|
|
||||||
execute "silent call jobstart(split('" . lynx_cmd . "', ' '))"
|
|
||||||
|
|
||||||
silent! execute "call delete('" . temp_file . "')"
|
|
||||||
endfunction
|
|
||||||
nnoremap <localleader>mp :call MarkdownPreview()<CR>
|
|
||||||
|
88
home-manager/nvim/which-key.lua
Normal file
88
home-manager/nvim/which-key.lua
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
require('which-key').setup({
|
||||||
|
plugins = {
|
||||||
|
marks = true, -- shows a list of your marks on ' and `
|
||||||
|
registers = true, -- shows your registers on " in NORMAL or <C-r> in INSERT mode
|
||||||
|
-- the presets plugin, adds help for a bunch of default keybindings in Neovim
|
||||||
|
-- No actual key bindings are created
|
||||||
|
spelling = {
|
||||||
|
enabled = true, -- enabling this will show WhichKey when pressing z= to select spelling suggestions
|
||||||
|
suggestions = 20, -- how many suggestions should be shown in the list?
|
||||||
|
},
|
||||||
|
presets = {
|
||||||
|
operators = true, -- adds help for operators like d, y, ...
|
||||||
|
motions = true, -- adds help for motions
|
||||||
|
text_objects = true, -- help for text objects triggered after entering an operator
|
||||||
|
windows = true, -- default bindings on <c-w>
|
||||||
|
nav = true, -- misc bindings to work with windows
|
||||||
|
z = true, -- bindings for folds, spelling and others prefixed with z
|
||||||
|
g = true, -- bindings for prefixed with g
|
||||||
|
},
|
||||||
|
},
|
||||||
|
-- add operators that will trigger motion and text object completion
|
||||||
|
-- to enable all native operators, set the preset / operators plugin above
|
||||||
|
operators = { gc = "Comments" },
|
||||||
|
key_labels = {
|
||||||
|
-- override the label used to display some keys. It doesn't effect WK in any other way.
|
||||||
|
-- For example:
|
||||||
|
-- ["<space>"] = "SPC",
|
||||||
|
-- ["<cr>"] = "RET",
|
||||||
|
-- ["<tab>"] = "TAB",
|
||||||
|
},
|
||||||
|
motions = {
|
||||||
|
count = true,
|
||||||
|
},
|
||||||
|
icons = {
|
||||||
|
breadcrumb = "»", -- symbol used in the command line area that shows your active key combo
|
||||||
|
separator = "➜", -- symbol used between a key and it's label
|
||||||
|
group = "+", -- symbol prepended to a group
|
||||||
|
},
|
||||||
|
popup_mappings = {
|
||||||
|
scroll_down = "<c-d>", -- binding to scroll down inside the popup
|
||||||
|
scroll_up = "<c-u>", -- binding to scroll up inside the popup
|
||||||
|
},
|
||||||
|
window = {
|
||||||
|
border = "none", -- none, single, double, shadow
|
||||||
|
position = "bottom", -- bottom, top
|
||||||
|
margin = { 1, 0, 1, 0 }, -- extra window margin [top, right, bottom, left]. When between 0 and 1, will be treated as a percentage of the screen size.
|
||||||
|
padding = { 1, 2, 1, 2 }, -- extra window padding [top, right, bottom, left]
|
||||||
|
winblend = 0, -- value between 0-100 0 for fully opaque and 100 for fully transparent
|
||||||
|
zindex = 1000, -- positive value to position WhichKey above other floating windows.
|
||||||
|
},
|
||||||
|
layout = {
|
||||||
|
height = { min = 4, max = 25 }, -- min and max height of the columns
|
||||||
|
width = { min = 20, max = 50 }, -- min and max width of the columns
|
||||||
|
spacing = 3, -- spacing between columns
|
||||||
|
align = "left", -- align columns left, center or right
|
||||||
|
},
|
||||||
|
ignore_missing = false, -- enable this to hide mappings for which you didn't specify a label
|
||||||
|
hidden = { "<silent>", "<cmd>", "<Cmd>", "<CR>", "^:", "^ ", "^call ", "^lua " }, -- hide mapping boilerplate
|
||||||
|
show_help = true, -- show a help message in the command line for using WhichKey
|
||||||
|
show_keys = true, -- show the currently pressed key and its label as a message in the command line
|
||||||
|
triggers = "auto", -- automatically setup triggers
|
||||||
|
-- triggers = {"<leader>"} -- or specifiy a list manually
|
||||||
|
-- list of triggers, where WhichKey should not wait for timeoutlen and show immediately
|
||||||
|
triggers_nowait = {
|
||||||
|
-- marks
|
||||||
|
"`",
|
||||||
|
"'",
|
||||||
|
"g`",
|
||||||
|
"g'",
|
||||||
|
-- registers
|
||||||
|
'"',
|
||||||
|
"<c-r>",
|
||||||
|
-- spelling
|
||||||
|
"z=",
|
||||||
|
},
|
||||||
|
triggers_blacklist = {
|
||||||
|
-- list of mode / prefixes that should never be hooked by WhichKey
|
||||||
|
-- this is mostly relevant for keymaps that start with a native binding
|
||||||
|
i = { "j", "k" },
|
||||||
|
v = { "j", "k" },
|
||||||
|
},
|
||||||
|
-- disable the WhichKey popup for certain buf types and file types.
|
||||||
|
-- Disabled by default for Telescope
|
||||||
|
disable = {
|
||||||
|
buftypes = {},
|
||||||
|
filetypes = {},
|
||||||
|
},
|
||||||
|
})
|
Reference in New Issue
Block a user