I've installed ultisnips using vim plug on Neovim. While the snippets engine works, the plugin installed snippets do not seem to work. The docs seem to suggest that writing 'let g:UltiSnipsSnippetDirectories=['UltiSnips']' will let me use plugin installed snippets (e.g., vim-snippets and vim-react-snippets), but this doesn't seem to work. How can I fix this?
Configuration:
set showmatch " show matching
set ignorecase " case insensitive
set mouse=v " middle-click paste with
set hlsearch " highlight search
set incsearch " incremental search
set tabstop=4 " number of columns occupied by a tab
set softtabstop=4 " see multiple spaces as tabstops so <BS> does the right thing
set expandtab " converts tabs to white space
set shiftwidth=4 " width for autoindents
set autoindent " indent a new line the same amount as the line just typed
set number " add line numbers
set wildmode=longest,list " get bash-like tab completions
set cc=80 " set an 80 column border for good coding style
filetype plugin indent on "allow auto-indenting depending on file type
syntax on " syntax highlighting
set mouse=a " enable mouseclick
set clipboard=unnamedplus " using system clipboard
filetype plugin on
set cursorline " highlight current cursorline
set ttyfast " Speed up scrolling in Vim
set backupcopy=yes " disable safe write
set ma
" set spell " enable spell check (may need to download language package)
" set noswapfile " disable creating swap file
" set backupdir=~/.cache/vim " Directory to store backup files.
call plug#begin('~/.vim/plugged')
Plug 'ryanoasis/vim-devicons'
Plug 'SirVer/ultisnips'
Plug 'honza/vim-snippets'
Plug 'scrooloose/nerdtree'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'mxw/vim-jsx'
Plug 'pangloss/vim-javascript'
Plug 'NLKNguyen/papercolor-theme'
Plug 'mlaursen/vim-react-snippets'
call plug#end()
let g:UltiSnipsExpandTrigger='<tab>'
" shortcut to go to next position
let g:UltiSnipsJumpForwardTrigger='<c-j>'
" shortcut to go to previous position
let g:UltiSnipsJumpBackwardTrigger='<c-k>'
let g:UltiSnipsSnippetDirectories=['UltiSnips']
:inoremap ii <Esc>
:nnoremap <F2> :NERDTreeToggle<CR>
colorscheme PaperColor
If relevant, I am using a macOS Monterey 12.3.
Related
So I just started using Neovim/Spacevim, and it's so awesome!
I am still getting used to everything, since I have never used Vim or anything like that before.
My question revolves around searching for particular text in all the files of the currently open project.
I am using the nerdtree file manager, and I was wondering how I might search through all the files in the project for a specific string. Like if I wanted to search function thisExactFunction() throughout the currently open folder/directory, how would I go about doing that? The main goal is to have a list of all the files that contain this search string.
I have fzf installed (as well as ripgrep), but seem to be having trouble in searching for specific text inside of all files. I can only search for files themselves, or some other search that does not yield what I need.
Can anyone point me in the right direction...? Thanks!
Check out the Ggrep command that Fzf supplies - see this series of vim screencasts to see how to use vim's in built features (quickfix list populated by :vimgrep) to achieve the same using other grepping tools.
Custom functions
I have a function in my .vimrc that uses ag silver
searcher to search within all
the files in a directory (and any subdirectories). So if you install ag, this
should work:
" Ag: Start ag in the specified directory e.g. :Ag ~/foo
function! s:ag_in(bang, ...)
if !isdirectory(a:1)
throw 'not a valid directory: ' .. a:1
endif
" Press `?' to enable preview window.
call fzf#vim#ag(join(a:000[1:], ' '),
\ fzf#vim#with_preview({'dir': a:1}, 'right:50%', '?'), a:bang)
endfunction
" Ag call a modified version of Ag where first arg is directory to search
command! -bang -nargs=+ -complete=dir Ag call s:ag_in(<bang>0, <f-args>)
Bonus
Sometimes it's hard to find things in vim's help, so I also have a function
that uses the one above to interactively search the help docs. This can be nice
to hone in on the topic you want. Use :H for this function (as opposed to the
classic :h)
function! Help_AG()
let orig_file = expand(#%)
let v1 = v:version[0]
let v2 = v:version[2]
" search in the help docs with ag-silver-search and fzf and open file
execute "normal! :Ag /usr/share/vim/vim".v1.v2."/doc/\<CR>"
" if we opened a help doc
if orig_file != expand(#%)
set nomodifiable
" for some reason not all the tags work unless I open the 'real' help
" so get whichever help was found and open it through Ag
let help_doc=expand("%:t")
" open and close that help doc - now the tags will work
execute "normal! :tab :help " help_doc "\<CR>:q\<CR>"
endif
endfunction
" get some help
command! H :call Help_AG()
Is there a quick and easy way to transform a selected text into "text". If you just press Shift + 2 on selected text, the text will be replaced by " and not enclosed ".
Same question for different IDE (Visual Studio)
Is there a way to put double quotes around selected text?
I have a script to copy all email attachments in a selected set of emails to a folder after some renaming. Because the attachments sometimes have identical names at origin, even with renaming, I need to add something like " copy" to subsequent versions so they don't save atop one another. With some programming knowledge but very little understanding of AppleScript, I cobbled this together:
tell application "Mail"
set theMessages to selection
set theOutputFolder to (choose folder) as string
repeat with a from 1 to length of theMessages
set theMessage to item a of theMessages
set {year:y, month:m, day:d} to date sent of theMessage
set theDate to (y * 10000 + m * 100 + d) as string
set theAttachments to every mail attachment of theMessage
repeat with b from 1 to length of theAttachments
set theAttachment to item b of theAttachments
set theAttachmentName to theDate & " " & name of theAttachment
set theSavePath to theOutputFolder & theAttachmentName
tell application "System Events" to exists file theSavePath
repeat while the result
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to {"."}
set delimitedList to every text item of theSavePath
set suffix to "." & last item of delimitedList
try
copy text items 1 thru -2 of theSavePath to theSavePathBase
on error
copy theSavePath to theSavePathBase
end try
-- display dialog "theSavePath pre- : " & theSavePath
-- display dialog "theSavePathBase & ' copy' & suffix pre- " & theSavePathBase & " copy" & suffix
set AppleScript's text item delimiters to oldDelims
copy theSavePathBase & " copy" & suffix to theSavePath
-- display dialog "theSavePath post- : " & theSavePath
tell application "System Events" to exists file theSavePath -- <<< *** BOMBS HERE
-- display dialog "Made it past existence check."
end repeat
try
display dialog "preparing to save..."
save theAttachment in theSavePath
on error errText number errNum
display dialog errText
end try
end repeat
end repeat
end tell
It works, except that when the need to fix the name of a copy is encountered, it bombs at the indicated location with this message: "System Events got an error: Can’t make {"...Desktop:Mail Attachments:20140830 Resumé 2014", "pages", " copy", ".zip"} into type integer." Something about the way I reconstituted the name changed the type to something the exists checker can't handle.
Any help would be appreciated. Help with an explanation would be better, since I'm not an AppleScripter but am interested. Thanks!
Your error message is telling you the problem. Notice the brackets {} around the error message.
Can’t make {"...Desktop:Mail Attachments:20140830 Resumé 2014", "pages", " copy", ".zip"} into type integer."
That's indicating that this is a list of items, not a string. As such you need to make it a string first therefore change...
copy text items 1 thru -2 of theSavePath to theSavePathBase
to:
copy (text items 1 thru -2 of theSavePath) as text to theSavePathBase
With that being said, I don't think your actual copy command (as follows) will work. It seems you're wanting the copy command to rename the file and copy it all in one step.
copy theSavePathBase & " copy" & suffix to theSavePath
The copy command won't be able to find "...Desktop:Mail Attachments:20140830 Resumé 2014.pages. copy.zip" because it doesn't exist. That's the name you want for the renamed file. I think you're best approach would be to use the "cp" unix executable command to preform your copy because it can copy and rename in one step. Something like this although you'll have to figure out how to get the actual value for the variable "theAttachmentCurrentPath".
do shell script "cp " & quoted form of POSIX path of theAttachmentCurrentPath & space & quoted form of POSIX path of (theOutputFolder & text 1 thru -5 of theAttachmentName & " copy" & text -4 thru -1 of theAttachmentName)
When I use the combinations of CTRL + SHIFT + F to format the code in Eclipse, I don't like when it brakes the lines like this:
Toast.makeText(Activity_1.this, String.valueOf(numbersOfRows),
Toast.LENGTH_LONG).show();
If I want to put comment signs like // in the beginning of the line, then I have to do the same on the second line otherwise I get an error!
Is there a way to prevent braking rows like that?
You can configure your formatter options in "windows/Preferences/Java/Code Style/Formatter". Click on edit your profile. Here you have "line wrapping" options.
Set "Line width for preview window" option and "maximum line width" option in Preferences/Java/Code Style/Formatter.
Before that you should create a new profile name instead of default profile name
I have used Vim for coding.
I want to learn Emacs too.
I would like to export at least some of the following customizations in my .vimrc to my .emacs.
My .vimrc
let Tlist_Auto_Open = 1
" http://stackoverflow.com/questions/165231/vim-dvorak-keybindings-rebinding
" Dvorak it!
no d h
no h j
no t k
no n l
no s :
no S :
no j d
no J D
no l n
no L N
" Added benefits
no - $
no _ ^
no N
no ; z
no T L
no P P
no p p
let Tex_ViewRuleComplete_pdf = '/usr/bin/open -a Skim $*.pdf'
set history=1000
set smartindent
set autoindent
set tabstop=4
set expandtab
set shiftwidth=3
set softtabstop=4
set number
set hlsearch
syntax on
set cursorline
highlight CursorLine guibg=#400000
set ruler
set textwidth=78
set foldcolumn=5
" REQUIRED. This makes vim invoke Latex-Suite when you open a tex file.
filetype plugin on
filetype indent on
" IMPORTANT: grep will sometimes skip displaying the file name if you
" search in a singe file. This will confuse Latex-Suite. Set your grep
" program to always generate a file-name.
set grepprg=grep\ -nH\ $*
" OPTIONAL: This enables automatic indentation as you type.
filetype indent on
" OPTIONAL: Starting with Vim 7, the filetype of empty .tex files defaults to
" 'plaintex' instead of 'tex', which results in vim-latex not being loaded.
" The following changes the default filetype back to 'tex':
let g:tex_flavor='latex'
" http://ubuntuforums.org/showthread.php?t=74889
set foldmethod=manual "folds by indentation, manual, indent
set nocompatible "Use Vim extensions
set backspace=indent,eol,start "More powerful backspacing
set nobackup "No backup file
set showmode "Tell when in insert mode
set showmatch "Show matching () {} etc
set hlsearch "Highlight what is searched for
set incsearch "Highlight as you type
if &t_Co > 2
syntax on
endif
set bg=dark
hi clear
if exists("syntax_on")
syntax reset
endif
"Allowable colors: red, yellow, green, blue, magenta,
" cyan, gray, black, gray
hi Normal ctermfg=gray ctermbg=none
hi ErrorMsg ctermfg=gray ctermbg=lightblue
hi Visual ctermfg=lightblue ctermbg=fg cterm=reverse
hi VisualNOS ctermfg=lightblue ctermbg=fg cterm=reverse,underline
hi Todo ctermfg=red ctermbg=darkblue
hi Search ctermfg=gray ctermbg=darkblue
hi IncSearch ctermfg=darkblue ctermbg=gray
hi SpecialKey ctermfg=darkcyan
hi Directory ctermfg=cyan
hi Title ctermfg=magenta cterm=bold
hi WarningMsg ctermfg=red
hi WildMenu ctermfg=yellow ctermbg=black cterm=none
hi ModeMsg ctermfg=lightblue
hi MoreMsg ctermfg=darkgreen ctermfg=darkgreen
hi Question ctermfg=green cterm=none
hi NonText ctermfg=darkblue
hi StatusLine ctermfg=blue ctermbg=gray cterm=none
hi StatusLineNC ctermfg=black ctermbg=gray cterm=none
hi VertSplit ctermfg=black ctermbg=gray cterm=none
"hi Folded ctermfg=darkgrey ctermbg=black cterm=bold
"hi FoldColumn ctermfg=darkgrey ctermbg=black cterm=bold
hi LineNr ctermfg=gray cterm=none
hi DiffAdd ctermbg=darkblue cterm=none
hi DiffChange ctermbg=magenta cterm=none
hi DiffDelete ctermfg=blue ctermbg=cyan
hi DiffText cterm=bold ctermbg=red
hi Cursor ctermbg=brown
hi lCursor ctermbg=darkgreen
hi Comment ctermfg=lightgreen cterm=none
hi Constant ctermfg=cyan cterm=none
hi Identifier ctermfg=gray cterm=none
hi Statement ctermfg=red cterm=none
hi PreProc ctermfg=yellow cterm=bold
hi Type ctermfg=darkyellow cterm=none
hi Special ctermfg=magenta cterm=none
hi Underlined cterm=underline
hi Ignore cterm=none
What is in your .emacs which would allow me to have some of the above features?
The EMACS Starter Kit is helpful too.
My God -- you really remap your keyboard to Dvorak in your .vim?
Okay, here are some of the others:
set smartindent
set autoindent
There automagically in programming modes. For text modes, look at 'autoindent-mode" and "filladapt."
set tabstop=4
set shiftwidth=3
set softtabstop=4
(setq c-basic-offset 4) ; indents 4 chars
(setq tab-width 4) ; and 4 char wide for TAB
(setq indent-tabs-mode nil) ; And force use of spaces
(There's no easy equivalent for shiftwidth; EMACS uses a smarter autindentation algorithm.
set expandtab
(setq indent-tabs-mode nil)
set number
There is a way to get numbered lines, but I never use it and don't remember it.
syntax on
(turn-on-font-lock)
set cursorline
There are a pile of cursor settings, look through M-x apropos cursor
Some of the other stuff is also available, these are the things I know of offhand.
Try these, and experiment.
dotfiles emacs
dotfiles.org
Apart from those, always a nice link:
GNU Emacs Manuals Online
You can get numbered lines with (linum-mode 1) or (global-linum-mode 1) for every buffer. This feature is currently only in the CVS Emacs. See further choices.
For opening PDF documents inside Emacs, there is doc-view-mode. See View PDF/PS/DVI files in an Emacs buffer for further instructions.
Anyway, it'd better if you start up learning Emacs with Emacs Starter Kit as Charlie Martin suggested, and then find yourself what you're really missing. Emacs world is different than Vi's. And you can always browse Stack Overflow to find if your question was already answered.
you definitely should try evil-mode. Best vim emulator for emacs:
http://www.emacswiki.org/emacs/Evil