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.bash
script 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
,Space
to 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
,p
to switch to the previously active windowCtrl
+b
,!
to move the current pane to a new windowCtrl
+b
,z
to toggle zoom state of current paneCtrl
+b
,w
to choose the current window (across all sessions) interactivelyCtrl
+b
,:
to get to bring up the tmux command promptbreak-pane
to 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
+d
to 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
+v
anywhere on a long line to select the entire line
- or use
- reformat with
gq
command
- select text to reformat using
Ctrl
+]
to jump to code definitions (as long as you have run the separatectags
command that generates thetags
file)Ctrl
+o
to jump back to where you were before (whether jumping to code definitions or just searching text or doing find/replace)- Use
:set spell
/:set nospell
to enable/disable spell checking]s
to move to the next misspelled word[s
to move to the previous misspelled wordz=
while cursor is on a misspelled word to get suggestionszg
while cursor is on a misspelled word to add it to the dictionary (in the~/.vim/spell/
directory)zug
to undo adding a word to the dictionary
- Use "visual mode" to select text while in normal/command mode
v
to start character-wise selection and use navigation keys (h/j/k/l) to expand the selectionV
to start line-wise selection and use down/up navigation keys (j/k) to expand the selectionctrl
+v
to 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)
- 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>ww
again
- 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
git
wrapper- Also see screencast series: http://vimcasts.org/blog/2011/05/the-fugitive-series/
:Gstatus
to see git status- if you move cursor to an unstaged file and press
-
it willgit add
the file - if you move cursor to a staged file and press
-
it willgit reset
the file - can also use
-
in visual mode<Shift>v
, thenj
ork
to select lines above/below; then press-
to either stage or unstage selected files
- if you move cursor to an unstaged file and press
<Shift>p
it willgit add -p
the 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 theGstatus
window- use
:Gdiff
(mentioned below)
- use
- use
cc
to open:Gcommit
from the status window (which opens a split with commit buffer)
- if you move cursor to an unstaged file and press
:Gdiff
to compare diff of current window's file- use
:close
on 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:Gblame
to open interactive vertical split withgit blame
output:Gmove <newname>
togit mv current <newname>
:Git [args]
to run arbitrary git command- i.e.
:Git checkout -b some-branch
and:Git push -u origin some-branch
- use
:close
on 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/file
to open a file from any branch in a read-only buffer:Ggrep 'some text' <branch>
togit grep
a 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)
:Obsess
to start recording session file (toSession.vim
in current directory)- can also pass a filename to save as (to keep separate for 4k.vim, etc)
:qa
to quit vim and close all windows- Load session with
vim -RS Session.vim
or:source
it :Obsess!
to remove the session file