From 91fb4f28ef5d87e8bcf7749928d30ba4a9cbbd34 Mon Sep 17 00:00:00 2001 From: Azat Bahawi Date: Sun, 19 Feb 2023 17:50:35 +0300 Subject: 2023-02-19 --- modules/common/vim/default.nix | 50 ++++++++ modules/common/vim/rc.vim | 253 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 303 insertions(+) create mode 100644 modules/common/vim/default.nix create mode 100644 modules/common/vim/rc.vim (limited to 'modules/common/vim') diff --git a/modules/common/vim/default.nix b/modules/common/vim/default.nix new file mode 100644 index 0000000..0328e10 --- /dev/null +++ b/modules/common/vim/default.nix @@ -0,0 +1,50 @@ +{ + config, + lib, + pkgs, + this, + ... +}: +with lib; let + cfg = config.nixfiles.modules.vim; +in { + options.nixfiles.modules.vim.enable = mkEnableOption "Vim"; + + config = mkIf cfg.enable { + programs.vim.package = with pkgs; + (vim_configurable.override { + features = "normal"; + cscopeSupport = false; + darwinSupport = pkgs.stdenv.isDarwin; + guiSupport = false; + luaSupport = false; + multibyteSupport = false; + netbeansSupport = false; + nlsSupport = false; + perlSupport = false; + pythonSupport = false; + rubySupport = false; + tclSupport = false; + ximSupport = false; + }) + .customize { + name = "vim"; + vimrcConfig = { + customRC = readFile ./rc.vim; + packages.myVimPackage.start = with vimPlugins; [ + editorconfig-vim + vim-eunuch + vim-nix + vim-sleuth + vim-surround + vim-unimpaired + ]; + }; + }; + + environment = { + systemPackages = [config.programs.vim.package]; + variables.EDITOR = mkOverride 100 "vim"; + }; + }; +} diff --git a/modules/common/vim/rc.vim b/modules/common/vim/rc.vim new file mode 100644 index 0000000..945643a --- /dev/null +++ b/modules/common/vim/rc.vim @@ -0,0 +1,253 @@ +set nocompatible + +let $VIMFILES = expand(':p:h') + +let g:skip_defaults_vim = 1 + +let g:netrw_dirhistmax = 0 + +set autoread +set backspace=indent,eol,start + +set clipboard=unnamedplus +set diffopt+=iwhite +set hidden +set history=256 +set lazyredraw +set mouse= +set path+=** +set tabpagemax=50 +set viminfo= + +set cmdheight=1 +set display+=lastline +set fillchars=vert:\ " +set laststatus=2 +set modeline +set noshowmode +set ruler +set shortmess+=I +set textwidth=0 +set title + +set sessionoptions-=options +set viewoptions-=options + +set noerrorbells +set novisualbell + +set splitbelow +set splitright + +set complete= +set complete+=. +set complete+=b +set complete+=t +set completeopt= +set completeopt+=menu +set completeopt+=longest + +set gdefault +set hlsearch +set incsearch +set iskeyword+=- +set magic + +set foldmethod=marker +set nofoldenable + +set shortmess= +set shortmess+=I +set shortmess+=T +set shortmess+=a +set shortmess+=c +set shortmess+=t + +set nolist +set nowrap + +set scrolloff=10 +set sidescrolloff=10 + +set number +if v:version >= 700 + set numberwidth=3 +endif + +set wildignorecase +set wildmenu +set wildignore= + +set nobackup +set noswapfile +set noundofile +set nowritebackup + +set smartcase +set ignorecase + +set autoindent +set breakindent +set smartindent + +set expandtab +set shiftround +set shiftwidth=4 +set smarttab +set softtabstop=4 +set tabstop=4 + +autocmd BufEnter *.* :set colorcolumn= + +if &t_Co == 8 && $TERM !~# '^Eterm' + set t_Co=16 +endif + +if &listchars ==# 'eol:$' + set listchars=tab:>\ ,trail:-,extends:>,precedes:<,nbsp:+ +endif + +if v:version > 703 || v:version == 703 && has("patch541") + set formatoptions+=j +endif + +if has('path_extra') + setglobal tags-=./tags tags-=./tags; tags^=./tags; +endif + +if !has('nvim') && &ttimeoutlen == -1 + set ttimeout + set ttimeoutlen=100 +endif + +try + set encoding=utf-8 + scriptencoding utf-8 +catch +endtry + +try + if &fileencodings !~? "utf-8" + let g:added_fenc_utf8 = 1 + set fileencodings+=utf-8 + endif +catch +endtry + +if has('autocmd') + filetype plugin indent on + + if exists("+omnifunc") + autocmd Filetype * + \ if &omnifunc == "" | + \ setlocal omnifunc=syntaxcomplete#Complete | + \ endif + endif + + autocmd BufEnter * set noreadonly +endif + +if has('syntax') && !exists('g:syntax_on') + syntax enable +endif + +if !exists('g:loaded_matchit') && findfile('plugin/matchit.vim', &rtp) ==# '' + runtime! macros/matchit.vim +endif + +nnoremap +let mapleader=" " + +nnoremap :W :w +nnoremap :W! :w! +nnoremap :Q :q +nnoremap :Q! :q! + +nnoremap j v:count ? 'j' : 'gj' +nnoremap k v:count ? 'k' : 'gk' + +nnoremap J gt +nnoremap K gT + +nnoremap ^h +vnoremap ^h +nnoremap H ^h +vnoremap H ^h + +nnoremap $ +vnoremap $ +nnoremap L $ +vnoremap L $ + +nnoremap N Nzzzv +nnoremap n nzzzv + +inoremap u +inoremap u + +vnoremap < >gv +vnoremap >gv +vnoremap >>_ +nnoremap <<_ + +nnoremap ]b :bnext +nnoremap [b :bprevious + +nnoremap h +nnoremap j +nnoremap k +nnoremap l + +nnoremap * /\<=expand('')\> +nnoremap # ?\<=expand('')\> + +nnoremap :nohlsearch=has('diff')?'diffupdate':'' + +cnoremap ;/ =expand('%:p:h').'/' +cnoremap ;; =expand('%:t') +cnoremap ;. =expand('%:p:r') + +nnoremap . :lcd %:p:h + +nnoremap Q @q + +nnoremap c ^v$h +nnoremap v ggVG + +nnoremap y "+y +nnoremap Y "+Y + +nnoremap p "+p +nnoremap P "+P + +inoremap "+pi +cnoremap + + +nmap w :w! +nmap wq :wq! + +nnoremap ZX :qa! + +nnoremap q :q + +command WS w !sudo tee "%" >/dev/null + +function! SwitchCase() + normal! ~ + if strlen(getline('.')) != virtcol('.') + normal! h + endif +endfunction +nnoremap ~ :call SwitchCase() + +function! s:GM() + execute 'normal! ^' + let first_col = virtcol('.') + execute 'normal! g_' + let last_col = virtcol('.') + execute 'normal! ' . (first_col + last_col) / 2 . '|' +endfunction +nnoremap gm :call GM() +onoremap gm :call GM() -- cgit 1.4.1