From 66575f2919d3df8beadec5bbf6281c111896b6ac Mon Sep 17 00:00:00 2001 From: tonybtw Date: Wed, 1 Oct 2025 02:41:46 -0700 Subject: [PATCH] refactor --- .gitignore | 8 ++ colors.vim | 6 ++ fzf.vim | 20 +++++ keybinds.vim | 59 +++++++++++++++ lightline.vim | 17 +++++ lsp.vim | 33 +++++++++ options.vim | 43 +++++++++++ plugins.vim | 28 +++++++ readme.org | 198 ++++++++++++++++++++++++++++++++++++++++++++++++++ vimrc | 7 ++ 10 files changed, 419 insertions(+) create mode 100644 .gitignore create mode 100644 colors.vim create mode 100644 fzf.vim create mode 100644 keybinds.vim create mode 100644 lightline.vim create mode 100644 lsp.vim create mode 100644 options.vim create mode 100644 plugins.vim create mode 100644 readme.org create mode 100644 vimrc diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..50c7a1a --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +# Ignore plugin manager files +plugged/ +autoload/ + +# Ignore undo files (if set with `set undodir=~/.vim/undodir`) +undodir/ + +.netrwhist diff --git a/colors.vim b/colors.vim new file mode 100644 index 0000000..2650602 --- /dev/null +++ b/colors.vim @@ -0,0 +1,6 @@ +set termguicolors + +let g:tokyonight_style = 'night' " available: night, storm +let g:tokyonight_enable_italic = 1 + +colorscheme tokyonight diff --git a/fzf.vim b/fzf.vim new file mode 100644 index 0000000..7bf4c0e --- /dev/null +++ b/fzf.vim @@ -0,0 +1,20 @@ +" FZF keymaps (requires Plug 'junegunn/fzf.vim') + +" Files +nnoremap ff :Files +nnoremap fo :History +nnoremap fb :Buffers +nnoremap fq :CList " For quickfix list +nnoremap fh :Helptags + +" Grep current string +nnoremap fs :Rg + +" Grep input string (fzf prompt) +nnoremap fg :Rg + +" Grep for current file name (without extension) +nnoremap fc :execute 'Rg ' . expand('%:t:r') + +" Find files in your Vim config +nnoremap fi :Files ~/.vim diff --git a/keybinds.vim b/keybinds.vim new file mode 100644 index 0000000..5b511c0 --- /dev/null +++ b/keybinds.vim @@ -0,0 +1,59 @@ +" Set leader key +let mapleader = " " + +" Open netrw with cd +nnoremap cd :Ex + +" Move selected lines up/down (like Alt-Up/Down) +vnoremap J :m '>+1gv=gv +vnoremap K :m '<-2gv=gv + +" Join lines with cursor preserved +nnoremap J mzJ`z + +" Scroll half-page and center cursor +nnoremap zz +nnoremap zz + +" Center on next/previous search result +nnoremap n nzzzv +nnoremap N Nzzzv + +" Paste without overwriting clipboard +xnoremap p "_dP +nnoremap d "_d +vnoremap d "_d + +" Make behave like in insert mode +inoremap + +" Navigate quickfix list using Ctrl-j/k +nnoremap :lnext +nnoremap :lprev +nnoremap cl :lclose + +" Disable Ex mode (accidental Q) +nnoremap Q + +" Location list navigation +nnoremap k :lnextzz +nnoremap j :lprevzz + +" Doge doc generator +nnoremap dg :DogeGenerate + +" Substitute word under cursor on line +nnoremap s :s/\<\>//gI + +" Make current file executable +nnoremap x :!chmod +x % + +" Yank via OSCYank +nmap y OSCYankOperator +vmap y OSCYankVisual + +" Reload vimrc (adjust path as needed) +nnoremap rl :source ~/.vim/vimrc + +" Source current file +nnoremap :so diff --git a/lightline.vim b/lightline.vim new file mode 100644 index 0000000..355a40a --- /dev/null +++ b/lightline.vim @@ -0,0 +1,17 @@ +set laststatus=2 +let g:lightline = { + \ 'colorscheme' : 'tokyonight', + \ 'active': { + \ 'left': [ [ 'mode', 'paste' ], + \ [ 'gitbranch', 'readonly', 'filename', 'modified' ] ], + \ 'right': [ [ 'lineinfo' ], [ 'fileformat', 'fileencoding', 'filetype' ] ] + \ }, + \ 'component_function': { + \ 'gitbranch': 'FugitiveHead', + \ 'filename': 'LightlineFilename' + \ } + \ } + +function! LightlineFilename() + return expand('%:t') !=# '' ? expand('%:t') : '[No Name]' +endfunction diff --git a/lsp.vim b/lsp.vim new file mode 100644 index 0000000..3a866a1 --- /dev/null +++ b/lsp.vim @@ -0,0 +1,33 @@ +" Enable diagnostics highlighting +let lspOpts = #{autoHighlightDiags: v:true} +autocmd User LspSetup call LspOptionsSet(lspOpts) +let lspServers = [ + \ #{ + \ name: 'rust-analyzer', + \ filetype: ['rust'], + \ path: 'rust-analyzer', + \ args: [] + \ } + \ ] + +autocmd User LspSetup call LspAddServer(lspServers) + +" Key mappings +nnoremap gd :LspGotoDefinition +nnoremap gr :LspShowReferences +nnoremap K :LspHover +nnoremap gl :LspDiag current +nnoremap nd :LspDiag next \| LspDiag current +nnoremap pd :LspDiag prev \| LspDiag current +inoremap + +" Set omnifunc for completion +autocmd FileType php setlocal omnifunc=lsp#complete + +" Custom diagnostic sign characters +autocmd User LspSetup call LspOptionsSet(#{ + \ diagSignErrorText: '✘', + \ diagSignWarningText: '▲', + \ diagSignInfoText: '»', + \ diagSignHintText: '⚑', + \ }) diff --git a/options.vim b/options.vim new file mode 100644 index 0000000..496715d --- /dev/null +++ b/options.vim @@ -0,0 +1,43 @@ +filetype plugin indent on +set softtabstop=4 +set smartindent +set showmatch +syntax on +" Line numbers +set number +set relativenumber + +" Indentation and tabs +set tabstop=4 +set shiftwidth=4 +set autoindent +set expandtab + +" Search +set ignorecase +set smartcase +set incsearch + +" Appearance +set background=dark +set signcolumn=yes +set cursorline +set colorcolumn=80 + +" Backspace behavior +set backspace=indent,eol,start + +" Split window behavior +set splitbelow +set splitright + +" dw/diw/ciw treat dash-separated words as single word +set iskeyword+=- + +" Keep cursor 8 lines from top/bottom +set scrolloff=8 + +" Cursor responsiveness +set updatetime=50 + +set laststatus=2 diff --git a/plugins.vim b/plugins.vim new file mode 100644 index 0000000..101b18f --- /dev/null +++ b/plugins.vim @@ -0,0 +1,28 @@ +" plugins.vim - Dead simple plugin manager +" Just source this file in your vimrc +let s:plugin_dir = expand('~/.vim/plugged') + +" Install a plugin if it doesn't exist +function! s:ensure(repo) + let name = split(a:repo, '/')[-1] + let path = s:plugin_dir . '/' . name + + if !isdirectory(path) + if !isdirectory(s:plugin_dir) + call mkdir(s:plugin_dir, 'p') + endif + execute '!git clone --depth=1 https://github.com/' . a:repo . ' ' . shellescape(path) + endif + + execute 'set runtimepath+=' . fnameescape(path) +endfunction + +" Your plugins +call s:ensure('junegunn/fzf') +call s:ensure('junegunn/fzf.vim') +call s:ensure('tomasiser/vim-code-dark') +call s:ensure('ghifarit53/tokyonight-vim') +call s:ensure('yegappan/lsp') +call s:ensure('ojroques/vim-oscyank') +call s:ensure('tpope/vim-commentary') +call s:ensure('itchyny/lightline.vim') diff --git a/readme.org b/readme.org new file mode 100644 index 0000000..e037ae0 --- /dev/null +++ b/readme.org @@ -0,0 +1,198 @@ +#+TITLE: Vim Configuration +#+AUTHOR: Tony +#+DATE: 2025 + +* Keybindings + +** General +| Key | Mode | Action | +|-----------------+--------+-------------------------------------| +| == | - | Leader key | +| =cd= | Normal | Open netrw file explorer | +| =rl= | Normal | Reload vimrc | +| == | Normal | Source current file | +| == | Insert | Behave like == | +| =Q= | Normal | Disabled (no Ex mode) | + +** Editing +| Key | Mode | Action | +|--------------+--------+----------------------------------------| +| =J= | Visual | Move selected lines down | +| =K= | Visual | Move selected lines up | +| =J= | Normal | Join lines with cursor preserved | +| =p= | Visual | Paste without overwriting clipboard | +| =d= | Normal/Visual | Delete without overwriting clipboard | +| =s= | Normal | Substitute word under cursor on line | +| =x= | Normal | Make current file executable | +| =dg= | Normal | Generate documentation (Doge) | + +** Navigation +| Key | Mode | Action | +|--------------+--------+----------------------------------| +| == | Normal | Scroll half-page down and center | +| == | Normal | Scroll half-page up and center | +| =n= | Normal | Next search result (centered) | +| =N= | Normal | Previous search result (centered)| +| == | Normal | Next location list item | +| == | Normal | Previous location list item | +| =k= | Normal | Next location list (centered) | +| =j= | Normal | Previous location list (centered)| +| =cl= | Normal | Close location list | + +** FZF +| Key | Mode | Action | +|--------------+--------+-------------------------------------| +| =ff= | Normal | Find files | +| =fo= | Normal | File history | +| =fb= | Normal | Open buffers | +| =fq= | Normal | Quickfix list | +| =fh= | Normal | Help tags | +| =fs= | Normal | Grep current word under cursor | +| =fg= | Normal | Grep (prompt for input) | +| =fc= | Normal | Grep for current filename | +| =fi= | Normal | Find files in =~/.vim= config | + +** Clipboard (OSCYank) +| Key | Mode | Action | +|-------------+---------------+---------------------------| +| =y= | Normal/Visual | Yank via OSCYank | + +* Dependencies + +** Required +- =git= - For plugin management +- =vim= - 8.0+ recommended +- =ripgrep= (=rg=) - Fast grep alternative for FZF +- =fd= - Fast find alternative for FZF +- =fzf= - Fuzzy finder + +** Optional +- =rust-analyzer= - Rust LSP server +- =typescript-language-server= - TypeScript/JavaScript LSP +- =intelephense= - PHP LSP + +** Installation + +*** macOS +#+begin_src bash +brew install git vim ripgrep fd fzf +brew install rust-analyzer # optional +npm install -g typescript-language-server # optional +#+end_src + +*** Linux (Debian/Ubuntu) +#+begin_src bash +sudo apt install git vim ripgrep fd-find fzf +# Note: fd is called fd-find on Debian/Ubuntu +#+end_src + +*** Rust Analyzer +#+begin_src bash +rustup component add rust-analyzer +#+end_src + +* Setup + +** 1. Clone or copy your Vim configuration +#+begin_src bash +git clone ~/.vim +#+end_src + +** 2. Configure Bash/Zsh +Add to =~/.bashrc= or =~/.zshrc=: + +#+begin_src bash +export FZF_DEFAULT_COMMAND='fd --type f --hidden --follow' +#+end_src + +Then source your shell config: +#+begin_src bash +source ~/.bashrc # or ~/.zshrc +#+end_src + +** 3. Configure fd ignore file +Create =~/.fdignore=: + +#+begin_src bash +vim ~/.fdignore +#+end_src + +Add these lines: +#+begin_src +undodir/ +plugged/ +.git +#+end_src + +** 4. Configure ripgrep ignore file +Create =~/.rgignore=: + +#+begin_src bash +vim ~/.rgignore +#+end_src + +Add the same patterns: +#+begin_src +undodir/ +plugged/ +.git +#+end_src + +** 5. Install plugins +Open Vim and the plugins will auto-install on first run. + +* Plugin List + +| Plugin | Purpose | +|-------------------------+-----------------------------------| +| =junegunn/fzf= | Fuzzy finder | +| =junegunn/fzf.vim= | FZF Vim integration | +| =tomasiser/vim-code-dark= | Code Dark color scheme | +| =ghifarit53/tokyonight-vim= | Tokyo Night color scheme | +| =yegappan/lsp= | LSP client | +| =ojroques/vim-oscyank= | Copy to system clipboard via OSC52| +| =tpope/vim-commentary= | Comment/uncomment code | +| =itchyny/lightline.vim= | Statusline | + +* File Structure + +#+begin_example +~/.vim/ +├── vimrc # Main config (sources all below) +├── options.vim # Vim options and settings +├── keybinds.vim # Keybindings +├── plugins.vim # Plugin manager and plugin list +├── colors.vim # Color scheme configuration +├── fzf.vim # FZF configuration +├── lightline.vim # Lightline configuration +└── plugged/ # Plugin installation directory +#+end_example + +* Usage + +** Installing Plugins +Plugins auto-install when you first start Vim. To manually reinstall, delete =~/.vim/plugged= and restart Vim. + +** Updating Plugins +#+begin_src bash +cd ~/.vim/plugged/ +git pull +#+end_src + +** FZF File Search +The FZF configuration respects =.gitignore=, =.fdignore=, and =.rgignore= files automatically. + +Use =ff= to search files, =fg= to grep content. + +** LSP Servers +Configure LSP servers in your config. Currently configured: +- Rust: =rust-analyzer= +- TypeScript/JavaScript: =typescript-language-server= +- PHP: =intelephense= + +* Notes + +- The plugin manager is custom and minimal - it auto-installs plugins on Vim startup +- =.fdignore= and =.rgignore= prevent searching through plugin directories and undo files +- FZF uses =fd= for file listing (faster than =find=) and =rg= for content search +- OSCYank allows copying to system clipboard even over SSH diff --git a/vimrc b/vimrc new file mode 100644 index 0000000..97e6b54 --- /dev/null +++ b/vimrc @@ -0,0 +1,7 @@ +source ~/.vim/options.vim +source ~/.vim/keybinds.vim +source ~/.vim/plugins.vim +source ~/.vim/colors.vim +source ~/.vim/fzf.vim +source ~/.vim/lightline.vim +source ~/.vim/lsp.vim