Vim

Detailed Vim shortcut key encyclopedia

The Vim configuration uses SPF-13 as an example

Project address: github.com/spf13/spf13…

The installation of Vim

  • Linux, *nix, Mac OSX Installation

The easiest way to install spf13-vim is to use our automatic installer by simply copying and pasting the following line into a terminal. This will install spf13-vim and backup your existing vim configuration. If you are upgrading from a prior version (before 3.0) this is also the recommended installation.

Requires Git 1.7+ and Vim 7.3+

curl https://j.mp/spf13-vim3 -L > spf13-vim.sh && sh spf13-vim.sh
Copy the code

If you have a bash-compatible shell you can run the script directly:

sh <(curl https://j.mp/spf13-vim3 -L)
Copy the code

This process will be relatively long, including the plug-in download and installation, this process nearly one hour

  • Installing on Windows

On Windows and *nix Git and Curl are required. Also, if you haven’t done so already, you’ll need to install Vim. The quickest option to install all three dependencies (Git, Curl, Vim and spf13-vim) is via Chocolatey NuGet. After installing Chocolatey, execute the following commands on the command prompt:

Install with cmd.exe(run as admin mode)

@powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%; %ALLUSERSPROFILE%\chocolatey\bin"
Copy the code
C:\> choco install spf13-vim
Copy the code

All the way to Y, it’s going to take about 2 hours

Introduction to Vim plug-in

  • Vundle(The best plugin manager)

Vundle is an excellent system built on the same principles as Pathogen, but with an integrated plugin management system that is Git and Github aware.

spf13-vim uses the Vundle plugin management system to have a well organized vim directory (Similar to mac’s app folders). Vundle also ensures that the latest versions of your plugins are installed and makes it easy to keep them up to date.

  • NERDTree(file navigation)

NERDTree is a file explorer plugin that provides “project drawer” functionality to your vim editing. You can learn more about it with :help NERDTree or checkout my post on NERDTree.

Use Ctrl+e to toggle NERDTree

  • ctrlp(fast file finder)

Ctrlp replaces the Command-T plugin with a 100% viml plugin. It provides an intuitive and fast mechanism to load files from the file system (with regex and fuzzy find), from open buffers, and from recently used files.

Use Ctrl+p to toggle Ctrlp

  • neocomplcache(autocomplete++)

NeoComplCache is an amazing autocomplete plugin with additional support for snippets. It can complete simulatiously from the dictionary, buffer, omnicomplete and snippets. This is the one true plugin that brings Vim autocomplete on par with the best editors.

Use Ctrl+n to toggle neocomplcache

  • Tagbar(tag generation and navigation)

spf13-vim includes the Tagbar plugin. This plugin requires exuberant-ctags and will automatically generate tags for your open files. It also provides a panel to navigate easily via tags

Use ,tt to toggle neocomplcache

The solution to invalid ctags on the Mac side

brew.sh/

Github.com/universal-c…

Github.com/universal-c…


On Windows, if you want to switch to a different drive letter, use

:NERDTree D:\\

To jump to a directory


Preview: To preview markdown format you need to install bluecloth gem

Preview: To Preview Markdown format you need To install bluecloth gem

Solution:

  • sudo gem install redcarpet

  • sudo gem install bluecloth

Problems with Linux

can’t find header files for ruby at /usr/lib/ruby/include/ruby.h

Sudo apt-get install ruby-dev

The tag file cannot be found

Use: 1. Generate the tag file (CMD to the project directory) in the current directory (run the command after the $prompt):$ctags-r. -r indicates recursive. Tag files are generated for c files in the current directory and its subdirectories. The last one is in the current directory. After running the current directory, there will be a file tag, which is the index file of the C tag. 2. Jump 1) Open a TAB file with vim 2) CTRL +] find the label definition where the cursor is 3) CTRL + T go back to the label before jump 3. Window display method command Tagbar toggle opens the corresponding method window display Note: To run vim at this time, it must be in"tags"Run in the directory where the file resides. Otherwise, run it and you won't find it"tags"File, and need to be used in vim":set tags="The command set"tags"File path. For a slightly larger project, you might open Vim in any directory, but generating a tags file in each directory is not a good idea, so what's the solution? To do this, add a line to.vimrc:settags=tags; / This is to tell Vim to look in the upper directory if the tags file cannot be found in the current directory.Copy the code

