Skip to content

Instantly share code, notes, and snippets.

@retsi101
Created November 22, 2020 23:52
Show Gist options
  • Save retsi101/e680c91393e9231226df13a1255faf13 to your computer and use it in GitHub Desktop.
Save retsi101/e680c91393e9231226df13a1255faf13 to your computer and use it in GitHub Desktop.
"Beware of descriptions copied right from vim's :help.
let $VIMFILES=$HOME."/vimfiles"
source $VIMFILES/my_diff.vim
"=====================================================
"=============== Functionality Section ===============
"=====================================================
set encoding=utf-8
set fileformat=unix
set path=**
set nohidden
let $TMPDIR=$HOME."/tmp"
"These .swp files are quite messy to have on your workspace.
"The intent of this is to redirect where they are created.
set backupdir=.backup/,~/vimfiles/.backup/
set directory=.swap/,~/vimfiles/.swap/
set undodir=.undo/,~/vimfiles/.undo/
"Don't go to the beginning of line when switching
"between files.
set nostartofline
"Copies Vim yank into Windows' clipboard.
set clipboard=unnamed
"Allows to move past beyond line endings.
set virtualedit=all
"Disable line wrapping
set nowrap
"When a file is changed outside Vim, just reload it without asking.
set autowrite
set autoread
"Automatically change to the opened file's directory.
"set autochdir
"Keep indent from previous line.
set autoindent
"Use the appropriate number of spaces to insert a <Tab>.
set expandtab
"Align case statements like if statements.
set cinoptions=l1
set tw=78
"Number of spaces that a <Tab> counts for while performing editing
"operations, like inserting a <Tab> or using <BS>. It "feels" like
"<Tab>s are being inserted, while in fact a mix of spaces and <Tab>s is used.
set softtabstop=4
"Number of steps to use when using (auto)indent.
set shiftwidth=4
"Number of spaces that a <Tab> in the file counts for.
set tabstop=4
"Handles serveral file types, type switching and indent options.
source $VIMFILES/filetype.vim
"Do not highlight search.
"set nohlsearch
set hlsearch
"Dynamically show search command pattern matching.
set incsearch
"Ignore case on search.
set ignorecase
"Enable mouse for all modes.
set mouse=a
"Keep the window width when windows are opened or closed.
"Needs equalalways enabled.
set nowfw
"Show '--More--' after long commands.
set more
"This basically prevents backspace from... breaking....
set bs=indent,eol,start
"Not really that opinionated, but it does make a difference
"when you use plugins like NERDCommenter, or simply by the
"fact that it is so easier to reach.
let mapleader=","
"Some of these are quite self explanatory
nnoremap ; :
inoremap jj <ESC>
"REDO with U instead of CTRL+R.
nnoremap U <C-r>
"Switch buffers more easily.
map gt :bn<CR>
map gT :bp<CR>
map tt :tabnext<CR>
map tT :tabprev<CR>
"Close buffers more easily.
noremap ,q :bp\|bd #<CR>
"When entering new lines, this prevents losing
"indentation.
inoremap <CR> <CR>x<BS>
"Go to the matching brace by hitting TAB.
nnoremap <Tab> %
vnoremap <Tab> %
"Move 5x farther by holding CTRL.
nnoremap <C-h> 5h
nnoremap <C-j> 5j
nnoremap <C-k> 5k
nnoremap <C-l> 5l
vmap <C-h> 5h
vmap <C-j> 5j
vmap <C-k> 5k
vmap <C-l> 5l
nnoremap <F6> :e! ~\notes.md<CR>
"Quickly edit VIMRC.
nnoremap ,ev :vsplit $MYVIMRC<CR>
nnoremap ,so :so%<CR>
nnoremap <C-p> :find
"Show command completions.
set wildmode=longest,list,full
"Ignore unimportant files.
set wildignore+=*.bmp,*.gif,*.ico,*.jpg,*.png,*.ico,*.o,*.cbp,node_modules/*,dist/*,bower_components/*,obj/*,bin/*,*.depend,*.layout,*.svg,*.meta,*.class,*.*~
"Goto next and previous errors.
map <silent> cn :cnext<CR>
map <silent> cp :cprevious<CR>
"Some functions that might help, not the best code though.
function! OpenRelatedCFile()
let l:this_file = expand('%')
let l:this_ext = strcharpart(l:this_file, strlen(l:this_file)-1, 2)
let l:this_file_name = strcharpart(l:this_file, 0, matchend(l:this_file, '.'.l:this_ext)-2)
if l:this_ext == 'c'
if bufexists(expand('%:p:h') . '\' . l:this_file_name . '.h') == 0
exec 'edit ' . l:this_file_name . '.h'
else
exec 'b ' . l:this_file_name . '.h'
endif
elseif l:this_ext == 'h'
if bufexists(expand('%:p:h') . '\' . l:this_file_name . '.c') == 0
exec 'edit ' . l:this_file_name . '.c'
else
exec 'b ' . l:this_file_name . '.c'
endif
endif
endfunction
map gm :call OpenRelatedCFile()<cr>
"==============================================
"=============== Plugin Section ===============
"==============================================
filetype plugin on
if filereadable($VIMPLUGRC)
source $VIMPLUGRC
endif
runtime macros/justify.vim
"=====================================================
"==============================================
"=============== Visual Section ===============
"==============================================
syntax off
"Commands can do pretty much everything those file
"menu options can. They aren't really needed and
"from a aesthetic perspective, it's nice to have
"some extra space on the view.
set go-=m
set go-=L
set go-=T
set go-=r
"Always show the status line.
set laststatus=2
function! MakeLight()
color default
hi Normal guifg=#202020 guibg=#f0f0f0
endfunction
function! MakeDark()
color evening
hi StatusLineNC gui=none guifg=white guibg=grey10
hi StatusLine gui=none guifg=black guibg=#dddddd
hi EndOfBuffer guibg=grey20
hi MoreMsg guifg=magenta
endfunction
nnoremap ,l :call MakeLight()<CR>
nnoremap ,d :call MakeDark()<CR>
if has("gui_running")
set gfn=Noto_Mono_For_Powerline:h8
set lines=36
set columns=143
call MakeDark()
hi Cursor guibg=black guifg=white
else
set scrolljump=-50
hi MatchParen ctermbg=0 ctermfg=4
endif
"Removes all trailing white spaces.
nnoremap <leader>W :%s/\s\+$//<cr>:let @/=''<CR>
"----------------------------------------------------
nnoremap ,cd :cd %:p:h<CR>
set backupcopy=yes
set tags=tags;/
let s:hidden_all = 0
function! ToggleHiddenAll()
if s:hidden_all == 0
let s:hidden_all = 1
set noshowmode
set noruler
set laststatus=0
set noshowcmd
else
let s:hidden_all = 0
set showmode
set ruler
set laststatus=2
set showcmd
endif
endfunction
nnoremap <S-h> :call ToggleHiddenAll()<CR>
function! LoadTemplate()
execute 'read ~\tt\' . expand('<cword>') . '.t'
normal b
normal daw
normal dd
endfunction
nnoremap ,f :call LoadTemplate()<CR>
"FileType ???
autocmd Filetype javascript setlocal expandtab tabstop=2 shiftwidth=2 softtabstop=2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment