Last active
August 27, 2024 22:31
-
-
Save marcs-feh/c71a73f51171b9ef8cc66aa29a1415b6 to your computer and use it in GitHub Desktop.
Quick neovim cfg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Simple init.vim that's compatible with Neovim and Vim | |
let g:Tabsize=4 | |
let g:JKEscape=v:true | |
" Syntax and colors | |
" if exists('g:syntax_on') | |
" syntax on | |
" endif | |
" General options | |
set nocompatible | |
let &tabstop=g:Tabsize | |
let &shiftwidth=g:Tabsize | |
let &fillchars='vert: ' | |
set nobackup | |
set hidden | |
set clipboard=unnamedplus | |
set cmdheight=1 | |
set completeopt=menuone,noselect | |
set conceallevel=0 | |
set fileencoding=utf-8 | |
set nohlsearch | |
set incsearch | |
set ignorecase | |
set mouse=a | |
set pumheight=10 | |
set noshowmode | |
set showtabline=2 | |
set laststatus=2 | |
set smartcase | |
set splitbelow | |
set splitright | |
set noswapfile | |
set timeoutlen=800 | |
set undofile | |
set updatetime=300 | |
set smartindent | |
set nowritebackup | |
set noexpandtab | |
set termguicolors | |
set nocursorline | |
set number | |
set norelativenumber | |
set numberwidth=3 | |
set signcolumn=no | |
set nowrap | |
set foldmethod=indent | |
set foldlevelstart=99 | |
set scrolloff=8 | |
set sidescrolloff=12 | |
set background=dark | |
" Netrw Options | |
let g:netrw_keepdir = 0 | |
let g:netrw_banner = 0 | |
let g:netrw_hide = 1 | |
let g:netrw_winsize = 30 | |
" Keybindings | |
function! s:map(mode, trigger, action) | |
execute a:mode . 'noremap <silent> ' . a:trigger . ' ' . a:action | |
endfunction | |
noremap <Space> <Nop> | |
let g:mapleader=' ' | |
let g:maplocalleader=' ' | |
noremap Q <Nop> | |
noremap K <Nop> | |
if g:JKEscape | |
" The `^ ensures that the cursor stays on the last character typed | |
call s:map('i', 'jk', '<ESC>`^') | call s:map('i', 'kj', '<ESC>`^') | |
call s:map('v', 'jk', '<ESC>`^') | call s:map('v', 'kj', '<ESC>`^') | |
endif | |
call s:map('n', '<C-s>', ':w<CR>') | |
call s:map('i', '<C-s>', '<ESC>:w<CR>') | |
call s:map('n', '<C-k>', '<C-u>zz') | |
call s:map('n', '<C-j>', '<C-d>zz') | |
call s:map('n', 'Y', 'y$') | |
call s:map('n', 'D', 'd$') | |
call s:map('n', 'C', 'c$') | |
call s:map('n', '<C-a>', ':normal ggVG<CR>') | |
call s:map('n', 'L', ':bnext<CR>') | |
call s:map('n', 'H', ':bprevious<CR>') | |
call s:map('n', '<leader>n', ':enew<CR>') | |
call s:map('n', '<leader>q', ':close<CR>') | |
call s:map('n', '<leader>x', ':bdelete<CR>') | |
call s:map('n', '<leader>X', ':bdelete!<CR>') | |
call s:map('n', '<leader>l', ':noh<CR>:echo<CR>') | |
call s:map('n', '<leader>c', ':Commentary<CR>') | |
call s:map('v', '<leader>c', ':Commentary<CR>') | |
augroup NetrwKeys | |
autocmd! | |
autocmd FileType netrw | |
\ nnoremap <buffer> <silent> cd :cd %<CR> | |
augroup END | |
function! s:betterCHighlight() | |
syn keyword cExtraType | |
\ i8 i16 i32 i64 | |
\ u8 u16 u32 u64 | |
\ b8 b16 b32 b64 | |
\ isize usize uint uintptr | |
\ f16 f32 f64 | |
syn keyword Keyword typedef sizeof alignof decltype | |
syn match cppNamespace '\v\zs\i+\ze(\<.{-}\>)?\s*::\s*\i+' | |
syn match cAttribute '\v\[\[.{-}\]\]' | |
hi! link cppNamespace Type | |
hi! link cAttribute Type | |
hi! link cExtraType Type | |
endfunction | |
function! s:betterCMaps() | |
inoremap <silent> <C-f> -> | |
endfunction | |
augroup CAndCpp | |
autocmd! | |
autocmd FileType c,cpp call s:betterCHighlight() | |
augroup END | |
nnoremap <silent> <leader>f :Lexplore<CR> | |
nnoremap <silent> <leader>W :%s/\s\+$//<CR> | |
nnoremap <silent> <leader>sh :split<CR> | |
nnoremap <silent> <leader>sv :vsplit<CR> | |
nnoremap <C-o> <C-w>w | |
inoremap <silent> <expr> <Tab> pumvisible() ? '<C-n>' : '<Tab>' | |
inoremap <silent> <expr> <S-Tab> pumvisible() ? '<C-p>' : '<S-Tab>' | |
inoremap <silent> <expr> <CR> pumvisible() ? ' ' : '<CR>' | |
vnoremap <silent> < <gv | |
vnoremap <silent> > >gv | |
xnoremap <silent> <C-k> :move '<-2<cr>gv-gv | |
xnoremap <silent> <C-j> :move '>+1<cr>gv-gv | |
let s:fencoding=(strlen(&fileencoding) > 0 ? &fileencoding : 'none') | |
let &statusline=' %m%f %= %y | %l:%c | ' . s:fencoding . '[' . &fileformat .'] ' | |
" === Embedded Plugins === | |
" These plugins are small and quite useful and as such were directly embedded | |
" into the config. You can delete this section and use a plugin manager like | |
" Plug if you prefer. Names are in the form: <author>/<repo-name> | <license> | |
" tpope/vim-commentary | :help license | |
function! s:commentary() | |
" Maintainer: Tim Pope <http://tpo.pe/> | |
let g:loaded_commentary = 1 | |
function! s:surroundings() abort | |
return split(get(b:, 'commentary_format', substitute(substitute(substitute( | |
\ &commentstring, '^$', '%s', ''), '\S\zs%s',' %s', '') ,'%s\ze\S', '%s ', '')), '%s', 1) | |
endfunction | |
function! s:strip_white_space(l,r,line) abort | |
let [l, r] = [a:l, a:r] | |
if l[-1:] ==# ' ' && stridx(a:line,l) == -1 && stridx(a:line,l[0:-2]) == 0 | |
let l = l[:-2] | |
endif | |
if r[0] ==# ' ' && (' ' . a:line)[-strlen(r)-1:] != r && a:line[-strlen(r):] == r[1:] | |
let r = r[1:] | |
endif | |
return [l, r] | |
endfunction | |
function! s:go(...) abort | |
if !a:0 | |
let &operatorfunc = matchstr(expand('<sfile>'), '[^. ]*$') | |
return 'g@' | |
elseif a:0 > 1 | |
let [lnum1, lnum2] = [a:1, a:2] | |
else | |
let [lnum1, lnum2] = [line("'["), line("']")] | |
endif | |
let [l, r] = s:surroundings() | |
let uncomment = 2 | |
let force_uncomment = a:0 > 2 && a:3 | |
for lnum in range(lnum1,lnum2) | |
let line = matchstr(getline(lnum),'\S.*\s\@<!') | |
let [l, r] = s:strip_white_space(l,r,line) | |
if len(line) && (stridx(line,l) || line[strlen(line)-strlen(r) : -1] != r) | |
let uncomment = 0 | |
endif | |
endfor | |
if get(b:, 'commentary_startofline') | |
let indent = '^' | |
else | |
let indent = '^\s*' | |
endif | |
let lines = [] | |
for lnum in range(lnum1,lnum2) | |
let line = getline(lnum) | |
if strlen(r) > 2 && l.r !~# '\\' | |
let line = substitute(line, | |
\'\M' . substitute(l, '\ze\S\s*$', '\\zs\\d\\*\\ze', '') . '\|' . substitute(r, '\S\zs', '\\zs\\d\\*\\ze', ''), | |
\'\=substitute(submatch(0)+1-uncomment,"^0$\\|^-\\d*$","","")','g') | |
endif | |
if force_uncomment | |
if line =~ '^\s*' . l | |
let line = substitute(line,'\S.*\s\@<!','\=submatch(0)[strlen(l):-strlen(r)-1]','') | |
endif | |
elseif uncomment | |
let line = substitute(line,'\S.*\s\@<!','\=submatch(0)[strlen(l):-strlen(r)-1]','') | |
else | |
let line = substitute(line,'^\%('.matchstr(getline(lnum1),indent).'\|\s*\)\zs.*\S\@<=','\=l.submatch(0).r','') | |
endif | |
call add(lines, line) | |
endfor | |
call setline(lnum1, lines) | |
let modelines = &modelines | |
try | |
set modelines=0 | |
silent doautocmd User CommentaryPost | |
finally | |
let &modelines = modelines | |
endtry | |
return '' | |
endfunction | |
function! s:textobject(inner) abort | |
let [l, r] = s:surroundings() | |
let lnums = [line('.')+1, line('.')-2] | |
for [index, dir, bound, line] in [[0, -1, 1, ''], [1, 1, line('$'), '']] | |
while lnums[index] != bound && line ==# '' || !(stridx(line,l) || line[strlen(line)-strlen(r) : -1] != r) | |
let lnums[index] += dir | |
let line = matchstr(getline(lnums[index]+dir),'\S.*\s\@<!') | |
let [l, r] = s:strip_white_space(l,r,line) | |
endwhile | |
endfor | |
while (a:inner || lnums[1] != line('$')) && empty(getline(lnums[0])) | |
let lnums[0] += 1 | |
endwhile | |
while a:inner && empty(getline(lnums[1])) | |
let lnums[1] -= 1 | |
endwhile | |
if lnums[0] <= lnums[1] | |
execute 'normal! 'lnums[0].'GV'.lnums[1].'G' | |
endif | |
endfunction | |
command! -range -bar -bang Commentary call s:go(<line1>,<line2>,<bang>0) | |
xnoremap <expr> <Plug>Commentary <SID>go() | |
nnoremap <expr> <Plug>Commentary <SID>go() | |
nnoremap <expr> <Plug>CommentaryLine <SID>go() . '_' | |
onoremap <silent> <Plug>Commentary :<C-U>call <SID>textobject(get(v:, 'operator', '') ==# 'c')<CR> | |
nnoremap <silent> <Plug>ChangeCommentary c:<C-U>call <SID>textobject(1)<CR> | |
if !hasmapto('<Plug>Commentary') || maparg('gc','n') ==# '' | |
xmap gc <Plug>Commentary | |
nmap gc <Plug>Commentary | |
omap gc <Plug>Commentary | |
nmap gcc <Plug>CommentaryLine | |
nmap gcu <Plug>Commentary<Plug>Commentary | |
endif | |
nmap <silent> <Plug>CommentaryUndo :echoerr "Change your <Plug>CommentaryUndo map to <Plug>Commentary<Plug>Commentary"<CR> | |
endfunction | |
call s:commentary() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment