Archived
1
0
Fork 0

VIM Settings

This commit is contained in:
J. Elfring (x) 2021-04-22 21:16:20 +02:00
parent ec27fbf5de
commit d609765f0b

View file

@ -1,13 +1,9 @@
"
" Basics
"
set nocompatible " be iMproved, required
filetype off " required
filetype plugin indent on " required
" "
" Install plugins " Install plugins
" "
set nocompatible " be iMproved, required
filetype off " required
call plug#begin('~/.vim/vimplug-plugins') call plug#begin('~/.vim/vimplug-plugins')
Plug 'Raimondi/delimitMate' " Autoclose quotes, parenthesis, brackets, etc. Plug 'Raimondi/delimitMate' " Autoclose quotes, parenthesis, brackets, etc.
Plug 'airblade/vim-gitgutter' " Git-indicators on the left Plug 'airblade/vim-gitgutter' " Git-indicators on the left
@ -19,244 +15,67 @@ Plug 'scrooloose/nerdtree' " Nerdtree...
Plug 'tpope/vim-fugitive' " git integration Plug 'tpope/vim-fugitive' " git integration
call plug#end() call plug#end()
filetype plugin indent on
syntax on
syntax sync minlines=256
" "
" Settings " Settings
" "
set noerrorbells " No beeps set autoindent
set number " Show line numbers
set backspace=indent,eol,start " Makes backspace key more powerful.
set showcmd " Show me what I'm typing
set showmode " Show current mode.
set noswapfile " Don't use swapfile
set nobackup " Don't create annoying backup files
set nowritebackup
set splitright " Split vertical windows right to the current windows
set splitbelow " Split horizontal windows below to the current windows
set encoding=utf-8 " Set default encoding to UTF-8
set autowrite " Automatically save before :next, :make etc.
set autoread " Automatically reread changed files without asking me anything set autoread " Automatically reread changed files without asking me anything
set laststatus=2 set autowrite " Automatically save before :next, :make etc.
set hidden set backspace=indent,eol,start " Makes backspace key more powerful.
set complete=.,w,b,u,t
set ruler " Show the cursor position all the time set completeopt=longest,menuone
au FocusLost * :wa " Set vim to save the file on focus out. set display+=lastline
set encoding=utf-8 " Set default encoding to UTF-8
set fileformats=unix,dos,mac " Prefer Unix over Windows over OS 9 formats set fileformats=unix,dos,mac " Prefer Unix over Windows over OS 9 formats
set hidden
set showmatch " Show matching brackets by flickering set history=500
set noshowmode " We show the mode with airlien or lightline set hlsearch
set incsearch " Shows the match while typing set ignorecase
set hlsearch " Highlight found searches set incsearch
set ignorecase " Search case insensitive... set laststatus=2
set smartcase " ... but not when search pattern contains upper case characters set lazyredraw
set ttyfast set nobackup " Don't create annoying backup files
set lazyredraw " Wait to redraw "
" speed up syntax highlighting
set nocursorcolumn set nocursorcolumn
set nocursorline set nocursorline
set noerrorbells " No beeps
syntax sync minlines=256 set noshowmode " We show the mode with airlien or lightline
set synmaxcol=300 set noswapfile " Don't use swapfile
set nowritebackup
set nrformats-=octal
set number " Show line numbers
set re=1 set re=1
set ruler " Show the cursor position all the time
" open help vertically set scrolloff=7
command! -nargs=* -complete=help Help vertical belowright help <args> set showcmd " Show me what I'm typing
autocmd FileType help wincmd L set showmatch " Show matching brackets by flickering
set sidescrolloff=7
set smartcase
set splitbelow " Split horizontal windows below to the current windows
set splitright " Split vertical windows right to the current windows
set synmaxcol=300
set tabpagemax=50
set ttyfast
" Make Vim to handle long lines nicely. " Make Vim to handle long lines nicely.
set wrap set wrap
set textwidth=79 set textwidth=79
set formatoptions=qrn1 set formatoptions=qrn1
" mail line wrapping
au BufRead /tmp/mutt-* set tw=72
set autoindent
set complete-=i
set smarttab
set tabstop=4
set shiftwidth=4
set expandtab
set nrformats-=octal
set shiftround
" Time out on key codes but not mappings. " Time out on key codes but not mappings.
" Basically this makes terminal Vim work sanely.
set notimeout set notimeout
set ttimeout set ttimeout
set ttimeoutlen=10 set ttimeoutlen=10
" Different Cursorshapes for the modes
let &t_SI = "\<Esc>[6 q"
let &t_SR = "\<Esc>[4 q"
let &t_EI = "\<Esc>[2 q"
" Better Completion
set complete=.,w,b,u,t
set completeopt=longest,menuone
if &history < 1000
set history=50
endif
if &tabpagemax < 50
set tabpagemax=50
endif
if !empty(&viminfo)
set viminfo^=!
endif
if !&scrolloff
set scrolloff=1
endif
if !&sidescrolloff
set sidescrolloff=5
endif
set display+=lastline
" CTRL-U in insert mode deletes a lot. Use CTRL-G u to first break undo,
" so that you can undo CTRL-U after inserting a line break.
inoremap <C-U> <C-G>u<C-U>
" Only do this part when compiled with support for autocommands.
if has("autocmd")
" Enable file type detection.
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on
" Put these in an autocmd group, so that we can delete them easily.
augroup vimrcEx
au!
" For all text files set 'textwidth' to 78 characters.
autocmd FileType text setlocal textwidth=78
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
" Also don't do it when the mark is in the first line, that is the default
" position when opening a file.
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
augroup END
else
endif " has("autocmd")
syntax enable
if has('gui_running') if has('gui_running')
"set transparency=3 "set transparency=3
" fix js regex syntax set regexpengine=1 " fix js regex syntax
set regexpengine=1
syntax enable
endif endif
" This comes first, because we have mappings that depend on leader
" With a map leader it's possible to do extra key combinations
" i.e: <leader>w saves the current file
let mapleader = "," let mapleader = ","
let g:mapleader = ","
let maplocalleader = ";"
" This trigger takes advantage of the fact that the quickfix window can be
" easily distinguished by its file-type, qf. The wincmd J command is
" equivalent to the Ctrl+W, Shift+J shortcut telling Vim to move a window to
" the very bottom (see :help :wincmd and :help ^WJ).
autocmd FileType qf wincmd J
" Dont show me any output when I build something
" Because I am using quickfix for errors
"nmap <leader>m :make<CR><enter>
" Some useful quickfix shortcuts
":cc see the current error
":cn next error
":cp previous error
":clist list all errors
map <C-n> :cn<CR>
map <C-m> :cp<CR>
nnoremap <silent> <leader>q :Sayonara<CR>
" Replace the current buffer with the given new file. That means a new file
" will be open in a buffer while the old one will be deleted
com! -nargs=1 -complete=file Breplace edit <args>| bdelete #
function! DeleteInactiveBufs()
"From tabpagebuflist() help, get a list of all buffers in all tabs
let tablist = []
for i in range(tabpagenr('$'))
call extend(tablist, tabpagebuflist(i + 1))
endfor
"Below originally inspired by Hara Krishna Dara and Keith Roberts
"http://tech.groups.yahoo.com/group/vim/message/56425
let nWipeouts = 0
for i in range(1, bufnr('$'))
if bufexists(i) && !getbufvar(i,"&mod") && index(tablist, i) == -1
"bufno exists AND isn't modified AND isn't in the list of buffers open in windows and tabs
silent exec 'bwipeout' i
let nWipeouts = nWipeouts + 1
endif
endfor
echomsg nWipeouts . ' buffer(s) wiped out'
endfunction
command! Ball :call DeleteInactiveBufs()
" Toggle line numbers
nmap <leader>ll :set number!<cr>
nmap <leader>lr :set relativenumber!<cr>
" Close quickfix easily
nnoremap <leader>a :cclose<CR>
" Remove search highlight
nnoremap <leader><space> :nohlsearch<CR>
" Better split switching
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l
" Center the screen
nnoremap <space> zz
" Move up and down on splitted lines (on small width screens)
map <Up> gk
map <Down> gj
map k gk
map j gj
nnoremap <F6> :setlocal spell! spell?<CR>
" Search mappings: These will make it so that going to the next one in a
" search will center on the line it's found in.
nnoremap n nzzzv
nnoremap N Nzzzv
"nnoremap <leader>. :lcd %:p:h<CR>
autocmd BufEnter * silent! lcd %:p:h
" trim all whitespaces away
nnoremap <leader>W :%s/\s\+$//<cr>:let @/=''<CR>
" Do not show stupid q: window
map q: :q
" dont save .netrwhist history " dont save .netrwhist history
let g:netrw_dirhistmax=0 let g:netrw_dirhistmax=0
@ -264,72 +83,98 @@ let g:netrw_dirhistmax=0
" Allow saving of files as sudo when I forgot to start vim using sudo. " Allow saving of files as sudo when I forgot to start vim using sudo.
cmap w!! w !sudo tee > /dev/null % cmap w!! w !sudo tee > /dev/null %
" never do this again --> :set paste <ctrl-v> :set no paste " open help vertically
let &t_SI .= "\<Esc>[?2004h" command! -nargs=* -complete=help Help vertical belowright help <args>
let &t_EI .= "\<Esc>[?2004l"
inoremap <special> <expr> <Esc>[200~ XTermPasteBegin() " Different Cursorshapes for the modes
let &t_SI = "\<Esc>[6 q"
let &t_SR = "\<Esc>[4 q"
let &t_EI = "\<Esc>[2 q"
function! XTermPasteBegin() " ==================== Remap Keys ====================
set pastetoggle=<Esc>[201~ " Remaps % to tab so navigate to matching brackets
set paste nnoremap <tab> %
return "" vnoremap <tab> %
endfunction
" set 80 character line limit " Visual mode pressing * or # searches for the current selection
"if exists('+colorcolumn') vnoremap <silent> * :call VisualSelection('f')<CR>
" set colorcolumn=80 vnoremap <silent> # :call VisualSelection('b')<CR>
"else
" au BufWinEnter * let w:m2=matchadd('ErrorMsg', '\%>80v.\+', -1)
"endif
" ----------------------------------------- " " Center, kill hl
" File Type settings " nnoremap n nzzzv
" ----------------------------------------- " nnoremap N Nzzzv
nnoremap <leader><space> :nohlsearch<CR>
nnoremap <space> zz
" CTRL-U in insert mode deletes a lot. Use CTRL-G u to first break undo,
" so that you can undo CTRL-U after inserting a line break.
inoremap <C-U> <C-G>u<C-U>
" Toggle line numbers and rulers
nmap <leader>ll :set number!<cr>
nmap <leader>lr :set relativenumber!<cr>
nmap <leader>cc :set cursorcolumn!<cr>
nmap <leader>cl :set cursorline!<cr>
" Better split switching
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l
map <C-down> <C-W>j
map <C-up> <C-W>k
map <C-left> <C-W>h
map <C-right> <C-W>l
" Move up and down on split lines
map <Up> gk
map <Down> gj
map k gk
map j gj
" Spell checking
nnoremap <F6> :setlocal spell! spell?<CR>
map <leader>ss :setlocal spell!<cr>
map <leader>sn ]s
map <leader>sp [s
map <leader>sa zg
map <leader>s? z=
" trim all whitespaces away
nnoremap <leader>W :%s/\s\+$//<cr>:let @/=''<CR>
" Do not show stupid q: window
map q: :q
" Paste Mode
set pastetoggle=<F2>
" ==================== File Type settings ====================
set tabstop=4
set softtabstop=4
set shiftwidth=4
set noexpandtab
set shiftround
set smarttab
au BufNewFile,BufRead *.vim setlocal noet ts=4 sw=4 sts=4 au BufNewFile,BufRead *.vim setlocal noet ts=4 sw=4 sts=4
au BufNewFile,BufRead *.txt setlocal noet ts=4 sw=4 au BufNewFile,BufRead *.txt setlocal noet ts=4 sw=4 sts=4
au BufNewFile,BufRead *.md setlocal noet ts=4 sw=4 au BufNewFile,BufRead *.md setlocal noet ts=4 sw=4 sts=4
au BufNewFile,BufRead *.yml,*.yaml setlocal expandtab ts=2 sw=2 au BufNewFile,BufRead *.json setlocal et ts=2 sw=2 sts=2
au BufNewFile,BufRead *.cpp setlocal expandtab ts=2 sw=2
au BufNewFile,BufRead *.hpp setlocal expandtab ts=2 sw=2
au BufNewFile,BufRead *.json setlocal expandtab ts=2 sw=2
augroup filetypedetect
au BufNewFile,BufRead .tmux.conf*,tmux.conf* setf tmux
au BufNewFile,BufRead .nginx.conf*,nginx.conf* setf nginx
augroup END
au FileType nginx setlocal noet ts=4 sw=4 sts=4
" Go settings
au BufNewFile,BufRead *.go setlocal noet ts=4 sw=4 sts=4 au BufNewFile,BufRead *.go setlocal noet ts=4 sw=4 sts=4
au BufNewFile,BufRead *.md setlocal et ts=4 sw=4 sts=4
au BufNewFile,BufRead *.lua setlocal noet ts=4 sw=4 sts=4
au BufNewFile,BufRead *.py setlocal et ts=4 sw=4 sts=4
au BufNewFile,BufRead *.yml,*.yaml setlocal et ts=2 sw=2 sts=2
au BufNewFile,BufRead *.htm,*.html setlocal noet ts=4 sw=4 sts=4
" scala settings au FileType dockerfile setlocal et ts=2 sw=2 sts=2
autocmd BufNewFile,BufReadPost *.scala setl shiftwidth=2 expandtab au FileType nginx setlocal noet ts=4 sw=4 sts=4
au FileType fstab,systemd set noet
au FileType gitconfig,sh,toml set noet
" Markdown Settings " ==================== Wildmenu ====================
autocmd BufNewFile,BufReadPost *.md setl ts=4 sw=4 sts=4 expandtab
" lua settings
autocmd BufNewFile,BufRead *.lua setlocal noet ts=4 sw=4 sts=4
" Dockerfile settings
autocmd FileType dockerfile set noexpandtab
" shell/config/systemd settings
autocmd FileType fstab,systemd set noexpandtab
autocmd FileType gitconfig,sh,toml set noexpandtab
" python indent
autocmd BufNewFile,BufRead *.py setlocal tabstop=4 softtabstop=4 shiftwidth=4 textwidth=80 smarttab expandtab
" toml settings
au BufRead,BufNewFile MAINTAINERS set ft=toml
" Wildmenu completion {{{
set wildmenu set wildmenu
" set wildmode=list:longest
set wildmode=list:full set wildmode=list:full
set wildignore+=.hg,.git,.svn " Version control set wildignore+=.hg,.git,.svn " Version control
@ -348,17 +193,13 @@ set wildignore+=*.pyc " Python byte code
set wildignore+=*.orig " Merge resolution files set wildignore+=*.orig " Merge resolution files
" ----------------------------------------- " " ==================== PLUGIN: Fugitive ====================
" Plugin configs "
" ----------------------------------------- "
" ==================== Fugitive ====================
nnoremap <leader>ga :Git add %:p<CR><CR> nnoremap <leader>ga :Git add %:p<CR><CR>
nnoremap <leader>gs :Gstatus<CR> nnoremap <leader>gs :Gstatus<CR>
nnoremap <leader>gp :Gpush<CR> nnoremap <leader>gp :Gpush<CR>
vnoremap <leader>gb :Gblame<CR> vnoremap <leader>gb :Gblame<CR>
" ==================== Lightline ==================== " ==================== PLUGIN: Lightline ====================
" "
let g:lightline = { let g:lightline = {
\ 'active': { \ 'active': {
@ -459,7 +300,7 @@ let g:ctrlp_status_func = {
\ 'prog': 'CtrlPStatusFunc_2', \ 'prog': 'CtrlPStatusFunc_2',
\ } \ }
" ==================== NerdTree ==================== " ==================== PLUGIN: NerdTree ====================
" For toggling " For toggling
nmap <C-n> :NERDTreeToggle<CR> nmap <C-n> :NERDTreeToggle<CR>
noremap <Leader>n :NERDTreeToggle<cr> noremap <Leader>n :NERDTreeToggle<cr>