vim
Initial Setup
I got into vim from a co-worker. I thought itâs that clunky text editor in your terminal you must use when you have ssh into the linux server. However, Iâve grown to understand vim is much more than a text editor. It can also be an IDE.
When I first used vim, it just looked plain an boring. The black screen with hard to understand shortcuts. There werenât any line numbers. I didnât even know how to exit the damn program for a good 5 minutes.
Then I started figuring it out slowly. Vim has different modes. Vim can do macros. Vim can find things with the same grep commands. And itâs quite expandable with the limitless plugins. Vim is an endless rabbithole where you will get sucked in hours just setting it up. But itâs your customization. And thatâs the beauty of vim.
Best advice - configure vim, and for that matter dotfiles, on your own. Donât blindly copy and paste configurations, because youâll never understand them all.
Modal Editing
Quoted from Nick Nisi
Change the meaning of the keys in each mode of operation
- Normal mode - navigate the structure of the file
- Insert Mode - editing the file
- Visual mode - highlighting portions of the file to manipulate at once
- Ex mode - command mode
Line Numbers
Where are my line numbers? Simply type the following.
:set number
To remove the numbers, you can use this command.
:set nonumber
Configuration
If youâre sick and tired of setting everything up every time you boot up vim, simply place the configuration in your configuration file.
You can find the configuration file at this location.
~/.vimrc
Hereâs a truncated version of my general settings.
syntax enable " Enable syntax highlighting
set tabstop=2 " set the tab stop at 2 spaces
set shiftwidth=2 " set the shift width by 2 spaces
set noexpandtab " do not expand tab
set number " show line numbers
For all of my settings, please view my dotfiles.
Useful Shortcuts
All of the shortcuts can be found on the Vim Wiki Website
Navigation
h
for leftl
for rightj
for downk
for upgg
top of the fileH
top of the windowctrl + e
move window down one linectrl + y
move window up one line
Word Manipulation
w
to go forward to the beginning of next wordb
to go backward to the beginning of previous worde
to go forward to the end of the next worddw
delete word up to the cursor including space between next worddiw
delete word on cursor
Yanking Words
yiw
yank in word
Line Manipulation
0
or^
for beginning of lineshift + i
go to the beginning of line and insert$
go to end of lineshift + a
go to end of line and insertdd
for delete line where cursor is on
Moving lines
:m <line number>
move to after the line number[selected_line_num]m <line_number>
moves the line to after the line number[from_line_num,to_line_num]m <line_number>
moves the selected lines to after the line number
Vim as a Language
Operations and thing you want to do the operation to. :
Editing
u
for undo
Many times, youâll want to know how to copy and paste.
Colon Commands
:help <command>
for help on any command
Plugins
Vim, like other text editors, has an ecosystem of plugins.
- vundle - plugin manager
- nerdtree - file tree
- ctrlp - Fuzzy file finder
- fugitive - git tool
- syntastic - syntax checker/linter
- vim-markdown - markdown syntax, matching rules and mappings, and extensions
Packages
- Sparkup - For html tag completion
Colorize
Iâm currently using Monokai, mainly because it was a default I had with Ruby on sublime. I set it up using vim-monokai, which I actually want to go back and figure out how to hook it up with vundle and have it linked to the repo.
I want to figure out how to do this better, so I placed a todo with the wiki from the vim wikia.
- Todo: https://vim.wikia.com/wiki/Turn_on_syntax_coloring_in_Mac_OS_X
- Todo: talk about colorschemes package
You can change the color scheme within normal mode. Heres how.
:colorscheme <name>
" short version
:colo <name>
" autocomplete
:colo <press tab>
Macros
Repeat last change
.
command repeats the last change made in normal mode.
Itâs like oh my gosh amaze balls.
- TODO https://vim.wikia.com/wiki/Repeat_last_change
- TODO Show an example
Recording
q{register} (do the things) q
Registers
WIP
More Research to go through
- https://yannesposito.com/Scratch/en/blog/Vim-as-IDE/
- coloring vim (as stated above)
- adding more language support
- adding line numbers
- go to top of file (shortcut)
- go to bottom of file (shortcut)
- how to find
- Macros: q command, recording so you donât repeat yourself
- Surround.vim
- mapping escape key to caps lock
- relative numbering
- commenting
- copying and pasting that doesnât get ruined with crazy indents
- Snippets
Helpful Resources
- vim + tmux - Talk at OMG!Code given by Nick Nisi
- vimtutor - type
vimtutor
in your terminal. Quick lessons summaries can be found on this post.
Written by Jeremy Wong and published on .