1# Smash into Vim. Andrew Stewart (Pluralsight)
23j Move down three line
33k Move up three lines
4d$ Delete from cursor to the end of the line
5u Undo
6Ctrl-R Redo
7c2/end Change all text from cursor to the BEGINNING of second end
8d2w delete two words
9:h st Get help on any topic eg :h motion (:bd to quit. bd is 'buffer delete')
10i Insert text
11I Insert text at the start of line
12w Move forward one word
13W Treats continuous code as one word, and moves forward to next word
14yy Yank (copy) a line
15p Paste below cursor
16P Paste above cursor
17i Insert text before cursor
18a Append text after cursor
19fN Jump forward to first 'N'
203fN Jump forward to the third 'N'
216l Move forward 6 letters
223w Forward 3 words
23cw Change word
243cw Change 3 words
25r9 Replace with '9'
26:e <filename> edit a file
27:syntax enable
28:set syntax=Apache
29:hidden
30#Tells vim to handle multiple files better
31#Command mode is also known as Normal mode
32d2w d is OPERATOR
33 2 is COUNT
34 w is motion
35# All code folding commands begin with Z
36# -because it looks like a folded sheet of paper
37#One way of overcoming write only file problem
38:w !sudo tee %
39:w !sudo tee example.conf
40#To open a file
41vim -N example.conf
42# The -N means 'not compatible with vi'
43#To Seach for, say, 'All Code'
44/All Code <enter>
45#Puts cursor at the start of the match
46#Replace with '9'
47r9
48#next match
49n
50#Previous match
51N
52#INCREMENTAL SEARCH (Inc Search)
53:set incsearch
54#HIGHLIGHT SEARCH (hlsearch)
55:set hlsearch
56:nohlsearch OR :noh
57#Substitute and Replace
58:%s/search/replace/gc
59#'g' is global
60#'c' is confirm
61#In a regular expression, the period matches any character
62#Line numbers
63:set number
6412G (12-capital 'G') Go to the 12th line
65gg Go to the top of the document
66G (capital 'G') Go to the end of the document
67:pwd Check the current working directory
68V Visual mode (Line)
69v Visual mode (Character)
70yy (yank) Copy
71:b <name> change buffer (try tab arrows as well)
72:bp previous buffer
73P Paste in text BEHIND cursor
74To delete text in V Select text and press d
75To change text in V select text and press c (goes into insert mode)
76Period Pressing the period repeates last command.
77 You will use it all the time!
78:set list (Boolean) lists tabs and end of line characters
79:set nolist
80:set list? Show current value
81:set list& Reset to defaults
82:set softabstop=2
83:set softtabstop?
84:set softtabstop&
85:set sts=2 The abbreviation for softtabstop is sts
86:verbose Using the verbose command when querying
87 an option will tell you where it was set
88:verbose set list?
89:options Brings up vim's options screen
90 to tell which options have been set
91:set See all options differing from default value
92vim commands in .vimrs are just like 'normal commands but just omit
93the colon!!
94:set filetype Tells you what filetype you are using
95:gf Go to file under cursor (Handy for editing code)
96#Where is my .vimrc?
97#see http://stackoverflow.com/questions/10921441/where-is-my-vimrc-file
98:scriptnames list all .vim files that vim has loaded for you
99:e $MYVIMRC open and edit the current .vimrc
100#buffer The contents of a file in memory
101#window A viewport into a buffer
102#Windows Commands
103Ctrl-w s Split window horizontally
104Ctrl-w v Split window vertically
105Ctrl-w j Move focus down
106Ctrl-w k Move focus up
107Ctrl-w c Close a window
108Ctrl-w o Close all but current
109Ctrl-w w Cycle focus (anti-clockwise)
110Ctrl-w W Cycle focus (clockwise)
111Ctrl-w p Focus previous window
112Ctrl-w J Move buffer up one window
113 [ie move windows themselves]
114Ctrl-w K Move buffer down one window
115Ctrl-w h Focus on left window
116Ctrl-w H Move buffer to the left
117Ctrl-w l Focus on the right window
118Ctrl-w L Move buffer to the right
119Ctrl-w t Move to top right
120Ctrl-w b Move to bottom left
121Ctrl-w r Rotate windows clockwise
122Ctrl-w R Rotate windows anti-clockwise
123#A tab holds one or more window
124:tabnew
125:tabedit
126:tabclose
127:tabonly
128:tabnext
129:tabprevious
130:tabfirst
131:tablast
132:tabmove
133#buffers
134:ls List all buffers
135:b3 Go to buffer number three
136# + means bufer with unsaved changes
137# = means read only
138# % is buffer in the current window
139:bn Go to next buffer
140:bp Go to pervious buffer
141:bd Buffer delete (close file)
142:bf Go to the first buffer
143:bl Go to the last buffer
144:ba Open a window for every buffer
145Ctrl-^ Edit the alternate file.
146 Generally this is the last file you edited
147 So if have nipped into another file with, say gf
148 then can go back from whence one came ctrl-caret.
149##Part Two, Pluralsight
150h, l Move forward, back one CHARACTER at a time
151w, b move forward, back one WORD at at a time
152e Move forward to the end of word
153#To move between non-blank entities, use the movement commands in uppercase
1540 Move to the start of a line
155$ Move to the end of a line
156^ Move to the FIRST NON BLANK character of a line
157gm Move to the middle of the line
158#For line lines that are wrapped
159g0 Go to the beginning of line
160g^ First character
161g$ End of line
162gm Middle of line
163#'g' is used a lot in Vim as a modifier
164fx Forward to next occurence of x
165Fx Back to previous occurence of x
166#You can repeat latest character jump with SEMI-COLON
167#A COMMA repeats the last jump in the opposite direction
168j,k Move down, up one line
169#If it helps, think of 'j' as down arrow
170gk Up one screen line
171- Up to Char
172+ Down char
173gj Down screen line
174M Jump to middle of screen
175H Jump to near top of screen
176L Jump to near bottom of screen
177Ctrl-b Scroll back ONE SCREEN
178Ctrl-f Scroll forward ONE SCREEN
179Ctrl-u Scroll back 1/2 SCREEN
180Ctrl-d Scroll forward 1/2 SCREEN
181zt Scroll current line to top of screen
182zz Scroll current line to middle of screen
183zb Scroll current line to bottom of screen
18442G or 42gg Go to line 42
185gg Takes you to the first line of the document
186G Takes you to the last line of the document
187#Marks
188#Vim keeps account of a few marks for you ...
189#To mark the cursor postion, type 'm' followed by letter: 'ma', 'mb'
190#Jump to it later with backtick and the letter
191#or, alternatively, jump to start of the line with the mark with single-quote and letter
192#Lower-case marks are file-specific
193#Upper-case marks are global
194#Ca
195#For
196d't Deletes from cursor position to mark t
197m cursor to the end of the line
198#Speedy way to avoid visual mode!
199:marks Get a list of all marks
200#Vims Mark
201`0-`9 The position of cursor when you exit vim
202 '0 is the most recent
203``, " The position of the cursor before the last jump
204`. or '. The postition of the LAST EDIT
205`` or '' To jump back to previous cursor postion
206 [Can be used to conveniently jump between two spots]
207#Editing text
208i Go into insert mode and insert text at cursor position
209I Go into insert mode and insert text at first non-blank character
210a Move one character to right before going into insert mode
211A Move to end of line before going into insert mode
212o Open a new line below
213O Open a new line above
214r <char you are on> Replaces the character you are on,
215 and goes straight back into 'normal' mode
2162f8 Go to second occurence of '8'
217R Go into Replace mode
218#Use backspace key to restore original text
219#More convenient to use change, c
220c3w Delete 3 words and switch to insert move
221x Delete character under the cursor
222dd or D Delete line
223yy or Y Yanks (copies) a line
224cc or C Change a line (delete text and then go into insert mode)
225J Join two lines [may insert up to two spaces]
2265J Join five lines [may insert up to two spaces]
227gJ Join without inserting spaces
228#Tabs
2292<< Normal mode unindent TWO LINES
2302>> Normal mode indent TWO LINES
231Ctrl-d Insert mode UN-indent a line (remove tab)
232Ctrl-t Insert mode indent (insert a tab)
233( Move to the start of a sentence
234) Move to the end of a sentence
235{ Move to the start of a paragraph
236} Move to the end of a paragraph
237#Can 'bounce' between matching brackets or parens with %
238#VIT, VAT and homologues
239#Operator-Extend_Object
240#V is operator, I extends, T is Object
241#Operators c change
242 d delete
243 y yank
244 v visual
245#Extends i inner-object
246 o all delimiters
247#Object w word
248 W Word
249 s sentence
250 p paragraph
251 t tag
252 " ' { {
253#To change flash[:error] to flash[:id]
254ci]:id<esc>
255#In Visual mode, 'o' toggles which end of selection is active
256#ie, toggles cursor position between beginning and end of selection
257#Extremely useful.
258#Never have to give up and reselect if starting position off by one
259## SEARCH and REPLACE
260/ Search forward from cursor position
261? Search backwards from cursor position
262n next match in search
263N previous match
264# The direction depends on which operator used to start the search
265* Search forward for the curent WHOLE word
266# Search backwards for the current WHOLE word
267g* Search forwards for curent word as PART of word
268g# Search backwoards for current word as PART of word
269/h1/+3 Put cursor on third line after section heading
270/hello/e3 Put cursor Three CHARACTERS after match
271d/bacon/e Delete text from cursor position to end of word 'bacon'
272y?def Yank (copy) text from current position to previous def
273#Substitution
274:[range]/s[ubstitute]/{pattern}/{string}/[flags] [count]
275:%s/bacon/lettuce/gc Replace 'bacon' with lettuce, global, confirm
276#flags
277c confirm
278i ignore case
279I case-sensitive
280g global
281n show number of matches (non-destructive)
282p print matching lines
283# (alt) print matching lines
284% A leading percent searches all lines in the current buffer
285%s/a/b ... for example
286s/a/b Omit '%' to search only the current line
287:.,'a s/bacon/lettuce Replace all occurences of 'bacon' with 'lettuce'
288 from the current line to the 'a' MARK
289.,'a Use a range from cursor to MARK 'a'
290s/a/b Search for 'a', replace with 'b'
291#Specify a line
292. Current line
293+5 5 lines down
294-3 3 lines up
2951 Line 1 of buffer
296$ Last line of buffer
297% All lines in buffer
298't Position of mark 't'
299/pattern/ Next line where pattern matches
300:s/bacon/lettuce/g10 Replace all occuences of 'bacon
301 with 'lettuce' within the next 10 lines only
302#Sometimes easier to go into visual mode
303V Activate visual mode for full lines
30425G Takes you to line 25
305#use 'o' to toggle position of cursor (end/beginning of selection) if necessary.
306#Now type a substitution command starting with a colon
307## Vim gives you the range specifier which represents the selected region
308# :'<,'> (Range specifier)
309# Enter a search pattern
310# :'<,'>s/bacon/lettuce
311# '%' is a shortcut for all lines in current buffer
312#GLOBAL COMMAND
313#can use vim's powerful global command to execute a command
314#on all lines that match a pattern
315#Search and Execute
316:[range]g[lobal]/{pattern}/[cmd]
317#GLOBAL COMMAND
318#can use vim's powerful global command to execute a command
319#on all lines that match a pattern
320#takes a form similar to search-and-replace
321#unlike search, default range is whole buffer
322#Search and Execute
323:[range]g[lobal]/{pattern}/[cmd]
324#normal {command} Execute an extended sequence
325:g/vim/p
326:g/re/p GREP!
327#To show all lines matching the regular expression re
328#This is where the Unix grep command got its name
329# show matches with line numbers
330p same as above
331d delete matching lines
332y yank matching lines
333:g/params[:foo]/# show lines and line numbers where
334 params[:foo] occurs
335:g/^$/d delete blank lines
336:g/pattern/+y Yank line after the ones that match
337#To execute command against lines that DONT match a pattern
338use v instead of g
339Some examples
340:.,+10g/foo/d delete matches from cursor through
341 next ten lines
342:.,'f+2g/foo/# show line numbers through two lines
343 after mark 'f'
344:.,/bar/g/foo/d Deletet lines through next line
345 mathching bar
346#Commands you can execute are not restricted to deleting and
347yanking
348#You can also execute normal mode commands by prefixing
349#your commamds with 'normal
350:g/bacon/normal OBacon is near
351#insert the line 'Bacon is near' above each line that matches
352#the word bacon.
353#Regular Expressions Vim uses in Search
354#In a regular expression, some characters are literal
355some are special.
356# Vim allows you to alter which is which with
357# an option called Magic
358# This has four levals
359Very Magic \v Similar to Perl, Ruby, Python
360Magic \m The default, but awkward
361No Magic \M Rarely used
362Very No Magic \V Rarely used
363#One area where vim's default behaviour is inconsistent and
364confusing
365#Invariably want Very Magic, which is similar to Perl's
366#regular expression syntax
367#It is NOT advisable to set this in .vimrc
368#Technically you can, but vim documentation
369#warns against it
370#How does Magic and Very Magic differ
371Very Magic Magic
372\s \s Whitespace same in both
373() \(\) Escaping Magic only
374{n, m} \{n,m} Quantifiers Escape opening in Magic
375[] [] Character Range No escape
376* *
377+ \+ 1 or many escape in Magic
378= \= Escap in Magic
379#Very Magic corresponds to Unix's egrep
380#Magic corresponds to Unix's grep
381#Magic uses lots of backslashes inconsistently - a disaster!
382#In Very Magic only literal characters are
383#0-9, a-z, A-Z, and underscore
384#Turn on Very Magic with \v
385#Two ways to search
386/\(.y\)\{3}
387/\v(.y){3}
388#To repeat a search
389/Ctrl-r/
390#ie, Ctrl-r, FOLLOWED BY SLASH
391#Ack commands in Vim
392:Ack current_user
393 search all files below your working directory
394:cn Next result
395:cp Previous result
396:cc3 Display third result
397:ccl Close the Quickfix window
398Advanced configuration (start)
399Three basic levels of configuration
400 #1 Basic Configuration
401 #2 Custom key mapping
402 #3 Vimscript plugins
403# Mappings provide a convenient method to enter a sequence of commands
404# with just a few keystrokes
405# Map one set of keystrokes to another. When vim sees the former it
406# acts as if it saw the latter
407#For example
408:vmap > >gv
409# Lets take it apart
410vmap # reassigns a key in visual mode
411> # when you type this ..
412>gv # shift text right, re-select it,
413 # and go bac to visual mode
414#Map Scope
415nmap # Normal mode
416imap # Insert mode
417vmap # Visual mode
418map # Normal, Visual, and operating-pending modes
419map! # Command and insert modes
420# Example
421# Map tab to autocomplete in insert mode
422:imap <Tab> <C-N>
423:imap <S-Tab> <C-P>
424# Now can use tab to bring up autocomplete and tab OR
425# shift-tab throught the options
426# You can examine the value of existing mapping
427# by omitting the final argument
428# Remove a mapping with 'unmap'
429:vunmap >
430# To see all mappings for a mode
431use :map, :vmap, or any other mode map specifies
432# store all mappings in .vimrc
433# Safely Swap Strokes
434# Safely swap colon and semicolon, say
435:nnoremap :;
436:noremap :;
437# So what keystrokes are safe to map?
438# Vim uses most of them already, so need to be careful
439# This is how to decide
440# Do you want to override Vim's behaviour?
441 # 1 yes => do it!
442 # 2 no =>
443 Do you want carpal tunnel syndrome
444 # 1 Yes => Map a meta key
445 # 2 No => Use the Leader and a single key`
446# The map leader is a character whose sole purpose is to
447# prevent your mappings from conflicting with vim's commands
448# Its default value is backslash,
449# but can set it in .vimrc to anything you feel
450# comfortable typing which does not clash
451# Note that you set it differently from other options
452:let mapleader="," # Change the personal hotkey
453# Say, for example, you want to map 'Ctrl-F in insert mode
454# to uppercase the word before the cursor.
455# One way: map Ctrl-F directly
456:map! <C-F> <Esc>gUiw`]a
457# or, if you didn't want to wipe out Vim's default Ctrl-F,
458# which is scroll forward one page,
459# you could take it to your leader
460:map! <Leader> <Esc>gUiw`]a # type exactly as given
461# Try it in INSERT mode by typing backslash -F
462\f
463# A goodie!
464<%= = %=>
465#Abbreviations
466:iab ff firefox
467iab # Declare an abbreviation for insert mode
468 # See also 'ab' for insert, Replace, and
469 # Command-line modes
470ff # What you type
471Firefox # What vim inserts
472# A super-goodie!
473# Some examples
474:ab teh the
475# For misspelled words, can type with impunity and Vim will clean up after you.
476#Folding
477# In the classic Sci-Fi novel 'Dune' by Frank Herbert
478# people learn to travel by folding space and taking a single step
479# onto another planet
480# In vim can operate on a file by folding long ranges of text
481# Novices use folds to put more content on the screen
482# Experts use folds to perform searches or global operations on
483# blocks of code as a single line
484# You may find that your mind does not naturally think in
485# terms of folds. That's OK! Some people find them indespensible
486# and others don't use them at all.
487# Vim Folding strategies
488:set foldmethod=
489 indent # Use spaces or tars to find foldable blocks
490 syntax # Fold on language features (methods, classes)
491 marker # Fold on textual marks
492 diff # Fold unchanged text
493 expr # Custom, code-driven folding
494 manual # Select ranges to fold
495# Default is manual
496# You will quickly tire of manual folding
497# Dan suggests fold by syntax or indent
498# Lets have a look at a Ruby file where folds are managed by
499# the easiest strategy -syntax
500# Will first do ineractively, but all may be stored in .vimrc files
501# As permanent defaults
502# 1 Syntax Folding
503:set foldmethod=syntax
504# or use abbreviation 'fdm'
505zK # Move up a fold
506zj # Move down a fold
507xM # Close ALL folds
508xc # Close a fold
509za # Toggle a fold (on/off)
510zo # Open a fold
511zR # Open ALL folds
512zk # Move back up to the end of the previous fold
513zi # Toggles folding on/off altogether
514zx # Reset folds, if you have 'made a pickle of things'
515 # this folds everything except the fold
516 # at the cursor's current line
517zX # Fold everything again
518# 2 Indent folding
519# A fallback is to let Vim detect blocks elegible for folding
520# by using simple indentation
521# Css is an example of this, which will also highlight a few problems
522# that are easily fixed
523# Open a css file and set the foldmethod to "indent"
524:set foldmethod=indent
525# Won't work as is
526# Two settings are relevant
527:set shiftwidth=2
528:set softtabstop=2
529# Some commands
530shiftwidth=2 # The number of spaces inserted when
531 # reindent operators or automatic indentation are used
532softtabstop=2 # The number of spaces inserted when TAB is hit
533:retab # Replace all tabs with spaces in the current buffer
534#Many aspects of folding are configurable
535:set foldcolumn=2
536# Put into .vimrc
537paper
538# Completion, Filtering, and Copying
539Ctrl-n # Activation completion menu for multiple options
540 # A goodie
541 # Brings up floating window
542 # Move down with Ctrl-n
543 # Move up with Ctrl-p
544 # Arrow keys work too
545 # When desired word is highlighted,
546 # hit enter or just resume typing
547# Filtering
548# sometimes it is worthwhile to filter text through an external program
549# such as unique.
550#Create a file (spamspam.txt) containing the following
551spam
552spam
553milk
554bacon
555eggs
556spam
557#Select all text using Visual mode (shift-V)
558#to run the filter type
559!unique # In general, !<filter>
560 # Four ways to run the unique filter on an entire buffer
561ggVG!uniq
562gg!uniq
563:1,$!uniq
564:%!uniq
565# The range may be established with visual mode or by specifying a range
566in command-line mode (after the colon).
567# Vim has a built on Sort command that can be used to sort
568# on various parts of each line
569# At its simplest, do range-sort, or range-sort! to reverse-sort
570:1,$ sort
571 # Automatic Indentation (Beautiful Code)
572ggVG=
573# An absolute goodie1
574#break it down
575ggVG # Visually select the entire buffer (beginning gg to end G)
576= # Format selection. Can be used on ANY selection
577# use set shiftwidth to adjust the level of indentation
578Text alignment
579V:ce # Center text on page
580# break it down
581V # Activate Visual Mode on lines (and select a region)
582ce # Center selection on screen
583:.,+3ri60 # Select from cursor to 3 lines down
584 # Right align on 60 characters wide
585gQ # Reflow paragraph to 80 characters wide
586# But if you coding, it is easier just to use '='
587# Useful tip
588:set paste # Disable automatic indentation
589# Do this just before you paste
590# Afterwards ...
591set nopaste # To carry on
592# Copying, Yanking and Registers
593#Example Vim's registers are must more elaborate than the standard clipboard
594# available on your standard OS
595# Whenever you delete, change, search, substitute, or yank text
596# vim stores it in a register
597# The register we have been using up to now is the default regiser
598# There are 8 types of register
599# 48 total registers
600# You may delete, change, substitute, search or yank to any register
601# CHOOSE A REGISTER WITH A DOUBLE QUOTATION MARK
602# To yank a link into the register called a, type:
603"ayy
604#Break it down
605"a # Use regiser a
606yy # Yank (copy) current line
607"ap # paste from resister a
608# Named registers
609"a-z
610"A-Z
611#Uppercase registers append new text to their contexts
612"" # The unnamed register. Contains the last deleted text
613# Whenever you delete text with 'd','c', 's' or 'x', or copy it with 'y',
614# Numbered registes 1-9 always contain the text from the last delete
615# or change command, but you'll rarely use them.
616:registers # show content of all registers
617"+ # System clipboard
618# You can repeat your last change or yank with '.'
619# and you may specify a different count if you want ('2.')
620@: # Repeat the last COMMAND LINE COMMAND
621#Break it down
622@ # Exectute text as command
623: # Use the : register as the text of the command
624# Macros
625#An example
626qadWWPjp
627# /Stop recording with q
628qa Start a recording named a
629dW # Delete a word
630w # go forward one word
631p # paste contents
632j # move down one line
633q # quit recoring
634@a # Execute a macro called a
6355@a # Do five times
636# Plugins
637# Vim can be extended with plugins, which are just vim scripts loaded automatically
638# There are two types of plugins
639global # Used for all
640filetype # Specific to a particular type of file
641# Almost all vim plugins are releases in script section of
642# vim.org
643# Most plugins are zip files which you unzip in your .vim dir
644# Pathogen makes things easier
645# Unzip to .vim/bundle directory
646# Check out Tim Pope's plugins (author of 'pathogen',
647# and many others)
648# Tim Pope
649# Git and Fugitive
650# A simple wrapper around the git command-line
651# tool, and a more integrated set of commands for use
652# in vim's command mode
653:Git push # Run commands right in Vim's command area
654:Gstatus # View status in a separate split
655 # Stage and commit within Vim
656# Installed git-fugitive. Possible also need git-vim
657:h fugitive
658:Git # Run an arbitrary git command
659# Rails Vim
660# Tim Pope again
661# Installed
662# Extensive enhancements for working with Ruby-on-Rails
663# Overrides built-in Vim featerus and adds others for navigation, tests, etc
664:gf # Jump to file customized for the Rails directory structure
665:Rake # Run Rake tasks with Vim
666# If your cursor is over a class name such as 'User', hit 'gf' to jump to file
667# for that model.
668# Or, specifically jump to associated files with
669:Rmodel
670:Rcontroller
671:Rview
672# Surround Plugin
673# Tim Pope
674# A super-goodie
675#Manipulate delimites such as XML/HTML tags,
676# quotes, or brackets.
677# Easily add a delimiter around existing text, change the delimiter,
678# or delete it altogether
679 cst # change surrounding tags
680 dst # delete surrounding tags
681 Vs # Add a tag aroud text
682## Addendum tgd
683# to add surounding tag, eg div
684css<div> goodie!
685# To change a h1 to a div, say
686/h1
687cst <enter>
688<div>
689# Note the absence of a colon!
690# similarly (no colon)
691dst
692# To surround with id tag - three ways
693VS<id>
694# 'S' is surround mode
695v$hS<id>
696yss<id> #Normal mode
697# Vim Documentation
698# One of its greatest assets
699:h
700:help
701#Divided into two manuals
702#1 User manual
703#2 Reference manaul (goes into nitty-gritty)
704:h autocmd
705# If not sure wha to look for, use autocompletion
706:h au<tab>
707# Every subject is tagged with one or more keywords in an alternate color
708# If your cursor is on a subject tag, can jump to it with
709Ctrl-] # Ctrl-right-bracket
710Ctrl-t, Ctrl-o # Get back to where you came from
711#How to access local additions
712:h
713#Now scroll down
714# Plugins listed, but ONLY if you have read in docs with helptags
715:Helptags
716# Above (pathogen command) will auto read in helptags for all
717# installed plugins
718# TGD VIM GOODIES
719# To Delete from cursor to the end of file
720dG
721# To delete from cursor to line 885
722d885G
723# To paste at end of line
724# (a super-goodie from here)
725http://superuser.com/a/121364
726:nmap , $p
727# To open every file in a directory
728args: /path/to/dir/*
729# To run a macro on every file in directory
730:bufdo normal @a
731# To add a buffer
732# Insert a carriage return
733# See here: http://stackoverflow.com/a/1585463/499167
734CTRL-V CTRL-M
735#ctrl-v tells vim the next character should be inserted literally
736#ctrl-m is the keystroke for carriage return
737# May also need to use backslash ..
738:s/.../\^V^M/g
739#Remove LEADING white space (A real super-goodie)
740:%s/^\s\+
741# See here...
742http://vim.wikia.com/wiki/Remove_unwanted_spaces
743# Remove all lines except single lines (a goodie)
744:g/^\_$\n\_^$/d
745# Above from stackoverflow
746# Tabs
747# To open each buffer file in new window
748:tab :sball
749:tab sball # at most six
750# without the tab modifier, opens each buffer is split view
751# See here
752http://stackoverflow.com/a/5483206/499167
753#To move between open tabs
754gt, gT, 1gt 2gt
755see here:
756http://stackoverflow.com/a/6832397/499167
757# Add a directory alias
758:command Cdscripts cd /home/username/.../Scripts
759# Must start with capital letter
760# See here
761http://stackoverflow.com/a/20011731/499167
762vim +/Choose <filename>
763vim +2 <filename>
764#Two Goodies
765# See here
766http://www.thegeekstuff.com/2010/11/50-linux-commands/
767# Gridline tips
768# See here: http://stackoverflow.com/a/11846256/499167
769set cursorline
770set cursorcolumn
771#also
772set nocursorline
773set nocursorcolumn
774# Print the name of the current file
775:echo @% #current filename
776# comment out text
777#see here: http://stackoverflow.com/q/1676632/499167
778Ctrl-v
779select block (using up-down-arrows)
780Shift-I (Capital I)
781insert # (or whatever)
782esc
783WAIT A SECOND
784#Command completion in Insert mode
785ctrl-p and ctrl-n
786# make symlink to vimo
787ln -s ~/acs_bash_github/vimod/vimo vimo
788# retab vim goodie
789:%s/\t/ /g
790## To find closing tag
791v # enter visual mode
792it # inner tag
793# and
794vat # outer tag
795# notes on nerd
796nerd #file explorer
797ctrl-n # shortcut
798cs'"
799cs'<p>
800ds"
801cst<li> # change surrounding tag
802yss<p> # surround text by p tag
803VS<p>
804#note that ctrl-n in INSERT mode toggles code completion.
805# Smash into vim, a second look!
806c2/end # delete all code to second occurence of end
807d2w #delete 2 words
808I #inserts text at start of line
809w #forward one words
810<- H
811down J
812L ->
813K Up #(Up Kildare)
814z code-folding (looks like a folded sheep of paper)
815zt #scrole to top
816zz #middle
817zb #bottom
818g-ctrl-g #Where you are in document GOODIE
819ma #mark cursor position
820`a
821`0 #position of cursor when last exited vim.
822`` or '' #to jump back to where you were
823#period is location of last change.
824:marks
825c3w # change three works
826J #join lines
827gJ #join without inserting spaces
828(,) #beginning, end of sentence
829{,} #ditto paragraphs
830Vit
831o - #toggle starting/end position,
832:%s/h1//n
833:%s/h1/gn ## goodie
834to change only current line, leave out the '%'
835V/body
836:g/class/p g/re/p or grep
837:g/class/# show line numbers
838:g/hello/y #yank
839:g/^$/d # delete blank lines
840use :v instead of :g to get lines that do not match pattern.
841ctrl-n (ctrl-n, ctrl-p) code completion
842"0 contains text from last yank!
843so paste with "0p
844V25gg
845V/bacon ## two goodies
846:g/class/p # all lines that match a pattern.
847:g/class/#
848/\vSidebar #Very magic search, equivalent to egrep (where magic is equivalent to grep)
849>> indent in normal mode
850ggVG ! grep hello/
851:ce center
852" double quotation mark selects register
853"ayy
854"ap
855uppercase registers append text to context!
856"" unnamed register #always contains the last deleted text
857yss<id> # surround with id
858# Mallett goodies
859tilde toggles case in normal mode
860gUU # make line uppercase
861g~~ # make line lowercase
862e! revert to last changes
8634y # copies 4
864vim +1064 smash_into_vim_psight_stewart_andrew # open on line number goodie
865vim +/^tilde smash_into_vim_psight_stewart_andrew
866:x # the same as :wq
867# More Mallett Goodies
868:% g/foo/m$ # move all lines containing 'foo' to end of document
869"add # cut from current line to end of the 'a' register
870:127,215 s/foo/bar
871:.,$j # meaning "from the current line to the last line, join them all into one line"
872:% # is synonymous with :1,$ (all the lines)
873:.,$v/bar/d # "from here to the end of the file, delete any lines which DON'T contain the string 'bar' ".
874:% g/foo/s/thomas/Thomas/g # for all lines containing 'foo' substitute 'thomas' with 'Thomas'
875# r! ls -lart # GOODIE read the RESULTS of a command!!
8761G!Gsort # equivalent to :1,$!sort ##
877 ! (bang) and :...! (ex bang) even more powerful than r!
878
879The + command line option to vi and Vim is normally used to start the editing session
880at a given line number. Can follow the + by any valid ex command/expression
881@ executes the contents of a register as if it were a vi or ex command. (obscure)
882vib # select text within parentheses
883vi" # select text within double quotes
884:r! cat article-template-bibtex.tex # read in template
885% match tags (matchit plugin)
886"+p paste from clipboard in vim a
887"+y yank currently selected code into system keyboard. # goodie
888ctrl-x ctrl-o (*works with sass*, code completion)
889edit (*do no specify a file name*) update current file (ie refresh)
890:edit! (force reload, but loose any changes)
891e and e! also work.
892:bufdo e (*Reload all buffers)
893// comment and un-comment // Nerd commenter plugin
894vim [count]<leader>cc //comment
895 [count]<leader>c<space> uncomment
896Indent trick // see https://stackoverflow.com/a/235876/499167
897ma at beginning // mark
898scroll down to end of what you want to indent
899>'a
900windo diffthis
901:vnew
902vim insert empty line after } in compressed css
903:%s/}/\0\r/g
904:%s/}/&\r/g
905see here https://stackoverflow.com/a/15000936/499167
906%s/;/&\r/gc // insert space BEFORE semicolon
907Fold example
908zf11j //fold 11 lines from cursor
909 // https://stackoverflow.com/questions/2362914/fold-function-in-vim
910to fold at curly braces: zf% (a goodie)
911// Paste into substitution command
912yank character or text
913;s/<Ctrl-R><"> // to paste text, Ctrl-R, followed by double quotes.
914// a goodie
915Write a vim script
916// see here
917http://www.east5th.co/blog/2017/10/16/formatting-with-vim-scripts/
918create a script file called myscript.vim
919:%s/dog/cat/g
920now execute
921vim -s myscript.vim file-to-be-edited
922//save vim buffer.
923//Goodie
924or, from within vim, :source script.vim.
925!node %:p // open node with current file //s is current buffer
926// :p full path to curent file
927In INSERT mode: // from 'let vim do the typing' video
928ctrl-R <register name> //insert contents of register
929 // and . <dot> repeats edit
930ctrl-R . // dot register contains whatever text inserted last time in insert mode.
931ctrl-a // also does the same thing (repeats insersion)
932Completion (no plugins)
933ctrl p // < p > for previous //default keybinding for completion
934ctrl n // < n > for next
935ctrl-[ is th same as <esc>
936still in INSERT mode
937ctrl-x ctrl-l //insert a line // A goodie //Make sure set: nopaste !!
938ctrl-x ctrl-f // bring up a list of filenames // another goodie
939ctrl-x ctrl-[ // insert a tag
940 // ctrl-x is completion mode
941ctrl-x ctrl-p // change the quick brown fox to 'the slow ...'
942ctrl-x ctrl-o // omnicompletion // a super goodie
943// see http://georgebrock.github.io/talks/vim-completion/
944CTRL-G // show location in file and file status // goodie from vimtutor
945set hsl is // set highlight seach and incremental search
946 // to turn off until next searh :nohls
947CTRL-D // command completion from COMMAND line // :e CTRL-D
948CTRL-W // Jump to another window
949To substitute from a register:
950s/<c-r>a/<c-r>b/gc //where <c-r> is CTRL-R (which brings up ")
951vim to reverse the postion of two split windows: ctrl-w ctrl-r
952:echom line('$') // echo the number of lines in a file
953to resize vertical splits to same size ctrl-w =
954ctrl-w q delete a split
955Ctrl-w t Ctrl-w H change 2 vertical splits to horizontal
956Ctrl-w t Ctrl-w K change 2 horizontal splits to vertical
957!! better
958:ball
959:vertical ball
960:ec system('wc -c ', "==============")
961:args //get a list of open buffers
962#wincmd
963instead of ctrl-w = ,can use :wincmd =
964#Colorizer
965:set t_Co=256
966:scriptnames
967:r! ls --color -l
968:ColorHighlight
969:ColorClear
970:ColorContrast //recycle through
971echo bufname('myfile') // match pattern #goodie
972let cc = system('ls') // get output of shell command as string