Skip to content

Instantly share code, notes, and snippets.

@phips
Created December 29, 2024 18:12
Show Gist options
  • Save phips/adfce992088773abc605af17c365d28d to your computer and use it in GitHub Desktop.
Save phips/adfce992088773abc605af17c365d28d to your computer and use it in GitHub Desktop.
A useful vimrc
" Use Vim settings, rather then Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
" vim: set ts=2 sw=2 et:
set nocompatible
" Install vim-plug if we don't already have it
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
call plug#begin('~/.vim/plugged')
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-surround'
Plug 'mattn/emmet-vim'
Plug 'preservim/nerdtree'
Plug 'Xuyuanp/nerdtree-git-plugin'
Plug 'bling/vim-airline'
Plug 'phelipetls/vim-hugo'
Plug 'hail2u/vim-css3-syntax'
Plug 'gko/vim-coloresque'
" *never used it; but useful to know?* Plug 'godlygeek/tabular'
" *no longer maintained* Plug 'scrooloose/syntastic'
" old language stuff I no longer use
" Plug 'tangledhelix/vim-kickstart'
" Plug 'pearofducks/ansible-vim'
" Plug 'kballard/vim-swift'
call plug#end()
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
set nobackup " do not keep a backup file, use versions instead
set history=50 " keep 50 lines of command line history
set ruler " show the cursor position all the time
set showcmd " display incomplete commands
set incsearch " do incremental searching
" Don't use Ex mode, use Q for formatting
map Q gq
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
syntax on
set hlsearch
endif
if has("terminfo")
if &term =~ "tmux"
set termguicolors " Enable true color support if your terminal supports it
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
elseif &term =~ "screen"
set t_Co=256
elseif &term =~ "xtermc"
set t_Co=256
elseif &term =~ "xterm-256color"
set t_Co=256
elseif &term =~ "xterm"
set t_Co=8
set t_Sf=^[[3%p1%dm
set t_Sb=^[[4%p1%dm
else
set t_Co=8
set t_Sf=^[[3%dm
set t_Sb=^[[4%dm
endif
endif
" Tab stops at 4 characters. Expand to spaces always.
let mytab=4
execute "set ts=".mytab
execute "set shiftwidth=".mytab
" Only do this part when compiled with support for autocommands.
if has("autocmd")
" http://www.reddit.com/r/vim/comments/2x5yav/markdown_with_fenced_code_blocks_is_great/
au! BufRead,BufNewFile *.md set filetype=markdown
au! BufRead,BufNewFile *.json set filetype=json
let g:markdown_fenced_languages = ['css', 'erb=eruby', 'javascript', 'js=javascript', 'json=javascript', 'xml', 'html', 'yaml']
" 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!
" textwidth for various filetypes
autocmd FileType text setlocal textwidth=78
" YAML file editing, change tab stops
autocmd FileType yaml setlocal ts=2 sw=2
" 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).
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
augroup END
" templates
autocmd BufNewFile * silent! 0r $HOME/vim/%:e.tpl
else
set autoindent " always set autoindenting on
endif " has("autocmd")
" The ultimate reference - https://vim.wikia.com/wiki/Best_Vim_Tips
"
" Perl compiling stuff. Groovy.
set makeprg=$VIMRUNTIME/tools/efm_perl.pl\ -c\ %\ $*
set errorformat=%f:%l:%m
map <F10> :mak<CR>
" When using CTRL-W_ only status lines will show for minimised windows.
set winminheight=0
set expandtab
" Smart searching - overrides ic when caps are used in search pattern
set ic
set smartcase
" status line, only if >1 window. 2=always
set laststatus=2
set bg=dark
" completion
set wildmenu
set wildmode=list:longest,full
" shift-Y yanks to EOL, not whole line
map Y y$
" matchit
source $VIMRUNTIME/macros/matchit.vim
" windows only
" let g:netrw_scp_cmd='c:\apps\pscp.exe -q -batch -agent -l USERID'
" let g:netrw_ssh_cmd='c:\apps\plink.exe'
if has('perl')
command! ReverseWord call ReverseWord()
function! ReverseWord()
perl << EOF
$curword = VIM::Eval('expand("<cword>")');
$reversed = reverse($curword);
VIM::Msg("$curword => $reversed");
VIM::DoCommand("norm lbcw$reversed");
EOF
endfun
nmap <Leader>r :ReverseWord<CR>
endif
function! TitleCase()
let l:save_cursor = getcurpos()
s/\v<(.)(\w*)/\u\1\L\2/g
call setpos('.', l:save_cursor)
endfunction
" default Leader is \
nn <Leader>ev :sp $MYVIMRC<cr>
nn <Leader>rv :so $MYVIMRC<cr>
nnoremap <leader>n :NERDTreeFocus<CR>
nnoremap <C-n> :NERDTree<CR>
nnoremap <C-t> :NERDTreeToggle<CR>
nnoremap <C-f> :NERDTreeFind<CR>
" vim-markdown
set nofoldenable
" lines to read for vim settings
set modelines=5
" if syntastic was installed
" set statusline+=%#warningmsg#
" set statusline+=%{SyntasticStatuslineFlag()}
" set statusline+=%*
" let g:syntastic_always_populate_loc_list = 1
" let g:syntastic_auto_loc_list = 1
" let g:syntastic_check_on_open = 1
" let g:syntastic_check_on_wq = 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment