What improvements can I do to my .vimrc to improve my experience in NeoVim? - config

Here's my .vimrc
call plug#begin('~/.vim/plugged')
Plug 'dart-lang/dart-vim-plugin'
Plug 'natebosch/vim-lsc'
Plug 'natebosch/vim-lsc-dart'
Plug 'tpope/vim-sensible'
Plug 'vim-airline/vim-airline'
Plug 'w0rp/ale'
Plug 'pearofducks/ansible-vim', { 'do': './UltiSnips/generate.sh' }
Plug 'ncm2/ncm'
Plug 'roxma/nvim-yarp'
Plug 'ncm2/ncm2-bufword'
Plug 'ncm2/ncm2-path'
Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app && yarn install' }
Plug 'codota/tabnine-vim'
Plug 'Chiel92/vim-autoformat'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'jiangmiao/auto-pairs'
Plug 'autozimu/LanguageClient-neovim', {
\ 'branch': 'next',
\ 'do': 'bash install.sh',
\}
" Plug 'valloric/youcompleteme'
let g:lsc_server_commands = {'dart': 'dart_language_server'}
call plug#end()
let g:ale_fixers = {
\ 'javascript': ['eslint']
\}
let g:ale_sign_error = '❌'
let g:ale_sign_warning = '⚠️'
let g:lsc_enable_autocomplete = v:true
let g:lsc_auto_map = v:true
let g:ale_fix_on_save = 1
let g:ale_javascript_prettier_use_local_config = 1
let g:ale_javascript_eslint_options = '-c ~/.eslintrc'
let g:ale_lint_on_enter = 0
let g:ansible_unindent_after_newline = 1
autocmd BufEnter * call ncm2#enable_for_buffer()
set completeopt=noinsert,menuone,noselect
" set softtabstop=2
" set shiftwidth=2
" set expandtab
set expandtab
" show existing tab with 2 spaces width
set tabstop=2
set softtabstop=2
" when indenting with '>', use 2 spaces width
set shiftwidth=2
nnoremap <A-Down> :m .+1<CR>==
nnoremap <A-Up> :m .-2<CR>==
inoremap <A-Down> <Esc>:m .+1<CR>==gi
inoremap <A-Up> <Esc>:m .-2<CR>==gi
vnoremap <A-Down> :m '>+1<CR>gv=gv
vnoremap <A-Up> :m '<-2<CR>gv=gv
set statusline=%<%f\ %h%m%r%{kite#statusline()}%=%-14.(%l,%c%V%)\ %P
set laststatus=2
let g:python3_host_prog='/home/thebozzkg/anaconda3/bin/python3'
au BufWrite * :Autoformat
let g:airline#extensions#tabline#enabled = 1
let g:airline_detect_spell=1
let g:airline_left_sep = ''
let g:airline_left_alt_sep = ''
let g:airline_right_sep = ''
let g:airline_right_alt_sep = ''
let g:airline_symbols.branch = ''
let g:airline_symbols.readonly = ''
let g:airline_symbols.linenr = '☰'
let g:airline_symbols.maxlinenr = ''
let g:airline_symbols.dirty='⚡'
nnoremap <ALT-Left> :tabprevious<CR>
nnoremap <ALT-Right> :tabnext<CR>
Some notes about me:
I don't use hjkl I use the arrow keys (pls don't insult me)
I write Javascript, Dart, Markdown, YAML, JSON, C, & C++ (so far) in neovim (I'm switching from VSCode)
Most of the stuff I have I literally copied from GitHub and some Vim wikis
I have Anaconda installed
I'm using Ubuntu Linux 20.04 (if that matters)
For some reason, I don't know which plugins are doing it but my autocompletion keeps messing up my files (editing YAML files and saving them are absolute torture, some indentation is lost with almost all files) and also crashing (TabNine)
Can someone help me with this mess?

Welcome to Vim!
I think most new vim users have been there. I certainly have! I wanted a
'vim as python IDE' and copied a whole bunch of stuff from every blog under the
sun into my vimrc almost immediately after installing vim.
After some time spent fighting with all the settings, plugins and remaps I
didn't understand, I decided to go through my vimrc, line by line and comment
out anything I didn't understand (nearly all of it).
Then I used this more minimal vim for a while and whenever I decided I had a
need for a certain feature, I checked the largely commented vimrc for anything
that looked related, and/or googled for that particular feature only. Often
you find that there is a built in method to do it with the core vim commands,
and if not, then there are a lot of solutions for the problem (and often, you
find that there is an even more powerful way that didn't occur to you - these
are good days).
But the key is to not try and coerce vim into a huge IDE overnight! Let it
happen gradually and things will make more sense, and you'll end up with a
vimrc that you understand and therefore be in a position to add to it and tweak
it.
The last thing I'll say is to recommend the following books:
'Learn VimScript the Hard Way' by Steve Losh
'Practical Vim' by Drew Neil, and his accompanying screencast series.
(Also there is The Primagean who does high quality youtube tutorials)
Having said all that, and acknowledging that an objective answer can't be given
for your question, here is a minimal vimrc which has a few plugins and settings
that do simple but very useful things (but do read up on them to understand how
they work!):
"==== PLUGINS =================================================================
set nocompatible " don't try to be compatible with Vi
filetype plugin indent on " use default plugins
call plug#begin('~/.vim/plugged')
" plugins I would put in a new vimrc
Plug 'tpope/vim-sensible'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-commentary'
Plug 'vim-scripts/ReplaceWithRegister'
Plug 'flazz/vim-colorschemes'
"==== CUSTOM CONFIGURATIONS ===================================================
"- general settings -----------------------------------------------------------
set encoding=utf-8
set linebreak " wrap long lines at char in 'breakat' (default " ^I!#*-+;:,./?")
set nowrap " don't wrap lines by default
set expandtab " expand tabs into spaces
set tabstop=4 " a tab is the same as 4 spaces
set softtabstop=4 " when I hit <tab> in insert mode, put 4 spaces
set shiftwidth=4 " when auto-indenting, use 4 spaces per tab
set autoindent " when creating a new line, copy indent from line above
set incsearch " show matches for patterns while they are being typed
set smartcase " with both on, searches with no capitals are case insensitive...
set ignorecase " ...while searches with capital characters are case sensitive.
set spell spelllang=en
set nospell " don't hightlight misspellings unles I say so
set lazyredraw " don't redraw screen during macros (let them complete faster)
set t_Co=256 " use full colours
syntax enable " highlight special words to aid readability
colorscheme zenburn
" THIS NEXT BIT I DEBATED INCLUDING - IT'S MY PERSONAL PREFERENCE AND BY
NO MEANS 'NECESSARY' AND COULD SAFELY BE EXCLUDED... BUT I JUST HATED THE
BLOCK CURSOR IN INSERT MODE SO MUCH...
"- cursor behaviour (make cursor blink for insert mode, block for normal mode)
augroup cursor_behaviour
autocmd!
" reset cursor on start:
autocmd VimEnter * silent !echo -ne "\e[2 q"
" cursor blinking bar on insert mode
let &t_SI = "\e[5 q"
" cursor steady block on command mode
let &t_EI = "\e[2 q"
" highlight current line when in insert mode
autocmd InsertEnter * set cursorline
" turn off current line hightlighting when leaving insert mode
autocmd InsertLeave * set nocursorline
augroup END
Good luck!

Related

Clipboard not shared between wsl and windows 10 neovim

I have a problem when using the paper clip in wsl, when using neovim when pressing yy to copy a line I can only paste it in neovim, but what I would like to do is paste it without any complications in a page or a txt file in windows with notepad, that was just an example, I would also like to be able to copy from windows and paste with the letter p in neovim directly, before I could do this, with the same previous configuration file, however I had to format my windows by virus.
Here my configuration file:
"set directory
set runtimepath^=~/.vim runtimepath+=~/.vim/after
let &packpath = &runtimepath
"files
so ~\.config/nvim/.vim/plugins.vim
so ~\.config/nvim/.vim/plugin-config.vim
so ~\.config/nvim/.vim/maps.vim
set list
syntax enable
"show line number and relative number
set nu
set rnu
set numberwidth=1 "better show the numbers
"copy and paste with the mouse
set mouse=a
"enable copy and paste 'yy, p'
set clipboard=unnamed
"shows the pressed
set showcmd
"Show current column
set ruler
"perform indent
set smartindent
"does not create external files
set noswapfile
set nobackup
"Seaching
"moves to result as you type
set incsearch
"distinguish between upper and lower case when searching
set smartcase
"Highlight matches
set hlsearch
"Unless they contain at least one capital letter
set ignorecase
"tab of 4 spaces
set noexpandtab
set tabstop=4 shiftwidth=4
"Scheme
colorscheme gruvbox
let g:gruvbox_contrast_dark = "hard"
"set background=dark
"highlight Normal ctermbg=NONE
set laststatus=2
set noshowmode
" React
"set backupcopy=yes
"Fonts
set guifont=Hurmit_Nerd_Font_Mono:h12
"When a file is edited its indent file is loaded
filetype plugin indent on
"Encoding
set encoding=utf-8
Before I only required this:
"enable copy and paste 'yy, p'
set clipboard=unnamed
Or maybe I am missing some packages in Ubuntu to achieve it, if so could you tell me please? I already searched like crazy and I only found a solution is the following:
" WSL yank support
let s:clip = '/mnt/c/Windows/System32/clip.exe' " change this path according to your mount point
if executable(s:clip)
augroup WSLYank
autocmd!
autocmd TextYankPost * if v:event.operator ==# 'y' | call system(s:clip, #0) | endif
augroup END
endif
However, this does not work in reverse, that is, if I copy something from windows, I cannot paste it in wsl
I have ubuntu 20.04, the same one I had before formatting, and I also have xclip, tmux, zsh, python3, python2, nodejs installed
Finally when doing a :%y I get this error, I also tried to put the let g: clipboard ..., but it doesn't work either
Neovim delegates clipboard access to external application. As you don't have any it cannot work. This is clearly written to you in the picture above.
Windows clip is not supported, because it cannot read from clipboard; xclip won't work, because it needs X-server to work (isn't it obvious from its name?) and so on.
Normally Neovim makes use of win32yank to access Windows clipboard. So try to download it and put somewhere on WSL path.
let g:clipboard = {
\ 'name': 'win32yank-wsl',
\ 'copy': {
\ '+': '/path-file/win32yank.exe -i --crlf',
\ '*': '/path-file/win32yank.exe -i --crlf',
\ },
\ 'paste': {
\ '+': '/path-file/win32yank.exe -o --lf',
\ '*': '/path-file/win32yank.exe -o --lf',
\ },
\ 'cache_enabled': 0,
\ }

