简体   繁体   中英

Trying to get some mappings to work in vim

There are a few mappings I want to work so I can use VIM more like a regular text editor I found this answer which seems to work for most people, most people not including me.

The idea is to use shift plus arrow keys for selection from normal mode but instead it just causes my curser to get stuck and does nothing else.

Also I'm trying to get multi-cursors working in vim but when I use my key mappings I get this error

E78: Unknown mark

Here are my key-mappings :

" Buffer switching
map <leader>p :bp<CR> " \p previous buffer
map <leader>n :bn<CR> " \n next buffer
map <leader>d :bd<CR> " \d delete buffer

" Increment numbers
nnoremap <A-a> <C-a>
nnoremap <A-x> <C-x>

map <Leader>c :call vroom#RunTestFile()<CR>
map <Leader>s :call vroom#RunNearestTest()<CR>
map <leader>t :A<CR> " \t to jump to test file
map <leader>r :r<cr> " \t to jump to related file
map <leader>E :Explore .<cr> " \E to open file explorer in root
map <leader>e :Explore<cr> " \e to open file explorer in current dir

"nerd tree mapings
map <C-n> <plug>NERDTreeTabsToggle<CR>

"shit plus arrow for selectio mode
" shift+arrow selection
nmap <S-Up> v<Up>
nmap <S-Down> v<Down>
nmap <S-Left> v<Left>
nmap <S-Right> v<Right>
vmap <S-Up> <Up>
vmap <S-Down> <Down>
vmap <S-Left> <Left>
vmap <S-Right> <Right>
imap <S-Up> <Esc>v<Up>
imap <S-Down> <Esc>v<Down>
imap <S-Left> <Esc>v<Left>
imap <S-Right> <Esc>v<Right>

"copy and pasting
vmap <C-c> y<Esc>i
vmap <C-x> d<Esc>i
map <C-v> pi
imap <C-v> <Esc>pi
imap <C-z> <Esc>ui

"multi-cursor mappings"
let g:multi_cursor_next_key='<leader>d'
let g:multi_cursor_prev_key='<leader>s'
let g:multi_cursor_skip_key='<C-x>'
let g:multi_cursor_quit_key='<Esc>'

" Removing escape
ino jj <esc>
cno jj <c-c>
vno v <esc>

" Remove highlights with leader + enter
nmap <Leader><CR> :nohlsearch<cr>

" Ruby hash syntax conversion
nnoremap <F12> :%s/:\([^ ]*\)\(\s*\)=>/\1:/g<return>

I'd also like to add I'm very new to vim beyond basic text editing so I don't doubt that I'm doing things wrong, ignorant to some aspect, etc, so please take that into account when answering.

Pressing shift+left results in D being outputted to the terminal.

Pressing shift+right results in C being outputted to the terminal.

I found the answer (eventually) and solved the other problem as welll.

The solution lies in this answer on a unixstack question.

First you need to tell vim the escape key codes used by your terminal. I have done this here :

function Allmap(mapping)
  execute 'map' a:mapping
  execute 'map!' a:mapping
endfunction

call Allmap('   <ESC>[1;2       <S>')
call Allmap('   <ESC>[1;2A      <S-Up>')
call Allmap('   <ESC>[1;2B      <S-Down>')
call Allmap('   <ESC>[1;2C      <S-Right>')
call Allmap('   <ESC>[1;2D      <S-Left>')
call Allmap('   <ESC>[1;2d      <S-d>')
call Allmap('   <ESC>[1;2s      <S-s>')

Then I just attach the commands I want to the declared key mappings:

map <S-Up> v<Up>
nmap <S-Down> v<Down>
nmap <S-Left> v<Left>
nmap <S-Right> v<Right>
vmap <S-Up> <Up>
vmap <S-Down> <Down>
vmap <S-Left> <Left>
vmap <S-Right> <Right>
imap <S-Up> <Esc>v<Up>
imap <S-Down> <Esc>v<Down>
imap <S-Left> <Esc>v<Left>
imap <S-Right> <Esc>v<Right>


"multi-cursor mappings"
let g:multi_cursor_next_key='<S-d>'
let g:multi_cursor_prev_key='<S-s>'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM