I just installed neovim. But I not sure how to auto indent bash code. I have vim configured so that it can autoindent code. My ~/.vimrc has the following code. But it seems that they will not be loaded with neovim.

fun BenIndent()
  let oldLine=line('.')
  normal gg=G
  execute ':' . oldLine
map -- :call BenIndent()<CR>

Neovim doesn't use the location ~/.vimrc for its configuration file. Try moving, copying, or symlinking your file to the location:

  • I didn't see that bit :|
    – kadekai
    Mar 6 '18 at 9:50

I think you should use the function as below:

function! BenIndent()
  let oldLine=line('.')
  normal! gg=G
  execute ':' . oldLine
nnoremap -- :call BenIndent()<CR>

Should work now I think.

Here's what I changed from your function:

fun -> function! BenIndent()  " I've just always known functions to be declared this way, I may be wrong
  let oldLine=line('.')
  normal -> normal! gg=G      " the ! sign tells vim to not remap the provided keys, e.g. if you map g to :q then vim would quit when indenting!
  execute ':' . oldLine
endfun -> endfunction         " just my convention
map -> nnoremap -- :call BenIndent()<CR> " noremap tells vim not to use remapped keys and n is for mapping in normal mode only, if you want in other modes change n with v, i or c etc.

prefix of -> is your code and suffix is mine.

  • I would reformat/reword this to highlight what you actually changed (i.e. fun -> function and map -> nnoremap. Your answer would also be better if you explained why these changes are necessary/good. Mar 5 '18 at 7:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.