Window shortcut keys

Ctrl+w+w

Close the split screen

Close the current window. Ctrl+W c to close the current window or exit Vim if there is only one left. Ctrl+W qCopy the code

After opening multiple Windows, how to quickly switch

: Buffers list :bn Next :bp The previous :b17

Cancel the search for the remaining borders

set: nohlseach
Copy the code

VIM edits multiple lines

Vim enters multi-line editing mode: <ESC> and then press CTRL+V to enter Visual Block mode (column editing). Move the cursor to the beginning of a line, enter Visual Block mode, select a line with up or down keys, press I (capital letter of I), and enterThen press the 
      
        key to add the ## at the beginning of multiple lines. You can also add fixed characters at fixed positions on multiple lines.
      If you want to delete these##, enter Visual Block mode, select these ## and press D.
Copy the code

Global search Ack

The keys function
? Display keyboard mapping
o Open the file
O Open the file and close the QuickFix window
go Preview the file, but stay focused on the ACK search results
t Open the file in a new TAB
T Open in a new TAB but do not switch to that TAB
h Split screen open
H The split screen opens, but the focus remains on the ACK search results
v Open vertical split screen
gv The vertical split screen opens, but the focus remains on the ACK search results
q Close the QuickFix window

windows

You can install Chocolatey on Windows using Chocolatey by first opening the CMD window as an administrator and then running the following command

@"% SystemRoot % \ System32 \ WindowsPowerShell \ v1.0 \ powershell exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%; %ALLUSERSPROFILE%\chocolatey\bin"
Copy the code

After the installation

choco install ack
Copy the code

Mac

brew install ack
Copy the code

If there is garbled code

'perl'It is not an internal or external command, nor a runnable programCopy the code

Download and install ActivePerl, and configure environment variables to solve this problem. Download address

SpaceVim

Gruvbox is used for this color scheme

If you want to change to this theme

  • Added to the vimrc file
 "Gruvbox theme"
Plugin 'morhetz/gruvbox'
set bg=dark
colorscheme gruvbox

Copy the code

Then search globally for let g:airline_theme and change it to the following colors to prevent color mismatch

  let g:airline_theme = 'dark'
Copy the code

After running PluginInstall on the terminal, restart it

How to open the most opened file

Start Vim with Ctrl+ O

tag

Use tags to move quickly. When you reach the mark, you can use Ctrl+ O to return to the original position. Ctrl+ O and Ctrl+ I are much like back and forward in the browser.

M {a-z}: marks the position of the cursor, a local mark, used only for the current file.

M {a-z}: marks the position of the cursor, A global mark. After the tag, exit Vim and restart with the tag still in effect.

‘{a-z}: Moves to the marked position.

‘{a-z}: Moves to the beginning of the marked line.

‘{0-9} : returns to the last position left when vim was closed last [2-10] times.

‘: Move to the last edit position.” That’s fine, but ‘accurate to columns, and’ accurate to rows. If you want to jump to an older location, press C-O, and jump to the newer location with c-i.

‘” : Move to where you left off last time.

‘.: Move to the last changed place.

:marks displays all tags.

:delmarks a b – Delete marks A and B.

:delmarks a-c — Delete marks A, B, and C.

:delmarks a c-f — Delete marks A, C, D, E, f.

:delmarks! – Deletes all flags in the current buffer.

: Help mark-motions

Failed to paste the system clipboard in Linux. Procedure

– First, check to see if the Vim version supports Clipboard

vim --version | grep "clipboard"
Copy the code

Clipboard has a small minus sign in front, indicating that it is not supported.

If not, you need to install vim with the graphical interface, or recompile Vim
sudo apt-get install vim-gnome
Copy the code

After the installation is complete, execute again:

vim --version | grep "clipboard"
Copy the code

Clipboard is supported

