Some tricks in Vim
Using Vim jump markers
-
Set the markers: You can set a marker by
m+ a letter, e.g.,mj) -
Clear all marks:
In normal mode, type:
-
Clear just the
jmark:If you only want to remove the
jmark, type: -
Jump to a mark you've set:
You can use either
'jor`jto jump to a specified mark.
Getting a split with copy of the text in a new buffer
The reason why this is a bit unusual is that:
-
:vsdoes not duplicate the current file or the current buffer. It simply creates a second Window (a viewport) that looks at the exact same Buffer (the text loaded in memory). -
:saveas main_copy.cpp: This does two things. First, it writes the current buffer to disk asmain_copy.cpp. Second, it renames the buffer itself tomain_copy.cpp.
Method 1: Read Alternate File
-
Type
:vnew(for horizontal split, usenew)This opens a vertical(horizontal) split with a brand new, empty, unnamed buffer. Because you just left your original file, Neovim quietly stores your original file as the "alternate file".
-
Type
:0r #:rmeans "read".#is the shorthand for the alternate file. The0tells Neovim to paste the text starting at line 0 (the very top).
Method 2: The "%" Register Trick (If you want to save the cooy immediately)
If you want to immediately create the physical copy on your hard drive (like main_copy.cpp) and open it in a split, you can use the % shorthand, which represents the current file's name.
-
Type
:w %:r_copy.%:e:wwrites the text to a new file, but unlike:saveas, it keeps your current buffer attached to the original file.%is your current file (e.g.,main.cpp).:rstrips the extension (leavingmain)._copyadds your custom text (leavingmain_copy)..%:egrabs just the original extension (adding.cpp). -
Type
:vs %:r_copy.%:eThis opens a vertical split for that newly created file.