Skip to content

Instantly share code, notes, and snippets.

@airstrike
Created August 27, 2023 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save airstrike/e51ebf09d8486b578949b8bdcfee2a6f to your computer and use it in GitHub Desktop.
Save airstrike/e51ebf09d8486b578949b8bdcfee2a6f to your computer and use it in GitHub Desktop.
vscode .vimrc
" VIM user interface
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Set 7 lines to the curors - when moving vertical..
set so=4
set ruler "Always show current position
set cmdheight=1 "The commandbar height
" Set backspace config
set backspace=eol,start,indent
set whichwrap+=<,>,h,l
set ignorecase "Ignore case when searching
set smartcase
set hlsearch "Highlight search things
set incsearch "Make search act like search in modern browsers
set nolazyredraw "Don't redraw while executing macros
set magic "Set magic on, for regular expressions
set showmatch "Show matching bracets when text indicator is over them
" No sound on errors
set noerrorbells
set novisualbell
set t_vb=
set tm=500
" Colors and Fonts
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set encoding=utf8
try
lang en_US
catch
endtry
set ffs=unix,mac,dos "Default file types
" tab, spacing, wrapping
set expandtab
set shiftwidth=4
set tabstop=4
set smarttab
set ai
set si
set nowrap
set autoread
" General
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Sets how many lines of history VIM has to remember
set history=700
" Enable filetype plugin
filetype plugin on
filetype indent on
" With a map leader it's possible to do extra key combinations
" like <leader>w saves the current file
let mapleader = ","
let g:mapleader = ","
" Fast saving
nnoremap <leader>w :w!<cr>
" Close buffer
nnoremap <leader>q :bdelete<cr>
" Fast buffer switching
nnoremap <leader>, :bprev<cr>
nnoremap <leader>. :bnext<cr>
nnoremap <leader>q :bwipeout<cr>
" Fast cargo run
nnoremap <leader>x :!clear && cargo run<cr>
nnoremap <leader>c :!cargo run<cr>
" Fast editing of the .vimrc
nnoremap <leader>e :e ~/.vimrc<cr>
" When vimrc is edited, reload it
autocmd! bufwritepost .vimrc source ~/.vimrc
" key mappings
nnoremap <silent> <CR> :noh<CR><CR>
" smarter moving around
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l
" Statusline
""""""""""""""""""""""""""""""
" Always hide the statusline
set laststatus=1
" Format the statusline
set statusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ CWD:\ %r%{CurDir()}%h\ \ \ Line:\ %l/%L:%c
function! HasPaste()
if &paste
return 'PASTE MODE '
else
return ''
endif
endfunction
" Remove the Windows ^M - when the encodings gets messed up
noremap <Leader>m mmHmt:%s/<C-V><cr>//ge<cr>'tzt'm
noremap <Leader>t :%s/\t/ /ge<cr>
" Remove any trailing whitespace that is in the file
autocmd BufRead,BufWrite * if ! &bin | silent! %s/\s\+$//ge | endif
" Restore cursor position to where it was before
augroup JumpCursorOnEdit
au!
autocmd BufReadPost *
\ if expand("<afile>:p:h") !=? $TEMP |
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ let JumpCursorOnEdit_foo = line("'\"") |
\ let b:doopenfold = 1 |
\ if (foldlevel(JumpCursorOnEdit_foo) > foldlevel(JumpCursorOnEdit_foo - 1)) |
\ let JumpCursorOnEdit_foo = JumpCursorOnEdit_foo - 1 |
\ let b:doopenfold = 2 |
\ endif |
\ exe JumpCursorOnEdit_foo |
\ endif |
\ endif
" Need to postpone using "zv" until after reading the modelines.
autocmd BufWinEnter *
\ if exists("b:doopenfold") |
\ exe "normal zv" |
\ if(b:doopenfold > 1) |
\ exe "+".1 |
\ endif |
\ unlet b:doopenfold |
\ endif
augroup END
" Misc Settings
" Necesary for lots of cool vim things
set nocompatible
" This shows what you are typing as a command. I love this!
set showcmd
" Folding Stuffs
set foldmethod=marker
" Needed for Syntax Highlighting and stuff
filetype on
filetype plugin on
syntax enable
set grepprg=grep\ -nH\ $*
" Cool tab completion stuff
set wildmenu
set wildmode=list:longest,full
" Line Numbers PWN!
set number
" This is totally awesome - remap jj to escape in insert mode. You'll never type jj anyway, so it's great!
inoremap jj <Esc>
nnoremap JJJJ <Nop>
"{{{ Paste Toggle
let paste_mode = 0 " 0 = normal, 1 = paste
func! Paste_on_off()
if g:paste_mode == 0
set paste
let g:paste_mode = 1
echo "Paste ON"
else
set nopaste
let g:paste_mode = 0
echo "Paste OFF"
endif
return
endfunc
"}}}
nnoremap <Leader>p :call Paste_on_off()<CR>
" Up and down are more logical with g..
inoremap <silent> <Up> <Esc>gka
inoremap <silent> <Down> <Esc>gja
" Create Blank Newlines and stay in Normal mode
nnoremap <silent> zj o<Esc>
nnoremap <silent> zk O<Esc>
" Space will toggle folds!
nnoremap <space> za
" 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.
map N Nzz
map n nzz
" Testing
set completeopt=longest,menuone,preview
" Swap ; and : Convenient.
nnoremap ; :
nnoremap : ;
vnoremap ; :
vnoremap : ;
" removing selectmode
set selectmode=
colorscheme default
" easier copy/paste into system clipboard
set mouse= " to enable right-click paste
noremap <Leader>y "*y
noremap <Leader>p "*p
noremap <Leader>Y "+y
noremap <Leader>P "+p
nnoremap <Leader>s${ v$S{
nnoremap <Leader>s$" v$S"
nnoremap <Leader>s$' v$S'
nnoremap <Leader>sw{ ysiw{
nnoremap <Leader>sW{ ysiW{
nnoremap <Leader>ss{ yss{
nnoremap <Leader>s$} v$S}
nnoremap <Leader>sw} ysiw}
nnoremap <Leader>sW} ysiW}
nnoremap <Leader>ss} yss}
nnoremap <Leader>s$( v$S(
nnoremap <Leader>sw( ysiw(
nnoremap <Leader>sW( ysiW(
nnoremap <Leader>ss( yss(
nnoremap <Leader>s$) v$S)
nnoremap <Leader>sw) ysiw)
nnoremap <Leader>sW) ysiW)
nnoremap <Leader>ss) yss)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment