[LINUX] [Vim] Minimum Leader setting to reduce basic operation load

Introduction

――In addition to the editor you usually use, you may use vim several times a day or a month. ――Therefore, there was no problem in the following situations. --Use is only for ** basic operation ** (move / save / end). --Therefore, a few lines or a blank .vimrc. --Complicated operations are manual input or copy. ――This time, in order to further reduce the finger burden of such basic operations, we will describe the settings of Vim's ** Leader ** function.

result

--Shows a description of the resulting .vimrc. --With the following settings, basic operations (move / save / end) can also be used with "** Space + various keys **".

"Set leader to space
let mapleader = "\<Space>"

""Space key+Key operation mapping such as "various keys"
inoremap <Leader>jj <Esc>                         "ESC key
nnoremap <Leader>w :w<CR>                         "Save
nnoremap <Leader>q :q<CR>                         "End
noremap <Leader>a myggVG$                         "Select all(normal)
inoremap <Leader>a <Esc>myggVG$                   "Select all(insert)
nnoremap <silent> <Leader>vr :new ~/.vimrc<CR>    " .open vimrc
nnoremap <silent> <Leader>r :source ~/.vimrc<CR>  " .loading vimrc
noremap <Leader><Leader> <C-w>w                   "Move window
map <leader>n :call RenameFile()<cr>              "Rename the file being edited

"Rename function definition
function! RenameCurrentFile()
  let old = expand('%')
  let new = input('New file name: ', old , 'file')
  if new != '' && new != old
    exec ':saveas ' . new
    exec ':silent !rm ' . old
    redraw!
  endif
endfunction

Contents

What is a leader

-Leader is a special character string and setting that can be assigned multiple key operations. ――In other words, you can create your own key mapping (shortcut) on Vim.

Setting

――When setting, I was conscious of the following. --Starting from the space key. -Try various keys such as "," and select the one that suits you best. --High frequency only setting --Identify frequently used operations. --Do not set more than necessary --Avoid increasing the number too much, as key collisions will occur. --Short standard operations are not basic settings.

--The main contents set in the above result are as follows. (** * Set by focusing on basic operations *) --space key + jj: ESC key --space key + w: save --space key + q: Finish --space key + a: Select all --space key + n: Rename the file being edited - Separate function definition

reference

Recommended Posts

[Vim] Minimum Leader setting to reduce basic operation load
From 0 to Django development environment construction to basic operation