If you are completely new to using the command line, checkout the background document.
Clone the repo and run the setup script
% git clone https://github.com/kenjyco/dotfiles && bash ./dotfiles/setup.bash
- the
setup.bashscript will create a backup copy of your existing dotfiles, then create symbolic links to the settings in this repository - plugins for Vim are also downloaded and installed
% cd dotfiles
% git submodule init && git submodule update
% cd vim/bundle/Vundle.vim
% git checkout master
% git pull
% cd ../../..
% git add vim/bundle/Vundle.vim
% git commit
Provided by vim-tmux-navigator to move between tmux panes and vim splits with the same key binding
Ctrl+h=> LeftCtrl+j=> DownCtrl+k=> UpCtrl+l=> RightCtrl+\=> Previous split
Note: When using :term or :vert term in vim (version 8+) to open a
terminal split the Ctrl + <direction> shortcuts will not work... you will
need to Ctrl + w first, then h/j/k/l
Ctrl+b,%to split the current pane verticallyCtrl+b,"to split the current pane horizontallyCtrl+b,Spaceto cyle current window through preset layoutsCtrl+b,{to move the current pane up one spotCtrl+b,}to move the current pane down one spotCtrl+b,;to switch to the previously active paneCtrl+b,pto switch to the previously active windowCtrl+b,!to move the current pane to a new windowCtrl+b,zto toggle zoom state of current paneCtrl+b,wto choose the current window (across all sessions) interactivelyCtrl+b,:to get to bring up the tmux command promptbreak-paneto move the current active pane to a new window/tab
Make 2 vertical splits, then make them equal widths
Ctrl+b,%Ctrl+b,%Ctrl+b,Space
The first preset layout is evenly spaced vertical splits
.
- Sometimes when writing code and there are multiple splits in the same file,
the syntax highlighting can appear messed up in the other split(s) when adding
a string (something with double quotes)... fix it with
:syntax sync fromstart - Sometimes when writing long lines (with textwidth and autoindent set) for a
bullet point in markdown files, after you hit Enter/Return, your cursor will
not be at the place where you would like to start the next bullet point... use
Ctrl+dto move the cursor to the correct position - If you have lines of text that need to get reformatted
- select text to reformat using
v(and then move cursor to highlight with k/j/h/l)- or use
Shift+vanywhere on a long line to select the entire line
- or use
- reformat with
gqcommand
- select text to reformat using
Ctrl+]to jump to code definitions (as long as you have run the separatectagscommand that generates thetagsfile)Ctrl+oto jump back to where you were before (whether jumping to code definitions or just searching text or doing find/replace)- Use
:set spell/:set nospellto enable/disable spell checking]sto move to the next misspelled word[sto move to the previous misspelled wordz=while cursor is on a misspelled word to get suggestionszgwhile cursor is on a misspelled word to add it to the dictionary (in the~/.vim/spell/directory)zugto undo adding a word to the dictionary
- Use "visual mode" to select text while in normal/command mode
vto start character-wise selection and use navigation keys (h/j/k/l) to expand the selectionVto start line-wise selection and use down/up navigation keys (j/k) to expand the selectionctrl+vto start block-wise selection and use navigation keys (h/j/k/l) to expand the selection- Once the selection is made, you can use nearly any command (including colon-commands)
- Use
\Cat the start of a search pattern when you want to use case-sensitive matching - Use
\|between multiple search patterns to match them- example:
/\Crh.[a-z_]*(\|self.[a-z][a-z_]*(\|ih.[a-z_]*(\|dh.[a-z_]*((to find rh. calls that arent rh.REDIS, self. calls that aren't private methods, ih., and dh. calls)
- example:
- https://github.com/christoomey/vim-tmux-navigator#usage
- https://github.com/wesQ3/vim-windowswap#howto
- Note: default
<leader>key in vim is\ - Navigate to window you want to move and press
<leader>ww - Navigate to window you want to swap with and press
<leader>wwagain
- Note: default
- https://github.com/will133/vim-dirdiff#usage
- From CLI:
vim -c "DirDiff dir1 dir2"
- From CLI:
- https://github.com/tpope/vim-fugitive#fugitivevim
- This is a
gitwrapper- Also see screencast series: http://vimcasts.org/blog/2011/05/the-fugitive-series/
:Gstatusto see git status- if you move cursor to an unstaged file and press
-it willgit addthe file - if you move cursor to a staged file and press
-it willgit resetthe file - can also use
-in visual mode<Shift>v, thenjorkto select lines above/below; then press-to either stage or unstage selected files
- if you move cursor to an unstaged file and press
<Shift>pit willgit add -pthe file (to let you select part of the file to stage) - if you press
<Enter>while on a file, it will open it in a split below theGstatuswindow- use
:Gdiff(mentioned below)
- use
- use
ccto open:Gcommitfrom the status window (which opens a split with commit buffer)
- if you move cursor to an unstaged file and press
:Gdiffto compare diff of current window's file- use
:closeon thefugitive://...window when done - Note: You can select lines of text in visual mode (v ..) and
copy to the
fugitive://window and:w!to stage different parts of the file!- No need to
git add -p - Verify in another terminal with
git diff --cached(or another split using:Git diff --cached)
- No need to
- use
:Gdiffsplit!on a file with merge conflicts will open 3 vertical splits with vimdiff:Gblameto open interactive vertical split withgit blameoutput:Gmove <newname>togit mv current <newname>:Git [args]to run arbitrary git command- i.e.
:Git checkout -b some-branchand:Git push -u origin some-branch - use
:closeon thefugitive://...window when done
- i.e.
:Gsplit <branch>:%to vimdiff current file with version on another branch (or at another commit) - Note: in vim%is a shortcut to current file:Gedit <branch>:path/to/fileto open a file from any branch in a read-only buffer:Ggrep 'some text' <branch>togit grepa pattern in a particular branch
- This is a
- https://github.com/tpope/vim-obsession#obsessionvim
- This is to help manage "sessions" (open splits, window positions, etc)
:Obsessto start recording session file (toSession.vimin current directory)- can also pass a filename to save as (to keep separate for 4k.vim, etc)
:qato quit vim and close all windows- Load session with
vim -RS Session.vimor:sourceit :Obsess!to remove the session file