Vim : How to remap <c-h> in insert mode? - editor

I want to map the following for navigation in insert mode :
<c-h> # Move left
<c-j> # Move down
<c-k> # Move up
<c-l> # Move right
So, I added the following to my .vimrc :
inoremap <c-h> <left>
inoremap <c-j> <down>
inoremap <c-k> <up>
inoremap <c-l> <right>
Now,
Left doesn't work [ Instead it deletes the left character ]
Right works !
Up works !
Down works !
As I understand, <c-h> by default deletes left character. But I am unable to override it.
I even tried this :
inoremap <c-j> <down>
inoremap <c-k> <up>
inoremap <c-l> <right>
" Re-mapping <c-h> for insert-mode
autocmd InsertEnter call RemapCtrlH()
function RemapCtrlH()
iunmap <c-h>
inoremap <c-h> <left>
endfunction
But even this didn't work either.

So, I added the following to my .vimrc :
inoremap <c-j> <down>
inoremap <c-j> <down>
inoremap <c-k> <up>
inoremap <c-l> <right>
Your first and second lines are the same! Change the first to the following:
inoremap <C-H> <Left>
You can confirm your mapping with:
:verbose imap <C-H>
Update following update to question, comments and acceptance
I've left the information above untouched, but to respond to the comments...
The clash with your "autoclose" plugin explains why this worked in the editor but not in $MYVIMRC. You could work around this by putting your mapping in a plugin file in an after-directory.
I used title case for the <C-H> mapping consistent with the notation in the official documentation. The documentation states:
The case of {char} does not matter; thus CTRL-A and CTRL-a are equivalent.
Should you wish to map CTRL-Shift-H, use inoremap <C-S-H> instead.
I'm delighted :verbose map helped you to track down the source of your problem! :verbose is a handy tool when debugging Vim scripts.
Good luck!

My solution:
inoremap <c-p> <up>
inoremap <c-n> <down>
inoremap <c-b> <left>
inoremap <c-f> <right>
Advantage: they're widely used in all programs.

Related

NeoVim: Show cursorline only in active panes without messing other plugin-related text inputs

Currently I'm using the following vim autocmd to show the cursorline only in active pane (i.e. current buffer) as follows.
augroup CursorLine
au!
au VimEnter,WinEnter,BufWinEnter * setlocal cursorline
au WinLeave * setlocal nocursorline
augroup END
But it's also showing cursorline in plugin-related-buffers since it's forcing to set cursorline in current-buffer with WinEnter. For example, there's cursorline in search box of Telescope Find Files as shown in the picture below.
Cursorline in text input box
I tried to hide cursorline just only for Telescope plugin with ‌autocmd VimEnter,WinEnter,BufWinEnter Telescope* setlocal nocursorline and it doesn't work, cursorline is still appearing.
So, is there any workaround to avoid this issue?
Thanks in advance.
Edit: 1. I just tried an experiment autocmd VimEnter,WinEnter,BufWinEnter NvimTree* setlocal nocursorline and cursorline in NvimTree plugin has disappeared as I wanted. So, why isn't this working in Telescope?? Or do we need to address the issue in different way??
Edit 2. I just tried using TelescopePrompt instead of Telescope and it didn't work.
Use FileType in your autocmd to disable cursorline for Telescope plugin :
au FileType Telescope setlocal nocursorline
You can also use the same configuration for your other plugin-related-buffers.

Neovim lua cannot change color in autocmd

I'm transitioning my neovim configuration from vimscript to lua. The following code is intended to change the color of the message area as the mode changes, as I did in the old configuration, but it is having no effect.
Changing the MsgArea any color I want outside the autocmd works fine
These debug messages print as expected when I change mode, so I know the autocmd is working
The MsgArea color does not change with the mode
I'm new to lua. Can you identify a syntax or conceptual problem here?
local normal_fg="#00ff00"
local normal_bg="#202020"
local insert_fg="#202020"
local insert_bg="#00ff00"
vim.api.nvim_set_hl(0,'MsgArea',{fg=normal_fg,bg=normal_bg,bold=true}) -- works fine
vim.api.nvim_create_autocmd( "InsertEnter",{ pattern="*",
callback=function()
vim.api.nvim_set_hl(0,'MsgArea',{fg=insert_fg,bg=insert_bg,bold=true}) -- no effect
print("inverted the colors") -- works fine
end
})
vim.api.nvim_create_autocmd( "InsertLeave",{ pattern="*",
callback=function()
vim.api.nvim_set_hl(0,'MsgArea',{fg=normal_fg,bg=normal_bg,bold=true}) -- no effect
print("back to normal") -- works fine
end
})
NVIM v0.7.2

Migrate Vim/Vimscript for asynchronously running external editors to Lua/Neovim

In my Vim's configuration file init.vim I am using code, that sets a default viewer for practically any kind of file suffix. Here I will demonstrate only an example for .md files:
let g:netrw_browsex_viewer="-"
function! NFH_md(f)
call asyncrun#run("", "cwd", "typora " . a:f)
endfunction
First paragraph makes sure to choose the function based on suffix of the file ("URI under cursor"). Second paragraph shows a function whose name i.e. NFH_md implies that this is the function opened when .md file is in the "URI under the cursor". Inside this function there is an call that opens an external program typora asynchronously so that I am still able to continue using Vim.
If you want to know more use :help netrw_browsex_viewer.
I tried porting the mentioned Vim script to Neovim & Lua but I only managed to port first line:
vim.g.netrw_browsex_viewer="-"
For I don't know, how to properly port the second paragraph. This is why for now I just use Vimscript source code like this:
vim.api.nvim_exec(
[[
function! NFH_md(f)
call asyncrun#run("", "cwd", "marktext " . a:f)
endfunction
]],
false
)
But I would love to translate all the code to Lua - Could anyone help a bit to translate this remaining Vimscript code to Lua?

