Skip to content

Instantly share code, notes, and snippets.

@abitrolly
Last active November 2, 2021 10:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save abitrolly/417168b9c359bec4bed15cf57f9aa5e1 to your computer and use it in GitHub Desktop.
Save abitrolly/417168b9c359bec4bed15cf57f9aa5e1 to your computer and use it in GitHub Desktop.
Notes from Vim masterclass by @vitaly-zdanevich @ Minsk Hackerspace
-- Modes --
i #
v # visual selection mode
Ctrl+v # visual block selection
ESC
Ctrl+o # in insert mode - run one command in normal mode
-- Open / Navigate --
:vsplit ~/path/to/file
Ctrl+ww # switch windows
:read scp://host/path
:read README.md # insert external file into place
:r README.md
$ vim scp://host/path
$ vim -b file.bin
-- Work with multiple files: Buffers --
:ls # opened buffers (including files)
:e path/to/file # open file in buffers
:e path/to/dir # open file browser
:bd # close buffer
-- Editing --
u # undo
Ctrl+r # redo
-- Helpers --
:set spell
set number
set relativenumber
set nonumber
plugins:
vim-gitgutter
:GitGutterPreviewHunk
:GitGutterUndoHunk
vim-fugitive
:Gblame
vim-airline
-- Vim Registers --
:reg
8yy # copy (yank) 8 lines
p # paste after current line
-- Working with external programs --
!git commit -p
:set wrap
:!python3 -m json.tool -h # run command
:%!python3 -m json.tool # filter current contents with external command
:w !wl-copy # send current file contents to wayland clipboard
:!go fmt % # run command with path of current file
vjjj:!echo # select three lines visually, run echo with content in stdin and replace selection with stdout
-- Working with code --
shift* # jump forward to current word
shift# # jump backward to current word
@: # repeat last command
. # repeat last command too
Ctrl+x+Ctrl+o # omni-complete
Ctrl+x+Crtl+f # complete filename
Shift+F5 # jump to pair
ci( # change everything in ()
di' # remove everything in ''
dis # remove sentence
vis # select inner sentence
/something # search
/something\c # search case-insensitive
"test object"
"buffer"
"window"
"tab"
"location" (lnext)
??? (cnext)
8zf #
[I # where word is mentioned
[i # ???
Ctrl+a # increment int under cursor
Ctrl+x # decrement int
%s/blablabla/gc
shift*v:s//replacement/g # replace selected word in selected block
:Ctrl+r+Ctrl+w # insert word under cursor
q: # list previous command, edit and run it
Shift+j
-- Things for future --
[ ] ??? how to visual select a block and then remove all such blocks?
Unix as IDE
+ ag
+ fd
[ ] onscreen keyboard for tutorials
[ ] follow the leader joint vim session
@abitrolly
Copy link
Author

Setting up LSP for Terraform.

$ git clone https://github.com/autozimu/LanguageClient-neovim.git ~/.vim/pack/plugins/start/LanguageClient
$ curl -sSL "$(curl -s https://api.github.com/repos/juliosueiras/terraform-lsp/releases/latest | grep -o -E "https://.+?linux_amd64.+?.gz")" | tar xvz -C /tmp
$ mv /tmp/terraform-lsp ~/.vim/pack/plugins/start/LanguageClient/bin/
autocmd BufRead *.tf setlocal filetype=terraform

let g:LanguageClient_serverCommands = { 'terraform': ['~/.vim/pack/plugins/start/LanguageClient/bin/terraform-lsp'] }

@abitrolly
Copy link
Author

Vitaly coded https://intelligent-speaker.com/ in vim.

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