So our goal is to copy to the system clipboard by selecting the content and typing the command “+y

The same goes for pasting into a particular register. For example, “+p “copies the system clipboard contents to vim (in non-edit mode).

Quick jump to Easymotion plug-in

vim-easymotion

The configuration is as follows:

let g:EasyMotion_smartcase = 1
"let g:EasyMotion_startofline = 0 " keep cursor colum when JK motion
map <Leader><leader>h <Plug>(easymotion-linebackward)
map <Leader><Leader>j <Plug>(easymotion-j)
map <Leader><Leader>k <Plug>(easymotion-k)
map <Leader><leader>l <Plug>(easymotion-lineforward)
Map 
      
       < Leader>. 
       
        (easyMotion -repeat)
       Copy the code
  • Usage 1: Jump to the position before and after the current cursor (w/b)
  • Usage 2: Search jump (s)
  • Usage 3: Row level jump (JK)
  • Usage 4: Inline jump (HL)
  • Usage 5: Repeat the previous action (.)

advice

1. F and T can also be used, but it is recommended to simplify, a W/B to go the world.

2. If you don’t use s often, you can change the s key, nmap S (EasyMotion -S), so that you only need to type s to search for a quick jump (ocD means can’t hold….) See the official document for details

3. Default as a shortcut to this plug-in is actually quite good, it seems that no other plug-ins will cause conflict, but also can configure a whole set, OCD is very satisfied

4. 2/ N characters can be configured to search the jump, more accurate, on demand (personally think too complex unnecessary) documents and documents

5. This plugin focuses on the jump, there is no need to do the search

Vim window switching

CTRL + W +(lowercase HJKL), “non-linear” jump: CTRl_W + T (top: left, +b: bottom, right), P: preview: Set mouse=a all = all

Ctrl_w + R: the window itself, not the mouse pointer moves clockwise (down, to the right), r: the mouse pointer moves counterclockwise (up, to the left) ctrl_w+x: the corresponding position of the window is reversed. Note that Windows must be corresponding. If they are not, they cannot be exchanged. For example, if there is a large window on the left and two small child Windows on the right, the left and right cannot be exchanged.

The window itself moves and is “maximized” in size… Note that this can be understood in terms of Windows window “bezel” maximization, where H and L are maximized to the left or right bezel display; JK is maximized by edging up or down. After maximization, you cannot operate the restore window again, and it is not necessary

Adjust the horizontal/vertical dimensions of the window? Use CTRL + W to combine >, < adjust horizontal size, and + – to adjust vertical size. This is fine tuning. You can also use pure commands :resize +/ -n, or vertical resize +/ -n (command shorthand is supported, but only if the command is uniquely identified. It’s usually done at 5,10,15, 20 intervals… Too small to make sense)

In addition to these mouse adjustment/traversal methods, there is also the problem of closing child Windows. In addition to commands, there are also window closing methods: CTRL + W + q(quit), C (close), o(other), etc.

VIM annotation plugin NerdCommEnter

nerdcommenter

Use: 3, \c< space > If part of the selected area is commented, the selected area will be uncommented, otherwise, the selected area will be reversed. 4, \cm will comment the selected area with a pair of comment characters. The preceding comment adds a comment to each line. 5, \ci inverts the comment by uncommenting the comments in the selected area and adding a comment to the non-comments. 6, \cs adds a sexy comment. 9. \cA jumps to the end of the line to add a comment and enters the edit mode. 10. \cA transforms the way of the comment, for example: /**/ and // 11, \cl \cb left-align and left-align it, left-align it, left-align it, left-align it, left-align it, left-align it, left-align it, left-align it, left-align it, left-align it, left-align it, left-align it, left-align it, left-align it, left-align it, left-align it, left-align itCopy the code

It requires Vim 7.3.885 or later with Lua support (” + Lua “)

Solution 1: brew Install vim --with-lua Solution 2: brew Uninstall vim brew Install luajit Brew Install vim -- with-LuajitCopy the code

For more articles, go to github.com/itgoyo/500D…

Please follow me on Github:itgoyo