Having eruby-nxhtml-mumamo-mode be set every time I open a .html.erb file

I downloaded nxhtml and unzip it. I then put this in my .emacs file.
(add-to-list 'load-path "~/nxhtml/util")
(require 'mumamo-fun)
(setq mumamo-chunk-coloring 'submode-colored)
(add-to-list 'auto-mode-alist '("\\.rhtml\\'" . eruby-nxhtml-mumamo-mode))
(add-to-list 'auto-mode-alist '("\\.html\\.erb\\'" . eruby-nxhtml-mumamo-mode))
When I open an .html.erb file it does not have the proper mode set(and therefore improper syntax highlighting). I know the require statement is running correctly b/c I can manually set aquamacs to eruby-nxhtml-mumamo-mode and if I comment out the require line I can't even switch to that mode. I have even tried replacing the eruby...-mode with other modes like c++-mode and other modes I know work and that doesn't work either.
So is my problem with the regex? I am not sure. Any help would be appreciated.
Try the following:
(add-to-list 'auto-mode-alist '("\\.rhtml?$" . eruby-nxhtml-mumamo-mode))
(add-to-list 'auto-mode-alist '("\\.html?\\.erb$" . eruby-nxhtml-mumamo-mode))
It appears you had an escaped comma at the end of your expressions.
I don't know if the lack of the 'l' in your header was intentional or not, but the question mark should account for it either way. The dollar sign anchors the expression to the end of the string, and are nominally optional, but it's nice to be explicit.

how to disable bold font in vim?

i've removed all references to bold (gui=bold, cterm=bold, term=bold) in the color syntax file slate.vim but i still see some bolded text. for example in a python file, the keywords class, def, try, except, return, etc. are still in a bold blue font.
also how to disable bold in status messages, like "recording" or "Press ENTER or type command.."?
Instead of removing =bold references you should replace them by
gui=NONE
cterm=NONE
term=NONE
Put the following line in the .vimrc file.
set t_md=
Just in case someone is using iTerm on MacOS and also has this problem (since the same color scheme and vimrc settings under Ubuntu never gave me this problem), there is an option in iTerm under Preference->Profiles->text that stops iTerm from rendering any bold text. That's an easier and quicker fix.
try also to remove the occurrences of standout.
You can find highlighting groups by doing the following:
:sp $VIMRUNTIME/syntax/hitest.vim | source %
You can find where colors and font options were defined by doing:
:verbose highlight ModeMsg
(replace ModeMsg by your highlight group)
In vim, :scriptnames shows a list of all scripts loaded at vim startup.
In bash, grep -rl "=bold" $VIM shows a list of all files in your vim folder that contain that string. If $VIM is not set, or if you have a space in the filename (windows users), cd to your vim directory and run the command with . in place of $VIM
You can compare the two lists to find the files that need editing. Replace =bold with =NONE as stated in the previous answer by Tassos.
A side note: :hi Shows all current highlight formatting, with examples to demonstrate how the syntax is actually being rendered. In my case, standout had no effect on whether the font appeared bold.
Here's the easiest method:
In /colors directory enter sed -i 's/=bold/=NONE/g' *.vim
In /syntax directory enter sed -i 's/=bold/=NONE/g' *.vim
This will replace every instance in all those *.vim files.
For me, it was a tmux/screen issue. https://unix.stackexchange.com/questions/237530/tmux-causing-bold-fonts-in-vim led me to TERM=screen-256color which resolved my problem. It might also be worth exploring the difference when TERM is xterm vs. xterm-256color.
#devskii 's answer in the comment, above, works great for me. I'm going to include specifically the unbolding part here & wiki the answer. (If #devskii would like to make it an answer, I'll delete this... if I can delete wiki answers.)
Put this in your .gvimrc and smoke it:
" Steve Hall wrote this function for me on vim#vim.org
" See :help attr-list for possible attrs to pass
function! Highlight_remove_attr(attr)
" save selection registers
new
silent! put
" get current highlight configuration
redir #x
silent! highlight
redir END
" open temp buffer
new
" paste in
silent! put x
" convert to vim syntax (from Mkcolorscheme.vim,
" http://vim.sourceforge.net/scripts/script.php?script_id=85)
" delete empty,"links" and "cleared" lines
silent! g/^$\| links \| cleared/d
" join any lines wrapped by the highlight command output
silent! %s/\n \+/ /
" remove the xxx's
silent! %s/ xxx / /
" add highlight commands
silent! %s/^/highlight /
" protect spaces in some font names
silent! %s/font=\(.*\)/font='\1'/
" substitute bold with "NONE"
execute 'silent! %s/' . a:attr . '\([\w,]*\)/NONE\1/geI'
" yank entire buffer
normal ggVG
" copy
silent! normal "xy
" run
execute #x
" remove temp buffer
bwipeout!
" restore selection registers
silent! normal ggVGy
bwipeout!
endfunction
autocmd BufNewFile,BufRead * call Highlight_remove_attr("bold")

Resources