How to write a text prompt in Nim that has readline-style line editing?

readLine() doesn't support line editing and recalling previous commands, eg:
while true:
var name: string = readLine(stdin)
echo "Hi, ", name, "!"
Has no editing. But if I compile that and wrap it in rlwrap:
$ rlwrap read_test
It works as I hope. with editable and recallable lines, provided by the readline library.
readLineFromStdin() almost works, but doesn't support ctrl+d, it returns an empty string on ctrl+d, which is indistinguishable from a newline.
How can I do this in pure Nim? Thanks!
Ctrl+D is an EOF "signal", and thus you can catch the EOF in your input:
while not endOfFile(stdin):
var name: string = readLine(stdin)
echo "Hi, ", name, "!"
The procedure readLineFromStdin (https://github.com/nim-lang/Nim/blob/version-1-2/lib/impure/rdstdin.nim#L54) is not that complex, and you can re-write your own adding the above code to it.
While #xbello's answer is correct, if you want to use a package, we ended up using https://github.com/jangko/nim-noise, which supports C-d handling and loads of other features.

perl6 Is there a way to do editable prompt input?

In bash shell, if you hit up or down arrows, the shell will show you your previous or next command that you entered, and you can edit those commands to be new shell commands.
In perl6, if you do
my $name = prompt("Enter name: ");
it will print "Enter name: " and then ask for input; is there a way to have perl6 give you a default value and then you just edit the default to be the new value. E.g.:
my $name = prompt("Your name:", "John Doe");
and it prints
Your name: John Doe
where the John Doe part is editable, and when you hit enter, the edited string is the value of $name.
https://docs.raku.org/routine/prompt does not show how to do it.
This is useful if you have to enter many long strings each of which is just a few chars different from others.
Thanks.
To get the editing part going, you could use the Linenoise module:
zef install Linenoise
(https://github.com/hoelzro/p6-linenoise)
Then, in your code, do:
use Linenoise;
sub prompt($p) {
my $l = linenoise $p;
linenoiseHistoryAdd($l);
$l
}
Then you can do your loop with prompt. Remember, basically all Perl 6 builtin functions can be overridden lexically. Now, how to fill in the original string, that I haven't figure out just yet. Perhaps the libreadline docs can help you with that.
Well by default, programs are completely unaware of their terminals.
You need your program to communicate with the terminal to do things like pre-fill an input line, and it's unreasonable to expect Perl 6 to handle something like this as part of the core language.
That said, your exact case is handled by the Readline library as long as you have a compatible terminal.
It doesn't look like the perl 6 Readline has pre-input hooks setup so you need to handle the callback and read loop yourself, unfortunately. Here's my rough attempt that does exactly what you want:
use v6;
use Readline;
sub prompt-prefill($question, $suggestion) {
my $rl = Readline.new;
my $answer;
my sub line-handler( Str $line ) {
rl_callback_handler_remove();
$answer = $line;
}
rl_callback_handler_install( "$question ", &line-handler );
$rl.insert-text($suggestion);
$rl.redisplay;
while (!$answer) {
$rl.callback-read-char();
}
return $answer;
}
my $name = prompt-prefill("What's your name?", "Bob");
say "Hi $name. Go away.";
If you are still set on using Linenoise, you might find the 'hints' feature good enough for your needs (it's used extensively by the redis-cli application if you want a demo). See the hint callback used with linenoiseSetHintsCallback in the linenoise example.c file. If that's not good enough you'll have to start digging into the guts of linenoise.
Another solution :
Use io-prompt
With that you can set a default value and even a default type:
my $a = ask( "Life, the universe and everything?", 42, type => Num );
Life, the universe and everything? [42]
Int $a = 42
You can install it with:
zef install IO::Prompt
However, if just a default value is not enough. Then it is better you use the approach Liz has suggested.

Update current line with command line tool in Swift

I built a OS X command line tool in Swift (same problem in Objective-C) for downloading certain files. I am trying to update the command line with download progress. Unfortunately, I cannot prevent the print statement to jump to the next line.
According to my research, the carriage return \r should jump to the beginning of the same line (while \n would insert a new line).
All tests have been performed in the OS X Terminal app, not the Xcode console.
let logString = String(format: "%2i%% %.2fM \r", percentage, megaBytes)
print(logString)
Still, the display inserts a new line. How to prevent this?
Note: This won't work in Xcode's debugger window because it's not a real terminal emulator and doesn't fully support escape sequences. So, to test things, you have to compile it and then manually run it in a Terminal window.
\r should work to move to the beginning of the current line in most terminals, but you should also take a look at VT100 Terminal Control Escape Sequences. They work by sending an escape character, \u{1B} in Swift, and then a command. (Warning: they make some pretty ugly string definitions)
One that you'll probably need is \u{1B}[K which clears the line from the current cursor position to the end. If you don't do this and your progress output varies in length at all, you'll get artifacts left over from previous print statements.
Some other useful ones are:
Move to any (x, y) position: \u{1B}[\(y);\(x)H Note: x and y are Ints inserted with string interpolation.
Save cursor state and position: \u{1B}7
Restore cursor state and position: \u{1B}8
Clear screen: \u{1B}[2J
You can also do interesting things like set text foreground and background colors.
If for some reason you can't get \r to work, you could work around it by saving the cursor state/position just before you print your logString and then restoring it after:
let logString = String(format: "\u{1B}7%2i%% %.2fM \u{1B}8", percentage, megaBytes)
print(logString)
Or by moving to a pre-defined (x, y) position, before printing it:
let x = 0
let y = 1 // Rows typically start at 1 not 0, but it depends on the terminal and shell
let logString = String(format: "\u{1B}[\(y);\(x)H%2i%% %.2fM ", percentage, megaBytes)
print(logString)
Here's an example assuming some async task is taking place with callbacks that pass a Progress type.
// Print an empty string first otherwise whichever line is above the printed out progress will be removed
print("")
let someProgressCallback: ExampleAsyncCallbackType = { progress in
let percentage = Int(progress.fractionCompleted * 100)
print("\u{1B}[1A\u{1B}[KDownloaded: \(percentage)%")
}
The key part is \u{1B}[1A\u{1B}[K and then whatever you want to print out to the screen following.
Your example will only work on the actual command line, not in the debugger console. And you also need to flush stdout for every iteration, like this:
var logString = String(format: "%2i%% %.2fM \r", 10, 5)
print(logString)
fflush(__stdoutp)

OmniComplete and Vim issues

I'm trying to get omnicomplete to work for C++, and while everything seems to be in order, when I reset my omnifunc to be omnifunc=omni#cpp#complete#Main, the plugin does not recognize the omnifunc, and I get a pattern not found error. I've installed Ctags and put it in .vim/<name_of_dir>, along with adding cpp_src to .vim/tags and running the necessary commands. (see here for more info)
The issue is that, no matter what I try, I still get this error. What can I do to get this working? I've tried this before, and the first time has just been a headache which resulted in me not being able to get it to work. This time, however, I'm determined.
VimRc
1 syntax on
2 set number
3 set autoindent
4 set ft=nasm
5 set ts=4
6 set nowrap
7 set nocp
8 filetype plugin on
9 map <C-F12> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR>
10
11 autocmd FileType cpp set omnifunc=omni#cpp#complete#Main
12
13 " configure tags - add additional tags here or comment out not-used ones
14 set tags+=~/.vim/tags/cpp
15 set tags+=~/.vim/tags/gl
16 set tags+=~/.vim/tags/sdl
17 " set tags+=~/.vim/tags/qt4
18 " " build tags of your own project with Ctrl-F12
19 map <C-F12> :!ctags -R --sort=yes --c++-kinds=+p --fields=+iaS --extra=+q .<CR>
20 "
21 " " OmniCppComplete
22 let OmniCpp_NamespaceSearch = 1
23 let OmniCpp_GlobalScopeSearch = 1
24 let OmniCpp_ShowAccess = 1
25 let OmniCpp_ShowPrototypeInAbbr = 1 " show function parameters
26 let OmniCpp_MayCompleteDot = 1 " autocomplete after .
27 let OmniCpp_MayCompleteArrow = 1 " autocomplete after ->
28 let OmniCpp_MayCompleteScope = 1 " autocomplete after ::
29 let OmniCpp_DefaultNamespaces = ["std", "_GLIBCXX_STD"]
30 " " automatically open and close the popup menu / preview window
31 au CursorMovedI,InsertLeave * if pumvisible() == 0|silent! pclose|endif
32 set completeopt=menuone,menu,longest,preview
As always, any help is much appreciated.
Update
Posting my Ctags file for others to inspect in case there is an issue with that:
ctags -R --c++-kinds=+p --fields-+iaS --extra=+q .
map <C-F12> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR>
Obviously, Vim can't find your tags file. Your command ctags -R --c++-kinds=+p --fields-+iaS --extra=+q . will create tags file in current directory. Make sure that this is what you want.
Please execute the following command:
:set tags?
and make sure your tags file is present in resulting list. You can also place cursor at any symbol (say, some class name) and press Ctrl-]. Vim will jump to this symbol definition if your tags is OK. If it is not, then, of course, omnicppcomplete will not work. (I use omnicppcomplete for more than year, and it works. Not perfectly with complicated classes/structs, but works.)
And, finally, check my answer here, because i would recommend absolutelly the same: to get perfect C/C++/Objective-C code completion you should use Clang Complete (no ctags is needed for this kind of completion).
And if you want tags to be present (say, to easily jump to symbol definition), please use Indexer plugin.