Skip to content

Instantly share code, notes, and snippets.

@ghomem
Last active June 12, 2024 23:27
Show Gist options
  • Save ghomem/816ac97ef7ccd1064e2ffa650b9033e8 to your computer and use it in GitHub Desktop.
Save ghomem/816ac97ef7ccd1064e2ffa650b9033e8 to your computer and use it in GitHub Desktop.
vimrc
call plug#begin()
" List your plugins here
Plug 'preservim/nerdtree'
Plug 'ghifarit53/tokyonight-vim'
Plug 'itchyny/lightline.vim'
Plug 'tpope/vim-fugitive'
Plug 'rodjek/vim-puppet'
Plug 'iberianpig/tig-explorer.vim'
Plug 'mhinz/vim-grepper'
call plug#end()
" NERDTree
"
" focus on file if a file is given as an argument, else focus starts on the tree
" updates CWD as you open a file
" Enter opens the file retaining focus on the tree, sets CWD implicitly
" Space expands a directory, sets CWD
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * NERDTree ~/ | if !argc() == 0 || exists('s:std_in') || !v:this_session == '' | wincmd p | endif
autocmd BufEnter * silent! lcd %:p:h
autocmd FileType nerdtree nmap <buffer> <CR> go
autocmd FileType nerdtree nmap <buffer> <Space> ocd
" Vim grepper (results on quickfix window -qf)
"
" Enter on grep results opens the file retaining focus on the result
" q exits the grep results
autocmd FileType qf nnoremap <buffer> <CR> <CR><C-W>p
autocmd FileType qf nnoremap <buffer> q :x<CR>
" Colorscheme
set termguicolors
let g:tokyonight_style = 'night' " available: night, storm
let g:tokyonight_enable_italic = 1
colorscheme tokyonight
" Lightline
let g:lightline = {
\ 'colorscheme': 'wombat',
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'gitbranch', 'readonly', 'filename', 'modified' ] ]
\ },
\ 'component_function': {
\ 'gitbranch': 'FugitiveHead'
\ },
\ }
" Key mappings
nnoremap <silent> <C-Right> <c-w>l
nnoremap <silent> <C-Left> <c-w>h
nnoremap <silent> <C-Up> <c-w>k
nnoremap <silent> <C-Down> <c-w>j
" open tig with current file
nnoremap <C-t> :TigOpenCurrentFile<CR>
" open tig with Project root path
nnoremap <C-y> :TigOpenProjectRootDir<CR>
" open tig blame with current file
nnoremap <C-b> :TigBlame<CR>
" toggle NERDTree to go "full screen", + toggle line numbers
nnoremap <F5> :NERDTreeToggle<CR>
nnoremap <F6> :set number!<CR>
" recursive search with Control+F
nnoremap <C-f> :GrepperGrep<Space>
" quit the usual way
nnoremap :q :qa
nnoremap :wq :wqa
" Misc
" uncomment if you want numbers on by default
" set number
" terminal opening below + mapping
set splitbelow
nnoremap <F4> :let $VIM_DIR=expand('%:p:h')<CR>:terminal<CR>cd $VIM_DIR<CR>clear<CR>
" this is somehow necessary for remapping to work reliably
set notimeout
@ghomem
Copy link
Author

ghomem commented May 21, 2024

Make sure your system contains the amazing tig utility:

sudo apt install tig

And now execute as a normal user:

curl -s https://gist.githubusercontent.com/ghomem/84549becd122453f27f7278cae19b91a/raw/ | bash

Note that the script that gets executed is this:

https://gist.github.com/ghomem/84549becd122453f27f7278cae19b91a

Now you are ready to use vim with the following shortcuts:

  • SPACE - expands a directory / opens a file moving the focus
  • ENTER - opens a file keeping the focus on the file tree
  • control + t - opens tig for the current file
  • control + b - opens tig blame for the current file
  • control + y - opens tig for the directory of the current file
  • control + f - greps recursively for a certain word
  • control + arrow - switches to the window in the corresponding direction
  • control + w w - cycles across the windows clockwise
  • F4 - opens a terminal in the directory of the current file
  • F5 - sets to current buffer window to full screen
  • F6 - toggles the line numbers
  • :q - closes all buffers and quits

Note: to move from the terminal to the other windows control + w w must be used. The remaining shortcuts are ignored by the terminal.

@ghomem
Copy link
Author

ghomem commented May 22, 2024

The result should look like this:

GOGztuHW4AAxf_9
GOGzeHTWIAMjfPA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment